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