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