[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/chrome_content_browser_client.h" |
| 6 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 7 | #include "base/command_line.h" |
| 8 | #include "chrome/app/breakpad_mac.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 9 | #include "chrome/browser/browser_about_handler.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 10 | #include "chrome/browser/browser_process.h" |
[email protected] | 3b8f7e3 | 2011-07-13 11:52:23 | [diff] [blame] | 11 | #include "chrome/browser/browsing_data_remover.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 12 | #include "chrome/browser/character_encoding.h" |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 13 | #include "chrome/browser/chrome_benchmarking_message_filter.h" |
[email protected] | 97e6c4c | 2011-05-18 16:08:51 | [diff] [blame] | 14 | #include "chrome/browser/chrome_plugin_message_filter.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 15 | #include "chrome/browser/chrome_quota_permission_context.h" |
[email protected] | 5327dfb | 2011-05-03 17:50:36 | [diff] [blame] | 16 | #include "chrome/browser/chrome_worker_message_filter.h" |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 17 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 18 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 19 | #include "chrome/browser/download/download_util.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 20 | #include "chrome/browser/extensions/extension_info_map.h" |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 21 | #include "chrome/browser/extensions/extension_message_handler.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 22 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 23 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 24 | #include "chrome/browser/geolocation/chrome_access_token_store.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 25 | #include "chrome/browser/google/google_util.h" |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 26 | #include "chrome/browser/net/chrome_net_log.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 27 | #include "chrome/browser/notifications/desktop_notification_service.h" |
| 28 | #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 29 | #include "chrome/browser/platform_util.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 30 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 31 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 32 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 33 | #include "chrome/browser/prerender/prerender_tracker.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 34 | #include "chrome/browser/printing/printing_message_filter.h" |
| 35 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 36 | #include "chrome/browser/profiles/profile_io_data.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 37 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | 53a0afa | 2011-04-28 02:09:33 | [diff] [blame] | 38 | #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 39 | #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" |
[email protected] | 3bc0b56 | 2011-08-24 23:51:04 | [diff] [blame] | 40 | #include "chrome/browser/speech/chrome_speech_input_manager.h" |
[email protected] | 8ec7126 | 2011-07-28 08:12:46 | [diff] [blame] | 41 | #include "chrome/browser/spellchecker/spellcheck_message_filter.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 42 | #include "chrome/browser/ssl/ssl_add_cert_handler.h" |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 43 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 44 | #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 45 | #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" |
| 46 | #include "chrome/browser/tab_contents/tab_util.h" |
| 47 | #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 48 | #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 49 | #include "chrome/common/child_process_logging.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 50 | #include "chrome/common/chrome_constants.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 51 | #include "chrome/common/chrome_switches.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 52 | #include "chrome/common/extensions/extension.h" |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 53 | #include "chrome/common/logging_chrome.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 54 | #include "chrome/common/pref_names.h" |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 55 | #include "chrome/common/render_messages.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 56 | #include "chrome/common/url_constants.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 57 | #include "content/browser/browser_url_handler.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 58 | #include "content/browser/browsing_instance.h" |
[email protected] | 97e6c4c | 2011-05-18 16:08:51 | [diff] [blame] | 59 | #include "content/browser/plugin_process_host.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 60 | #include "content/browser/renderer_host/browser_render_process_host.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 61 | #include "content/browser/renderer_host/render_view_host.h" |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 62 | #include "content/browser/resource_context.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 63 | #include "content/browser/site_instance.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 64 | #include "content/browser/ssl/ssl_cert_error_handler.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 65 | #include "content/browser/ssl/ssl_client_auth_handler.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 66 | #include "content/browser/tab_contents/tab_contents.h" |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 67 | #include "content/browser/tab_contents/tab_contents_view.h" |
[email protected] | 5327dfb | 2011-05-03 17:50:36 | [diff] [blame] | 68 | #include "content/browser/worker_host/worker_process_host.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 69 | #include "content/common/desktop_notification_messages.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 70 | #include "grit/generated_resources.h" |
[email protected] | 29b25d09 | 2011-06-29 20:57:34 | [diff] [blame] | 71 | #include "grit/ui_resources.h" |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 72 | #include "net/base/cookie_monster.h" |
| 73 | #include "net/base/cookie_options.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 74 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 75 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 76 | |
[email protected] | 5778d50 | 2011-10-13 17:13:21 | [diff] [blame] | 77 | #if defined(OS_CHROMEOS) |
| 78 | #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" |
| 79 | #elif defined(USE_AURA) |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 80 | #include "chrome/browser/chrome_browser_main_aura.h" |
| 81 | #elif defined(OS_WIN) |
| 82 | #include "chrome/browser/chrome_browser_main_win.h" |
| 83 | #elif defined(OS_MACOSX) |
| 84 | #include "chrome/browser/chrome_browser_main_mac.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 85 | #elif defined(OS_LINUX) |
| 86 | #include "chrome/browser/chrome_browser_main_gtk.h" |
| 87 | #endif |
| 88 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 89 | #if defined(OS_LINUX) |
| 90 | #include "base/linux_util.h" |
| 91 | #include "chrome/browser/crash_handler_host_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 92 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 93 | |
[email protected] | 080f34f | 2011-09-20 05:39:26 | [diff] [blame] | 94 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 95 | #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" |
| 96 | #elif defined(OS_LINUX) |
| 97 | #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" |
| 98 | #elif defined(OS_MACOSX) |
| 99 | #include "chrome/browser/tab_contents/tab_contents_view_mac.h" |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 100 | #endif |
| 101 | |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 102 | #if defined(USE_NSS) |
| 103 | #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 104 | #endif |
| 105 | |
[email protected] | b45937e | 2011-10-07 19:49:17 | [diff] [blame] | 106 | |
| 107 | #if defined(USE_AURA) || defined(TOUCH_UI) |
| 108 | #include "chrome/browser/renderer_host/render_widget_host_view_views.h" |
| 109 | #elif defined(OS_WIN) |
| 110 | #include "chrome/browser/renderer_host/render_widget_host_view_views.h" |
| 111 | #include "content/browser/renderer_host/render_widget_host_view_win.h" |
| 112 | #elif defined(OS_LINUX) |
| 113 | #include "content/browser/renderer_host/render_widget_host_view_gtk.h" |
| 114 | #elif defined(OS_MACOSX) |
| 115 | #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 116 | #endif |
| 117 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 118 | namespace { |
| 119 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 120 | // Handles rewriting Web UI URLs. |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 121 | bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 122 | if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url)) |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 123 | return false; |
| 124 | |
| 125 | // Special case the new tab page. In older versions of Chrome, the new tab |
| 126 | // page was hosted at chrome-internal:<blah>. This might be in people's saved |
| 127 | // sessions or bookmarks, so we say any URL with that scheme triggers the new |
| 128 | // tab page. |
| 129 | if (url->SchemeIs(chrome::kChromeInternalScheme)) { |
| 130 | // Rewrite it with the proper new tab URL. |
| 131 | *url = GURL(chrome::kChromeUINewTabURL); |
| 132 | } |
| 133 | |
| 134 | return true; |
| 135 | } |
| 136 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 137 | // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions |
| 138 | // below. Extension, and isolated apps require different privileges to be |
| 139 | // granted to their RenderProcessHosts. This classification allows us to make |
| 140 | // sure URLs are served by hosts with the right set of privileges. |
| 141 | enum RenderProcessHostPrivilege { |
| 142 | PRIV_NORMAL, |
| 143 | PRIV_EXTENSION, |
| 144 | PRIV_ISOLATED, |
| 145 | }; |
| 146 | |
| 147 | RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( |
| 148 | const GURL& url, |
| 149 | ExtensionService* service) { |
| 150 | // Default to a normal renderer cause it is lower privileged. This should only |
| 151 | // occur if the URL on a site instance is either malformed, or uninitialized. |
| 152 | // If it is malformed, then there is no need for better privileges anyways. |
| 153 | // If it is uninitialized, but eventually settles on being an a scheme other |
| 154 | // than normal webrenderer, the navigation logic will correct us out of band |
| 155 | // anyways. |
| 156 | if (!url.is_valid()) |
| 157 | return PRIV_NORMAL; |
| 158 | |
| 159 | if (url.SchemeIs(chrome::kExtensionScheme)) { |
| 160 | const Extension* extension = service->GetExtensionByURL(url); |
| 161 | if (extension && extension->is_storage_isolated()) { |
| 162 | return PRIV_ISOLATED; |
| 163 | } |
| 164 | |
| 165 | return PRIV_EXTENSION; |
| 166 | } |
| 167 | |
| 168 | return PRIV_NORMAL; |
| 169 | } |
| 170 | |
| 171 | RenderProcessHostPrivilege GetProcessPrivilege( |
| 172 | RenderProcessHost* process_host, |
| 173 | ExtensionProcessManager* extension_process_manager) { |
| 174 | if (extension_process_manager->IsExtensionProcess(process_host->id())) { |
| 175 | if (extension_process_manager->IsStorageIsolatedForProcess( |
| 176 | process_host->id())) { |
| 177 | return PRIV_ISOLATED; |
| 178 | } |
| 179 | return PRIV_EXTENSION; |
| 180 | } |
| 181 | |
| 182 | return PRIV_NORMAL; |
| 183 | } |
| 184 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 185 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 186 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 187 | namespace chrome { |
| 188 | |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 189 | content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( |
| 190 | const MainFunctionParams& parameters) { |
[email protected] | 5778d50 | 2011-10-13 17:13:21 | [diff] [blame] | 191 | #if defined(OS_CHROMEOS) |
| 192 | return new ChromeBrowserMainPartsChromeos(parameters); |
| 193 | #elif defined(USE_AURA) |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 194 | return new ChromeBrowserMainPartsAura(parameters); |
| 195 | #elif defined(OS_WIN) |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 196 | return new ChromeBrowserMainPartsWin(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 197 | #elif defined(OS_MACOSX) |
[email protected] | 46c83b6 | 2011-09-08 22:09:04 | [diff] [blame] | 198 | return new ChromeBrowserMainPartsMac(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 199 | #elif defined(OS_LINUX) |
[email protected] | e6b5bc2 | 2011-09-08 22:01:56 | [diff] [blame] | 200 | return new ChromeBrowserMainPartsGtk(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 201 | #else |
| 202 | return NULL; |
| 203 | #endif |
| 204 | } |
| 205 | |
[email protected] | b45937e | 2011-10-07 19:49:17 | [diff] [blame] | 206 | RenderWidgetHostView* ChromeContentBrowserClient::CreateViewForWidget( |
| 207 | RenderWidgetHost* widget) { |
| 208 | #if defined(USE_AURA) || defined(TOUCH_UI) |
| 209 | return new RenderWidgetHostViewViews(widget); |
| 210 | #elif defined(OS_WIN) |
| 211 | if (views::Widget::IsPureViews()) |
| 212 | return new RenderWidgetHostViewViews(widget); |
| 213 | return new RenderWidgetHostViewWin(widget); |
| 214 | #elif defined(OS_LINUX) |
| 215 | return new RenderWidgetHostViewGtk(widget); |
| 216 | #elif defined(OS_MACOSX) |
| 217 | return render_widget_host_view_mac::CreateRenderWidgetHostView(widget); |
| 218 | #else |
| 219 | #error Need to create your platform ViewForWidget here. |
| 220 | #endif |
| 221 | } |
| 222 | |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 223 | TabContentsView* ChromeContentBrowserClient::CreateTabContentsView( |
| 224 | TabContents* tab_contents) { |
[email protected] | 080f34f | 2011-09-20 05:39:26 | [diff] [blame] | 225 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 226 | return new TabContentsViewViews(tab_contents); |
| 227 | #elif defined(OS_LINUX) |
| 228 | return new TabContentsViewGtk(tab_contents); |
| 229 | #elif defined(OS_MACOSX) |
| 230 | return tab_contents_view_mac::CreateTabContentsView(tab_contents); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 231 | #else |
| 232 | #error Need to create your platform TabContentsView here. |
| 233 | #endif |
| 234 | } |
| 235 | |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 236 | void ChromeContentBrowserClient::RenderViewHostCreated( |
| 237 | RenderViewHost* render_view_host) { |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 238 | |
| 239 | SiteInstance* site_instance = render_view_host->site_instance(); |
| 240 | Profile* profile = Profile::FromBrowserContext( |
| 241 | site_instance->browsing_instance()->browser_context()); |
| 242 | |
| 243 | new ChromeRenderViewHostObserver(render_view_host, |
| 244 | profile->GetNetworkPredictor()); |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 245 | new ExtensionMessageHandler(render_view_host); |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 246 | } |
| 247 | |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 248 | void ChromeContentBrowserClient::BrowserRenderProcessHostCreated( |
| 249 | BrowserRenderProcessHost* host) { |
[email protected] | c47cfd6 | 2011-04-29 21:27:02 | [diff] [blame] | 250 | int id = host->id(); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 251 | Profile* profile = Profile::FromBrowserContext(host->browser_context()); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 252 | host->channel()->AddFilter(new ChromeRenderMessageFilter( |
[email protected] | c47cfd6 | 2011-04-29 21:27:02 | [diff] [blame] | 253 | id, profile, profile->GetRequestContextForRenderProcess(id))); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 254 | host->channel()->AddFilter(new PrintingMessageFilter()); |
| 255 | host->channel()->AddFilter( |
[email protected] | c47cfd6 | 2011-04-29 21:27:02 | [diff] [blame] | 256 | new SearchProviderInstallStateMessageFilter(id, profile)); |
| 257 | host->channel()->AddFilter(new SpellCheckMessageFilter(id)); |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 258 | host->channel()->AddFilter(new ChromeBenchmarkingMessageFilter( |
| 259 | id, profile, profile->GetRequestContextForRenderProcess(id))); |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 260 | |
[email protected] | 2ccf45c | 2011-08-19 23:35:50 | [diff] [blame] | 261 | host->Send(new ChromeViewMsg_SetIsIncognitoProcess( |
| 262 | profile->IsOffTheRecord())); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 263 | } |
| 264 | |
[email protected] | 97e6c4c | 2011-05-18 16:08:51 | [diff] [blame] | 265 | void ChromeContentBrowserClient::PluginProcessHostCreated( |
| 266 | PluginProcessHost* host) { |
| 267 | host->AddFilter(new ChromePluginMessageFilter(host)); |
| 268 | } |
| 269 | |
[email protected] | 5327dfb | 2011-05-03 17:50:36 | [diff] [blame] | 270 | void ChromeContentBrowserClient::WorkerProcessHostCreated( |
| 271 | WorkerProcessHost* host) { |
| 272 | host->AddFilter(new ChromeWorkerMessageFilter(host)); |
| 273 | } |
| 274 | |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 275 | content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() { |
| 276 | return ChromeWebUIFactory::GetInstance(); |
| 277 | } |
| 278 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 279 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
| 280 | content::BrowserContext* browser_context, const GURL& url) { |
| 281 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 282 | // Get the effective URL for the given actual URL. If the URL is part of an |
| 283 | // installed app, the effective URL is an extension URL with the ID of that |
| 284 | // extension as the host. This has the effect of grouping apps together in |
| 285 | // a common SiteInstance. |
| 286 | if (!profile || !profile->GetExtensionService()) |
| 287 | return url; |
| 288 | |
| 289 | const Extension* extension = |
| 290 | profile->GetExtensionService()->GetExtensionByWebExtent(url); |
| 291 | if (!extension) |
| 292 | return url; |
| 293 | |
| 294 | // If the URL is part of an extension's web extent, convert it to an |
| 295 | // extension URL. |
| 296 | return extension->GetResourceURL(url.path()); |
| 297 | } |
| 298 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 299 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 300 | content::BrowserContext* browser_context, const GURL& effective_url) { |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 301 | // Non-extension URLs should generally use process-per-site-instance. |
| 302 | // Because we expect to use the effective URL, hosted apps URLs should have |
| 303 | // an extension scheme by now. |
| 304 | if (!effective_url.SchemeIs(chrome::kExtensionScheme)) |
| 305 | return false; |
| 306 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 307 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 308 | if (!profile || !profile->GetExtensionService()) |
| 309 | return false; |
| 310 | |
| 311 | const Extension* extension = |
| 312 | profile->GetExtensionService()->GetExtensionByURL(effective_url); |
| 313 | if (!extension) |
| 314 | return false; |
| 315 | |
| 316 | // If the URL is part of a hosted app that does not have the background |
| 317 | // permission, we want to give each instance its own process to improve |
| 318 | // responsiveness. |
| 319 | if (extension->GetType() == Extension::TYPE_HOSTED_APP && |
| 320 | !extension->HasAPIPermission(ExtensionAPIPermission::kBackground)) |
| 321 | return false; |
| 322 | |
| 323 | // Hosted apps that have the background permission must use process per site, |
| 324 | // since all instances can make synchronous calls to the background window. |
| 325 | // Other extensions should use process per site as well. |
| 326 | return true; |
| 327 | } |
| 328 | |
[email protected] | 0f012df8 | 2011-05-19 14:15:29 | [diff] [blame] | 329 | bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) { |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 330 | return url == GURL(chrome::kChromeUICrashURL) || |
| 331 | url == GURL(chrome::kChromeUIKillURL) || |
| 332 | url == GURL(chrome::kChromeUIHangURL) || |
| 333 | url == GURL(chrome::kChromeUIShorthangURL); |
[email protected] | 0f012df8 | 2011-05-19 14:15:29 | [diff] [blame] | 334 | } |
| 335 | |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 336 | bool ChromeContentBrowserClient::IsSuitableHost( |
| 337 | RenderProcessHost* process_host, |
| 338 | const GURL& site_url) { |
| 339 | Profile* profile = |
| 340 | Profile::FromBrowserContext(process_host->browser_context()); |
| 341 | ExtensionProcessManager* extension_process_manager = |
| 342 | profile->GetExtensionProcessManager(); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 343 | ExtensionService* service = profile->GetExtensionService(); |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 344 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 345 | // These may be NULL during tests. In that case, just assume any site can |
| 346 | // share any host. |
| 347 | if (!extension_process_manager || !service) |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 348 | return true; |
| 349 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 350 | return GetProcessPrivilege(process_host, extension_process_manager) == |
| 351 | GetPrivilegeRequiredByUrl(site_url, service); |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 352 | } |
| 353 | |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 354 | bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation( |
| 355 | const GURL& current_url, |
| 356 | const GURL& new_url) { |
| 357 | if (current_url.is_empty()) { |
| 358 | // Always choose a new process when navigating to extension URLs. The |
| 359 | // process grouping logic will combine all of a given extension's pages |
| 360 | // into the same process. |
| 361 | if (new_url.SchemeIs(chrome::kExtensionScheme)) |
| 362 | return true; |
| 363 | |
| 364 | return false; |
| 365 | } |
| 366 | |
| 367 | // Also, we must switch if one is an extension and the other is not the exact |
| 368 | // same extension. |
| 369 | if (current_url.SchemeIs(chrome::kExtensionScheme) || |
| 370 | new_url.SchemeIs(chrome::kExtensionScheme)) { |
| 371 | if (current_url.GetOrigin() != new_url.GetOrigin()) |
| 372 | return true; |
| 373 | } |
| 374 | |
| 375 | return false; |
| 376 | } |
| 377 | |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 378 | std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName( |
| 379 | const std::string& alias_name) { |
| 380 | return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name); |
| 381 | } |
| 382 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 383 | void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( |
| 384 | CommandLine* command_line, int child_process_id) { |
| 385 | #if defined(USE_LINUX_BREAKPAD) |
| 386 | if (IsCrashReporterEnabled()) { |
| 387 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
| 388 | child_process_logging::GetClientId() + "," + base::GetLinuxDistro()); |
| 389 | } |
| 390 | #elif defined(OS_MACOSX) |
| 391 | if (IsCrashReporterEnabled()) { |
| 392 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
| 393 | child_process_logging::GetClientId()); |
| 394 | } |
| 395 | #endif // OS_MACOSX |
| 396 | |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 397 | if (logging::DialogsAreSuppressed()) |
| 398 | command_line->AppendSwitch(switches::kNoErrorDialogs); |
| 399 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 400 | std::string process_type = |
| 401 | command_line->GetSwitchValueASCII(switches::kProcessType); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 402 | const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 403 | if (process_type == switches::kRendererProcess) { |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 404 | FilePath user_data_dir = |
| 405 | browser_command_line.GetSwitchValuePath(switches::kUserDataDir); |
| 406 | if (!user_data_dir.empty()) |
| 407 | command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); |
| 408 | #if defined(OS_CHROMEOS) |
| 409 | const std::string& login_profile = |
| 410 | browser_command_line.GetSwitchValueASCII(switches::kLoginProfile); |
| 411 | if (!login_profile.empty()) |
| 412 | command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile); |
| 413 | #endif |
| 414 | |
| 415 | RenderProcessHost* process = RenderProcessHost::FromID(child_process_id); |
| 416 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 417 | Profile* profile = Profile::FromBrowserContext(process->browser_context()); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 418 | |
| 419 | ExtensionProcessManager* extension_process_manager = |
| 420 | profile->GetExtensionProcessManager(); |
| 421 | if (extension_process_manager->IsExtensionProcess( |
| 422 | process->id())) { |
| 423 | command_line->AppendSwitch(switches::kExtensionProcess); |
| 424 | } |
| 425 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 426 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 427 | // Currently this pref is only registered if applied via a policy. |
| 428 | if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && |
| 429 | prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 430 | // Turn this policy into a command line switch. |
| 431 | command_line->AppendSwitch(switches::kDisable3DAPIs); |
| 432 | } |
| 433 | |
| 434 | // Disable client-side phishing detection in the renderer if it is disabled |
[email protected] | 8c40da6 | 2011-07-13 22:58:46 | [diff] [blame] | 435 | // in the Profile preferences or the browser process. |
| 436 | if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) || |
| 437 | !g_browser_process->safe_browsing_detection_service()) { |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 438 | command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection); |
[email protected] | 8c40da6 | 2011-07-13 22:58:46 | [diff] [blame] | 439 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 440 | |
| 441 | static const char* const kSwitchNames[] = { |
| 442 | switches::kAllowHTTPBackgroundPage, |
| 443 | switches::kAllowScriptingGallery, |
| 444 | switches::kAppsCheckoutURL, |
| 445 | switches::kAppsGalleryURL, |
[email protected] | be9d9c8 | 2011-07-13 04:17:31 | [diff] [blame] | 446 | switches::kCloudPrintServiceURL, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 447 | switches::kDebugPrint, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 448 | switches::kDisablePrintPreview, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 449 | switches::kDomAutomationController, |
| 450 | switches::kDumpHistogramsOnExit, |
| 451 | switches::kEnableClickToPlay, |
| 452 | switches::kEnableCrxlessWebApps, |
| 453 | switches::kEnableExperimentalExtensionApis, |
| 454 | switches::kEnableInBrowserThumbnailing, |
| 455 | switches::kEnableIPCFuzzing, |
| 456 | switches::kEnableNaCl, |
[email protected] | 5714ee3 | 2011-08-18 01:51:24 | [diff] [blame] | 457 | switches::kEnablePrintPreview, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 458 | switches::kEnableSearchProviderApiV2, |
| 459 | switches::kEnableWatchdog, |
| 460 | switches::kExperimentalSpellcheckerFeatures, |
| 461 | switches::kMemoryProfiling, |
| 462 | switches::kMessageLoopHistogrammer, |
[email protected] | 2a6bb0b1 | 2011-10-05 19:18:04 | [diff] [blame] | 463 | switches::kNoRunningInsecureContent, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 464 | switches::kPpapiFlashArgs, |
| 465 | switches::kPpapiFlashInProcess, |
| 466 | switches::kPpapiFlashPath, |
| 467 | switches::kPpapiFlashVersion, |
| 468 | switches::kProfilingAtStart, |
| 469 | switches::kProfilingFile, |
| 470 | switches::kProfilingFlush, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 471 | switches::kSilentDumpOnDCHECK, |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 472 | switches::kEnableBenchmarking, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 473 | }; |
| 474 | |
| 475 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 476 | arraysize(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 477 | } else if (process_type == switches::kUtilityProcess) { |
| 478 | if (browser_command_line.HasSwitch( |
| 479 | switches::kEnableExperimentalExtensionApis)) { |
| 480 | command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 481 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 482 | } else if (process_type == switches::kPluginProcess) { |
| 483 | static const char* const kSwitchNames[] = { |
| 484 | #if defined(OS_CHROMEOS) |
| 485 | switches::kLoginProfile, |
| 486 | #endif |
| 487 | switches::kMemoryProfiling, |
| 488 | switches::kSilentDumpOnDCHECK, |
| 489 | switches::kUserDataDir, |
| 490 | }; |
| 491 | |
| 492 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 493 | arraysize(kSwitchNames)); |
| 494 | } else if (process_type == switches::kZygoteProcess) { |
| 495 | static const char* const kSwitchNames[] = { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 496 | switches::kUserDataDir, // Make logs go to the right file. |
| 497 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
| 498 | switches::kPpapiFlashInProcess, |
| 499 | switches::kPpapiFlashPath, |
| 500 | switches::kPpapiFlashVersion, |
| 501 | }; |
| 502 | |
| 503 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 504 | arraysize(kSwitchNames)); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 505 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 506 | |
| 507 | // The command line switch kEnableBenchmarking needs to be specified along |
| 508 | // with the kEnableStatsTable switch to ensure that the stats table global |
| 509 | // is initialized correctly. |
| 510 | if (command_line->HasSwitch(switches::kEnableBenchmarking)) |
| 511 | DCHECK(command_line->HasSwitch(switches::kEnableStatsTable)); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
| 515 | return g_browser_process->GetApplicationLocale(); |
| 516 | } |
| 517 | |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 518 | std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 519 | Profile* profile = Profile::FromBrowserContext(tab->browser_context()); |
| 520 | return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 521 | } |
| 522 | |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 523 | SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() { |
| 524 | ResourceBundle &rb = ResourceBundle::GetSharedInstance(); |
[email protected] | 2cc6a929 | 2011-10-13 21:41:01 | [diff] [blame] | 525 | #if defined(TOUCH_UI) |
| 526 | // In touch builds, we want large default favicons for the tabstrip, but in |
| 527 | // other places (such as bookmark, manage search engines, homepage) we assume |
| 528 | // default favicons are 16x16. |
| 529 | return rb.GetBitmapNamed(IDR_DEFAULT_LARGE_FAVICON); |
| 530 | #else |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 531 | return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
[email protected] | 2cc6a929 | 2011-10-13 21:41:01 | [diff] [blame] | 532 | #endif |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 533 | } |
| 534 | |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 535 | bool ChromeContentBrowserClient::AllowAppCache( |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 536 | const GURL& manifest_url, |
[email protected] | 0a60884 | 2011-09-08 10:55:19 | [diff] [blame] | 537 | const GURL& first_party, |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 538 | const content::ResourceContext& context) { |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 539 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 540 | ProfileIOData* io_data = |
| 541 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
[email protected] | efa5521 | 2011-05-13 16:19:38 | [diff] [blame] | 542 | ContentSetting setting = io_data->GetHostContentSettingsMap()-> |
[email protected] | 0a60884 | 2011-09-08 10:55:19 | [diff] [blame] | 543 | GetCookieContentSetting(manifest_url, first_party, true); |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 544 | DCHECK(setting != CONTENT_SETTING_DEFAULT); |
| 545 | return setting != CONTENT_SETTING_BLOCK; |
| 546 | } |
| 547 | |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 548 | bool ChromeContentBrowserClient::AllowGetCookie( |
| 549 | const GURL& url, |
| 550 | const GURL& first_party, |
| 551 | const net::CookieList& cookie_list, |
| 552 | const content::ResourceContext& context, |
| 553 | int render_process_id, |
| 554 | int render_view_id) { |
| 555 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 556 | ProfileIOData* io_data = |
| 557 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 558 | ContentSetting setting = io_data->GetHostContentSettingsMap()-> |
| 559 | GetCookieContentSetting(url, first_party, false); |
| 560 | bool allow = setting == CONTENT_SETTING_ALLOW || |
| 561 | setting == CONTENT_SETTING_SESSION_ONLY; |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 562 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 563 | BrowserThread::PostTask( |
| 564 | BrowserThread::UI, FROM_HERE, |
| 565 | NewRunnableFunction( |
| 566 | &TabSpecificContentSettings::CookiesRead, |
| 567 | render_process_id, render_view_id, url, cookie_list, !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 568 | return allow; |
| 569 | } |
| 570 | |
| 571 | bool ChromeContentBrowserClient::AllowSetCookie( |
| 572 | const GURL& url, |
| 573 | const GURL& first_party, |
| 574 | const std::string& cookie_line, |
| 575 | const content::ResourceContext& context, |
| 576 | int render_process_id, |
| 577 | int render_view_id, |
| 578 | net::CookieOptions* options) { |
| 579 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 580 | ProfileIOData* io_data = |
| 581 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 582 | ContentSetting setting = io_data->GetHostContentSettingsMap()-> |
| 583 | GetCookieContentSetting(url, first_party, true); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 584 | |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 585 | if (setting == CONTENT_SETTING_SESSION_ONLY) |
| 586 | options->set_force_session(); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 587 | |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 588 | bool allow = setting == CONTENT_SETTING_ALLOW || |
| 589 | setting == CONTENT_SETTING_SESSION_ONLY; |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 590 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 591 | BrowserThread::PostTask( |
| 592 | BrowserThread::UI, FROM_HERE, |
| 593 | NewRunnableFunction( |
| 594 | &TabSpecificContentSettings::CookieChanged, |
| 595 | render_process_id, render_view_id, url, cookie_line, *options, |
| 596 | !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 597 | return allow; |
| 598 | } |
| 599 | |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 600 | bool ChromeContentBrowserClient::AllowSaveLocalState( |
| 601 | const content::ResourceContext& context) { |
| 602 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 603 | ProfileIOData* io_data = |
| 604 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 605 | return !io_data->clear_local_state_on_exit()->GetValue(); |
| 606 | } |
| 607 | |
[email protected] | 6133f92 | 2011-07-01 21:34:34 | [diff] [blame] | 608 | net::URLRequestContext* |
| 609 | ChromeContentBrowserClient::OverrideRequestContextForURL( |
| 610 | const GURL& url, const content::ResourceContext& context) { |
| 611 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 612 | if (url.SchemeIs(chrome::kExtensionScheme)) { |
| 613 | ProfileIOData* io_data = |
| 614 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 615 | return io_data->extensions_request_context(); |
| 616 | } |
| 617 | |
| 618 | return NULL; |
| 619 | } |
| 620 | |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 621 | QuotaPermissionContext* |
| 622 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
| 623 | return new ChromeQuotaPermissionContext(); |
| 624 | } |
| 625 | |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 626 | void ChromeContentBrowserClient::OpenItem(const FilePath& path) { |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 627 | // On Mac, this call needs to be done on the UI thread. On other platforms, |
| 628 | // do it on the FILE thread so we don't slow down UI. |
| 629 | #if defined(OS_MACOSX) |
| 630 | platform_util::OpenItem(path); |
| 631 | #else |
| 632 | BrowserThread::PostTask( |
| 633 | BrowserThread::FILE, FROM_HERE, |
| 634 | NewRunnableFunction(&platform_util::OpenItem, path)); |
| 635 | #endif |
| 636 | } |
| 637 | |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 638 | void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) { |
| 639 | #if defined(OS_MACOSX) |
| 640 | // Mac needs to run this operation on the UI thread. |
| 641 | platform_util::ShowItemInFolder(path); |
| 642 | #else |
| 643 | BrowserThread::PostTask( |
| 644 | BrowserThread::FILE, FROM_HERE, |
| 645 | NewRunnableFunction(&platform_util::ShowItemInFolder, path)); |
| 646 | #endif |
| 647 | } |
| 648 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 649 | void ChromeContentBrowserClient::AllowCertificateError( |
| 650 | SSLCertErrorHandler* handler, |
| 651 | bool overridable, |
[email protected] | 8a27abf | 2011-09-30 21:59:58 | [diff] [blame] | 652 | const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) { |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 653 | // If the tab is being prerendered, cancel the prerender and the request. |
| 654 | TabContents* tab = tab_util::GetTabContentsByID( |
| 655 | handler->render_process_host_id(), |
| 656 | handler->tab_contents_id()); |
| 657 | if (!tab) { |
| 658 | NOTREACHED(); |
| 659 | return; |
| 660 | } |
| 661 | prerender::PrerenderManager* prerender_manager = |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 662 | prerender::PrerenderManagerFactory::GetForProfile( |
| 663 | Profile::FromBrowserContext(tab->browser_context())); |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 664 | if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) { |
| 665 | if (prerender_manager->prerender_tracker()->TryCancel( |
| 666 | handler->render_process_host_id(), |
| 667 | handler->tab_contents_id(), |
| 668 | prerender::FINAL_STATUS_SSL_ERROR)) { |
| 669 | handler->CancelRequest(); |
| 670 | return; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | // Otherwise, display an SSL blocking page. |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 675 | SSLBlockingPage* blocking_page = new SSLBlockingPage( |
| 676 | handler, overridable, callback); |
| 677 | blocking_page->Show(); |
| 678 | } |
| 679 | |
[email protected] | c99c442e | 2011-08-24 11:37:30 | [diff] [blame] | 680 | void ChromeContentBrowserClient::SelectClientCertificate( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 681 | int render_process_id, |
| 682 | int render_view_id, |
| 683 | SSLClientAuthHandler* handler) { |
| 684 | TabContents* tab = tab_util::GetTabContentsByID( |
| 685 | render_process_id, render_view_id); |
| 686 | if (!tab) { |
| 687 | NOTREACHED(); |
| 688 | return; |
| 689 | } |
| 690 | |
| 691 | TabContentsWrapper* wrapper = |
| 692 | TabContentsWrapper::GetCurrentWrapperForContents(tab); |
[email protected] | c99c442e | 2011-08-24 11:37:30 | [diff] [blame] | 693 | wrapper->ssl_helper()->SelectClientCertificate(handler); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | void ChromeContentBrowserClient::AddNewCertificate( |
| 697 | net::URLRequest* request, |
| 698 | net::X509Certificate* cert, |
| 699 | int render_process_id, |
| 700 | int render_view_id) { |
| 701 | // The handler will run the UI and delete itself when it's finished. |
| 702 | new SSLAddCertHandler(request, cert, render_process_id, render_view_id); |
| 703 | } |
| 704 | |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 705 | void ChromeContentBrowserClient::RequestDesktopNotificationPermission( |
| 706 | const GURL& source_origin, |
| 707 | int callback_context, |
| 708 | int render_process_id, |
| 709 | int render_view_id) { |
| 710 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 711 | render_process_id, render_view_id); |
| 712 | if (!rvh) { |
| 713 | NOTREACHED(); |
| 714 | return; |
| 715 | } |
| 716 | |
| 717 | RenderProcessHost* process = rvh->process(); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 718 | Profile* profile = Profile::FromBrowserContext(process->browser_context()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 719 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 720 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 721 | service->RequestPermission( |
| 722 | source_origin, render_process_id, render_view_id, callback_context, |
| 723 | tab_util::GetTabContentsByID(render_process_id, render_view_id)); |
| 724 | } |
| 725 | |
| 726 | WebKit::WebNotificationPresenter::Permission |
| 727 | ChromeContentBrowserClient::CheckDesktopNotificationPermission( |
| 728 | const GURL& source_url, |
| 729 | const content::ResourceContext& context) { |
| 730 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 731 | ProfileIOData* io_data = |
| 732 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 733 | |
| 734 | const Extension* extension = |
| 735 | io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url); |
| 736 | if (extension && |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 737 | extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) { |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 738 | return WebKit::WebNotificationPresenter::PermissionAllowed; |
| 739 | } |
| 740 | |
| 741 | // Fall back to the regular notification preferences, which works on an |
| 742 | // origin basis. |
| 743 | return io_data->GetNotificationService() ? |
| 744 | io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) : |
| 745 | WebKit::WebNotificationPresenter::PermissionNotAllowed; |
| 746 | } |
| 747 | |
| 748 | void ChromeContentBrowserClient::ShowDesktopNotification( |
| 749 | const DesktopNotificationHostMsg_Show_Params& params, |
| 750 | int render_process_id, |
| 751 | int render_view_id, |
| 752 | bool worker) { |
| 753 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 754 | render_process_id, render_view_id); |
| 755 | if (!rvh) { |
| 756 | NOTREACHED(); |
| 757 | return; |
| 758 | } |
| 759 | |
| 760 | RenderProcessHost* process = rvh->process(); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 761 | Profile* profile = Profile::FromBrowserContext(process->browser_context()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 762 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 763 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 764 | service->ShowDesktopNotification( |
| 765 | params, render_process_id, render_view_id, |
| 766 | worker ? DesktopNotificationService::WorkerNotification : |
| 767 | DesktopNotificationService::PageNotification); |
| 768 | } |
| 769 | |
| 770 | void ChromeContentBrowserClient::CancelDesktopNotification( |
| 771 | int render_process_id, |
| 772 | int render_view_id, |
| 773 | int notification_id) { |
| 774 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 775 | render_process_id, render_view_id); |
| 776 | if (!rvh) { |
| 777 | NOTREACHED(); |
| 778 | return; |
| 779 | } |
| 780 | |
| 781 | RenderProcessHost* process = rvh->process(); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 782 | Profile* profile = Profile::FromBrowserContext(process->browser_context()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 783 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 784 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 785 | service->CancelDesktopNotification( |
| 786 | render_process_id, render_view_id, notification_id); |
| 787 | } |
| 788 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 789 | bool ChromeContentBrowserClient::CanCreateWindow( |
| 790 | const GURL& source_url, |
| 791 | WindowContainerType container_type, |
| 792 | const content::ResourceContext& context) { |
| 793 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 794 | // If the opener is trying to create a background window but doesn't have |
| 795 | // the appropriate permission, fail the attempt. |
| 796 | if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
| 797 | ProfileIOData* io_data = |
| 798 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 799 | const Extension* extension = |
| 800 | io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url); |
| 801 | return (extension && |
[email protected] | 0d3e4a2 | 2011-06-23 19:02:52 | [diff] [blame] | 802 | extension->HasAPIPermission(ExtensionAPIPermission::kBackground)); |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 803 | } |
| 804 | return true; |
| 805 | } |
| 806 | |
| 807 | std::string ChromeContentBrowserClient::GetWorkerProcessTitle( |
| 808 | const GURL& url, const content::ResourceContext& context) { |
| 809 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 810 | // Check if it's an extension-created worker, in which case we want to use |
| 811 | // the name of the extension. |
| 812 | ProfileIOData* io_data = |
| 813 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 814 | const Extension* extension = |
| 815 | io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); |
| 816 | return extension ? extension->name() : std::string(); |
| 817 | } |
| 818 | |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 819 | ResourceDispatcherHost* |
| 820 | ChromeContentBrowserClient::GetResourceDispatcherHost() { |
| 821 | return g_browser_process->resource_dispatcher_host(); |
| 822 | } |
| 823 | |
| 824 | ui::Clipboard* ChromeContentBrowserClient::GetClipboard() { |
| 825 | return g_browser_process->clipboard(); |
| 826 | } |
| 827 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 828 | MHTMLGenerationManager* |
| 829 | ChromeContentBrowserClient::GetMHTMLGenerationManager() { |
| 830 | return g_browser_process->mhtml_generation_manager(); |
| 831 | } |
| 832 | |
[email protected] | dce50276 | 2011-07-20 08:53:49 | [diff] [blame] | 833 | DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() { |
| 834 | return g_browser_process->devtools_manager(); |
| 835 | } |
| 836 | |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 837 | net::NetLog* ChromeContentBrowserClient::GetNetLog() { |
| 838 | return g_browser_process->net_log(); |
| 839 | } |
| 840 | |
[email protected] | 3bc0b56 | 2011-08-24 23:51:04 | [diff] [blame] | 841 | speech_input::SpeechInputManager* |
| 842 | ChromeContentBrowserClient::GetSpeechInputManager() { |
| 843 | return speech_input::ChromeSpeechInputManager::GetInstance(); |
| 844 | } |
| 845 | |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 846 | AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() { |
| 847 | return new ChromeAccessTokenStore(); |
| 848 | } |
| 849 | |
[email protected] | dbae6b0 | 2011-06-29 23:51:41 | [diff] [blame] | 850 | bool ChromeContentBrowserClient::IsFastShutdownPossible() { |
| 851 | const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 852 | return !browser_command_line.HasSwitch(switches::kChromeFrame); |
| 853 | } |
| 854 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 855 | WebPreferences ChromeContentBrowserClient::GetWebkitPrefs( |
| 856 | content::BrowserContext* browser_context, bool is_web_ui) { |
| 857 | return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context, |
| 858 | is_web_ui); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | void ChromeContentBrowserClient::UpdateInspectorSetting( |
| 862 | RenderViewHost* rvh, const std::string& key, const std::string& value) { |
| 863 | RenderViewHostDelegateHelper::UpdateInspectorSetting( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 864 | rvh->process()->browser_context(), key, value); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) { |
| 868 | RenderViewHostDelegateHelper::ClearInspectorSettings( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 869 | rvh->process()->browser_context()); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 870 | } |
| 871 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 872 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 873 | BrowserURLHandler* handler) { |
| 874 | // Add the default URL handlers. |
| 875 | handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, |
| 876 | BrowserURLHandler::null_handler()); |
| 877 | handler->AddHandlerPair(BrowserURLHandler::null_handler(), |
| 878 | &ExtensionWebUI::HandleChromeURLOverrideReverse); |
| 879 | |
| 880 | // about: |
| 881 | handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 882 | BrowserURLHandler::null_handler()); |
| 883 | // chrome: & friends. |
| 884 | handler->AddHandlerPair(&HandleWebUI, |
| 885 | BrowserURLHandler::null_handler()); |
| 886 | } |
| 887 | |
| 888 | void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 889 | Profile* profile = Profile::FromBrowserContext( |
| 890 | rvh->site_instance()->GetProcess()->browser_context()); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 891 | BrowsingDataRemover* remover = new BrowsingDataRemover(profile, |
| 892 | BrowsingDataRemover::EVERYTHING, |
| 893 | base::Time()); |
| 894 | remover->Remove(BrowsingDataRemover::REMOVE_CACHE); |
| 895 | // BrowsingDataRemover takes care of deleting itself when done. |
| 896 | } |
| 897 | |
| 898 | void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 899 | Profile* profile = Profile::FromBrowserContext( |
| 900 | rvh->site_instance()->GetProcess()->browser_context()); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 901 | BrowsingDataRemover* remover = new BrowsingDataRemover(profile, |
| 902 | BrowsingDataRemover::EVERYTHING, |
| 903 | base::Time()); |
[email protected] | dceaa91 | 2011-09-06 17:17:23 | [diff] [blame] | 904 | int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA; |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 905 | remover->Remove(remove_mask); |
| 906 | // BrowsingDataRemover takes care of deleting itself when done. |
| 907 | } |
| 908 | |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 909 | FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
| 910 | return download_util::GetDefaultDownloadDirectory(); |
| 911 | } |
| 912 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 913 | std::string ChromeContentBrowserClient::GetDefaultDownloadName() { |
| 914 | return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 915 | } |
| 916 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 917 | #if defined(OS_LINUX) |
| 918 | int ChromeContentBrowserClient::GetCrashSignalFD( |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 919 | const CommandLine& command_line) { |
| 920 | if (command_line.HasSwitch(switches::kExtensionProcess)) { |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 921 | ExtensionCrashHandlerHostLinux* crash_handler = |
| 922 | ExtensionCrashHandlerHostLinux::GetInstance(); |
| 923 | return crash_handler->GetDeathSignalSocket(); |
| 924 | } |
| 925 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 926 | std::string process_type = |
| 927 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 928 | |
| 929 | if (process_type == switches::kRendererProcess) |
| 930 | return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 931 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 932 | if (process_type == switches::kPluginProcess) |
| 933 | return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 934 | |
| 935 | if (process_type == switches::kPpapiPluginProcess) |
| 936 | return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 937 | |
| 938 | if (process_type == switches::kGpuProcess) |
| 939 | return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 940 | |
| 941 | return -1; |
| 942 | } |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 943 | #endif // defined(OS_LINUX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 944 | |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 945 | #if defined(OS_WIN) |
| 946 | const wchar_t* ChromeContentBrowserClient::GetResourceDllName() { |
| 947 | return chrome::kBrowserResourcesDll; |
| 948 | } |
| 949 | #endif |
| 950 | |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 951 | #if defined(USE_NSS) |
| 952 | crypto::CryptoModuleBlockingPasswordDelegate* |
| 953 | ChromeContentBrowserClient::GetCryptoPasswordDelegate( |
| 954 | const GURL& url) { |
| 955 | return browser::NewCryptoModuleBlockingDialogDelegate( |
| 956 | browser::kCryptoModulePasswordKeygen, url.host()); |
| 957 | } |
| 958 | #endif |
| 959 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 960 | } // namespace chrome |