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