[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 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> |
[email protected] | 1033acd | 2012-02-08 08:46:27 | [diff] [blame] | 8 | #include <utility> |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 11 | #include "base/bind.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 13 | #include "base/utf_string_conversions.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 14 | #include "chrome/app/breakpad_mac.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 15 | #include "chrome/browser/browser_about_handler.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 16 | #include "chrome/browser/browser_process.h" |
[email protected] | 3b8f7e3 | 2011-07-13 11:52:23 | [diff] [blame] | 17 | #include "chrome/browser/browsing_data_remover.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 18 | #include "chrome/browser/character_encoding.h" |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 19 | #include "chrome/browser/chrome_benchmarking_message_filter.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 20 | #include "chrome/browser/chrome_quota_permission_context.h" |
[email protected] | edece21 | 2011-11-16 11:56:56 | [diff] [blame] | 21 | #include "chrome/browser/content_settings/content_settings_utils.h" |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 22 | #include "chrome/browser/content_settings/cookie_settings.h" |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 23 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 24 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 25 | #include "chrome/browser/download/download_util.h" |
[email protected] | 6e672df | 2012-01-25 10:39:47 | [diff] [blame] | 26 | #include "chrome/browser/extensions/api/webrequest/webrequest_api.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_info_map.h" |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 28 | #include "chrome/browser/extensions/extension_message_handler.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 29 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 31 | #include "chrome/browser/extensions/extension_webkit_preferences.h" |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 32 | #include "chrome/browser/geolocation/chrome_access_token_store.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 33 | #include "chrome/browser/google/google_util.h" |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 34 | #include "chrome/browser/net/chrome_net_log.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 35 | #include "chrome/browser/notifications/desktop_notification_service.h" |
| 36 | #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 37 | #include "chrome/browser/platform_util.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 38 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 39 | #include "chrome/browser/prefs/scoped_user_pref_update.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 40 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 41 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 42 | #include "chrome/browser/prerender/prerender_tracker.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 43 | #include "chrome/browser/printing/printing_message_filter.h" |
| 44 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 45 | #include "chrome/browser/profiles/profile_io_data.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 46 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | 53a0afa | 2011-04-28 02:09:33 | [diff] [blame] | 47 | #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 48 | #include "chrome/browser/renderer_host/plugin_info_message_filter.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 49 | #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" |
[email protected] | 3bc0b56 | 2011-08-24 23:51:04 | [diff] [blame] | 50 | #include "chrome/browser/speech/chrome_speech_input_manager.h" |
[email protected] | 8ec7126 | 2011-07-28 08:12:46 | [diff] [blame] | 51 | #include "chrome/browser/spellchecker/spellcheck_message_filter.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 52 | #include "chrome/browser/ssl/ssl_add_cert_handler.h" |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 53 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 54 | #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" |
| 55 | #include "chrome/browser/tab_contents/tab_util.h" |
| 56 | #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 57 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 58 | #include "chrome/browser/user_style_sheet_watcher.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 59 | #include "chrome/common/child_process_logging.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 60 | #include "chrome/common/chrome_constants.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 61 | #include "chrome/common/chrome_switches.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 62 | #include "chrome/common/extensions/extension.h" |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 63 | #include "chrome/common/extensions/extension_set.h" |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 64 | #include "chrome/common/logging_chrome.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 65 | #include "chrome/common/pref_names.h" |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 66 | #include "chrome/common/render_messages.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 67 | #include "chrome/common/url_constants.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 68 | #include "content/browser/browser_url_handler.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 69 | #include "content/browser/renderer_host/render_view_host.h" |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 70 | #include "content/browser/resource_context.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 71 | #include "content/browser/ssl/ssl_cert_error_handler.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 72 | #include "content/browser/ssl/ssl_client_auth_handler.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 73 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 74 | #include "content/public/browser/child_process_security_policy.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 75 | #include "content/public/browser/render_process_host.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 76 | #include "content/public/browser/site_instance.h" |
[email protected] | 91ee368 | 2012-01-19 15:02:19 | [diff] [blame] | 77 | #include "content/public/browser/web_contents.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 78 | #include "content/public/browser/web_contents_view.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 79 | #include "grit/generated_resources.h" |
[email protected] | 29b25d09 | 2011-06-29 20:57:34 | [diff] [blame] | 80 | #include "grit/ui_resources.h" |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 81 | #include "net/base/cookie_monster.h" |
| 82 | #include "net/base/cookie_options.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 83 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 84 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 85 | #include "webkit/glue/webpreferences.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 86 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 87 | #if defined(OS_WIN) |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 88 | #include "chrome/browser/chrome_browser_main_win.h" |
| 89 | #elif defined(OS_MACOSX) |
| 90 | #include "chrome/browser/chrome_browser_main_mac.h" |
[email protected] | 7ceb9901 | 2011-12-21 08:05:56 | [diff] [blame] | 91 | #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 92 | #elif defined(OS_CHROMEOS) |
| 93 | #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 94 | #elif defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 95 | #include "chrome/browser/chrome_browser_main_linux.h" |
| 96 | #elif defined(OS_POSIX) |
| 97 | #include "chrome/browser/chrome_browser_main_posix.h" |
| 98 | #endif |
| 99 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 100 | #if defined(TOOLKIT_USES_GTK) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 101 | #include "chrome/browser/chrome_browser_main_extra_parts_gtk.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 102 | #endif |
| 103 | |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 104 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 105 | #include "chrome/browser/chrome_browser_main_extra_parts_views.h" |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 106 | #endif |
| 107 | |
| 108 | #if defined(USE_AURA) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 109 | #include "chrome/browser/chrome_browser_main_extra_parts_aura.h" |
| 110 | #endif |
| 111 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 112 | #if defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 113 | #include "base/linux_util.h" |
| 114 | #include "chrome/browser/crash_handler_host_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 115 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 116 | |
[email protected] | 080f34f | 2011-09-20 05:39:26 | [diff] [blame] | 117 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 118 | #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" |
[email protected] | c92f4ed | 2011-10-21 19:50:21 | [diff] [blame] | 119 | #elif defined(TOOLKIT_USES_GTK) |
[email protected] | 9bce777 | 2011-11-16 01:24:45 | [diff] [blame] | 120 | #include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h" |
[email protected] | 9058042 | 2012-01-12 00:26:22 | [diff] [blame] | 121 | #include "content/browser/tab_contents/tab_contents_view_gtk.h" |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 122 | #elif defined(OS_MACOSX) |
[email protected] | cce3ab7 | 2012-02-04 18:05:16 | [diff] [blame] | 123 | #include "chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.h" |
[email protected] | eb668c9 | 2012-02-06 15:35:29 | [diff] [blame] | 124 | #include "content/browser/tab_contents/web_contents_view_mac.h" |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 125 | #endif |
| 126 | |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 127 | #if defined(USE_NSS) |
| 128 | #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 129 | #endif |
| 130 | |
[email protected] | c8c7718 | 2011-12-21 15:04:47 | [diff] [blame] | 131 | using content::AccessTokenStore; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 132 | using content::BrowserThread; |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 133 | using content::ChildProcessSecurityPolicy; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 134 | using content::SiteInstance; |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 135 | using content::WebContents; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 136 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 137 | namespace { |
| 138 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 139 | // Handles rewriting Web UI URLs. |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 140 | bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 141 | if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 142 | 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)) { |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 181 | const Extension* extension = |
| 182 | service->extensions()->GetByID(url.host()); |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 183 | if (extension && extension->is_storage_isolated()) |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 184 | return PRIV_ISOLATED; |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 185 | if (extension && extension->is_hosted_app()) |
| 186 | return PRIV_HOSTED; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 187 | |
| 188 | return PRIV_EXTENSION; |
| 189 | } |
| 190 | |
| 191 | return PRIV_NORMAL; |
| 192 | } |
| 193 | |
| 194 | RenderProcessHostPrivilege GetProcessPrivilege( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 195 | content::RenderProcessHost* process_host, |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 196 | extensions::ProcessMap* process_map, |
| 197 | ExtensionService* service) { |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 198 | std::set<std::string> extension_ids = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 199 | process_map->GetExtensionsInProcess(process_host->GetID()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 200 | if (extension_ids.empty()) |
[email protected] | 676f6ab | 2011-10-19 20:23:21 | [diff] [blame] | 201 | return PRIV_NORMAL; |
| 202 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 203 | for (std::set<std::string>::iterator iter = extension_ids.begin(); |
| 204 | iter != extension_ids.end(); ++iter) { |
| 205 | const Extension* extension = service->GetExtensionById(*iter, false); |
| 206 | if (extension && extension->is_storage_isolated()) |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 207 | return PRIV_ISOLATED; |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 208 | if (extension && extension->is_hosted_app()) |
| 209 | return PRIV_HOSTED; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 210 | } |
| 211 | |
[email protected] | 676f6ab | 2011-10-19 20:23:21 | [diff] [blame] | 212 | return PRIV_EXTENSION; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 213 | } |
| 214 | |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 215 | bool IsIsolatedAppInProcess(const GURL& site_url, |
| 216 | content::RenderProcessHost* process_host, |
| 217 | extensions::ProcessMap* process_map, |
| 218 | ExtensionService* service) { |
| 219 | std::set<std::string> extension_ids = |
| 220 | process_map->GetExtensionsInProcess(process_host->GetID()); |
| 221 | if (extension_ids.empty()) |
| 222 | return false; |
| 223 | |
| 224 | for (std::set<std::string>::iterator iter = extension_ids.begin(); |
| 225 | iter != extension_ids.end(); ++iter) { |
| 226 | const Extension* extension = service->GetExtensionById(*iter, false); |
| 227 | if (extension && |
| 228 | extension->is_storage_isolated() && |
| 229 | extension->url() == site_url) |
| 230 | return true; |
| 231 | } |
| 232 | |
| 233 | return false; |
| 234 | } |
| 235 | |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 236 | bool CertMatchesFilter(const net::X509Certificate& cert, |
| 237 | const base::DictionaryValue& filter) { |
| 238 | // TODO(markusheintz): This is the minimal required filter implementation. |
| 239 | // Implement a better matcher. |
| 240 | |
| 241 | // An empty filter matches any client certificate since no requirements are |
| 242 | // specified at all. |
| 243 | if (filter.empty()) |
| 244 | return true; |
| 245 | |
| 246 | std::string common_name; |
| 247 | if (filter.GetString("ISSUER.CN", &common_name) && |
| 248 | (cert.issuer().common_name == common_name)) { |
| 249 | return true; |
| 250 | } |
| 251 | return false; |
| 252 | } |
| 253 | |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 254 | // Fills |map| with the per-script font prefs under path |map_name|. |
| 255 | void FillFontFamilyMap(const PrefService* prefs, |
| 256 | const char* map_name, |
| 257 | WebPreferences::ScriptFontFamilyMap* map) { |
| 258 | for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { |
| 259 | const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; |
| 260 | std::string pref_name = base::StringPrintf("%s.%s", map_name, script); |
| 261 | std::string font_family = prefs->GetString(pref_name.c_str()); |
| 262 | if (!font_family.empty()) |
| 263 | map->push_back(std::make_pair(script, UTF8ToUTF16(font_family))); |
| 264 | } |
| 265 | } |
| 266 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 267 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 268 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 269 | namespace chrome { |
| 270 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 271 | content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( |
| 272 | const content::MainFunctionParams& parameters) { |
| 273 | ChromeBrowserMainParts* main_parts; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 274 | // Construct the Main browser parts based on the OS type. |
| 275 | #if defined(OS_WIN) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 276 | main_parts = new ChromeBrowserMainPartsWin(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 277 | #elif defined(OS_MACOSX) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 278 | main_parts = new ChromeBrowserMainPartsMac(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 279 | #elif defined(OS_CHROMEOS) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 280 | main_parts = new ChromeBrowserMainPartsChromeos(parameters); |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 281 | #elif defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 282 | main_parts = new ChromeBrowserMainPartsLinux(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 283 | #elif defined(OS_POSIX) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 284 | main_parts = new ChromeBrowserMainPartsPosix(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 285 | #else |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 286 | NOTREACHED(); |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 287 | main_parts = new ChromeBrowserMainParts(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 288 | #endif |
| 289 | |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 290 | // Construct additional browser parts. Stages are called in the order in |
| 291 | // which they are added. |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 292 | #if defined(TOOLKIT_USES_GTK) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 293 | main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk()); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 294 | #endif |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 295 | |
| 296 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 297 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 298 | #endif |
| 299 | |
| 300 | #if defined(USE_AURA) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 301 | main_parts->AddParts(new ChromeBrowserMainExtraPartsAura()); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 302 | #endif |
| 303 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 304 | return main_parts; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 305 | } |
| 306 | |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 307 | content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView( |
[email protected] | 8dad546b | 2012-01-17 21:47:35 | [diff] [blame] | 308 | WebContents* web_contents) { |
[email protected] | 080f34f | 2011-09-20 05:39:26 | [diff] [blame] | 309 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 8dad546b | 2012-01-17 21:47:35 | [diff] [blame] | 310 | return new TabContentsViewViews(web_contents); |
[email protected] | c92f4ed | 2011-10-21 19:50:21 | [diff] [blame] | 311 | #elif defined(TOOLKIT_USES_GTK) |
[email protected] | 8dad546b | 2012-01-17 21:47:35 | [diff] [blame] | 312 | return new content::TabContentsViewGtk(web_contents, |
[email protected] | 9058042 | 2012-01-12 00:26:22 | [diff] [blame] | 313 | new ChromeTabContentsViewWrapperGtk); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 314 | #elif defined(OS_MACOSX) |
[email protected] | eb668c9 | 2012-02-06 15:35:29 | [diff] [blame] | 315 | return web_contents_view_mac::CreateWebContentsView( |
[email protected] | cce3ab7 | 2012-02-04 18:05:16 | [diff] [blame] | 316 | web_contents, |
| 317 | chrome_web_contents_view_mac_delegate::CreateWebContentsViewMacDelegate( |
| 318 | web_contents)); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 319 | #else |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 320 | #error Need to create your platform WebContentsView here. |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 321 | #endif |
| 322 | } |
| 323 | |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 324 | void ChromeContentBrowserClient::RenderViewHostCreated( |
| 325 | RenderViewHost* render_view_host) { |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 326 | |
| 327 | SiteInstance* site_instance = render_view_host->site_instance(); |
| 328 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 329 | site_instance->GetBrowserContext()); |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 330 | |
| 331 | new ChromeRenderViewHostObserver(render_view_host, |
| 332 | profile->GetNetworkPredictor()); |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 333 | new ExtensionMessageHandler(render_view_host); |
[email protected] | 85f0a57 | 2012-02-07 22:20:13 | [diff] [blame] | 334 | |
| 335 | if (render_view_host->delegate()->GetRenderViewType() == |
| 336 | content::VIEW_TYPE_INTERSTITIAL_PAGE) { |
| 337 | render_view_host->Send(new ChromeViewMsg_SetAsInterstitial( |
| 338 | render_view_host->routing_id())); |
| 339 | } |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 340 | } |
| 341 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 342 | void ChromeContentBrowserClient::RenderProcessHostCreated( |
| 343 | content::RenderProcessHost* host) { |
| 344 | int id = host->GetID(); |
| 345 | Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
| 346 | host->GetChannel()->AddFilter(new ChromeRenderMessageFilter( |
[email protected] | c47cfd6 | 2011-04-29 21:27:02 | [diff] [blame] | 347 | id, profile, profile->GetRequestContextForRenderProcess(id))); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 348 | host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile)); |
| 349 | host->GetChannel()->AddFilter(new PrintingMessageFilter()); |
| 350 | host->GetChannel()->AddFilter( |
[email protected] | c47cfd6 | 2011-04-29 21:27:02 | [diff] [blame] | 351 | new SearchProviderInstallStateMessageFilter(id, profile)); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 352 | host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id)); |
[email protected] | 7ceb9901 | 2011-12-21 08:05:56 | [diff] [blame] | 353 | #if defined(OS_MACOSX) |
| 354 | host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac()); |
| 355 | #endif |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 356 | host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter( |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 357 | id, profile, profile->GetRequestContextForRenderProcess(id))); |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 358 | |
[email protected] | 2ccf45c | 2011-08-19 23:35:50 | [diff] [blame] | 359 | host->Send(new ChromeViewMsg_SetIsIncognitoProcess( |
| 360 | profile->IsOffTheRecord())); |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 361 | |
| 362 | SendExtensionWebRequestStatusToHost(host); |
[email protected] | edece21 | 2011-11-16 11:56:56 | [diff] [blame] | 363 | |
| 364 | RendererContentSettingRules rules; |
| 365 | GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules); |
| 366 | host->Send(new ChromeViewMsg_SetContentSettingRules(rules)); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 367 | } |
| 368 | |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 369 | content::WebUIControllerFactory* |
| 370 | ChromeContentBrowserClient::GetWebUIControllerFactory() { |
| 371 | return ChromeWebUIControllerFactory::GetInstance(); |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 372 | } |
| 373 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 374 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
| 375 | content::BrowserContext* browser_context, const GURL& url) { |
| 376 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 377 | // Get the effective URL for the given actual URL. If the URL is part of an |
| 378 | // installed app, the effective URL is an extension URL with the ID of that |
| 379 | // extension as the host. This has the effect of grouping apps together in |
| 380 | // a common SiteInstance. |
| 381 | if (!profile || !profile->GetExtensionService()) |
| 382 | return url; |
| 383 | |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 384 | const Extension* extension = profile->GetExtensionService()->extensions()-> |
| 385 | GetHostedAppByURL(ExtensionURLInfo(url)); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 386 | if (!extension) |
| 387 | return url; |
| 388 | |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 389 | // Bookmark apps do not use the hosted app process model, and should be |
| 390 | // treated as normal URLs. |
| 391 | if (extension->from_bookmark()) |
| 392 | return url; |
| 393 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 394 | // If the URL is part of an extension's web extent, convert it to an |
| 395 | // extension URL. |
| 396 | return extension->GetResourceURL(url.path()); |
| 397 | } |
| 398 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 399 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 400 | content::BrowserContext* browser_context, const GURL& effective_url) { |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 401 | // Non-extension URLs should generally use process-per-site-instance. |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 402 | // Because we expect to use the effective URL, URLs for hosted apps (apart |
| 403 | // from bookmark apps) should have an extension scheme by now. |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 404 | if (!effective_url.SchemeIs(chrome::kExtensionScheme)) |
| 405 | return false; |
| 406 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 407 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 408 | if (!profile || !profile->GetExtensionService()) |
| 409 | return false; |
| 410 | |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 411 | const Extension* extension = profile->GetExtensionService()->extensions()-> |
| 412 | GetExtensionOrAppByURL(ExtensionURLInfo(effective_url)); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 413 | if (!extension) |
| 414 | return false; |
| 415 | |
| 416 | // If the URL is part of a hosted app that does not have the background |
| 417 | // permission, we want to give each instance its own process to improve |
| 418 | // responsiveness. |
| 419 | if (extension->GetType() == Extension::TYPE_HOSTED_APP && |
| 420 | !extension->HasAPIPermission(ExtensionAPIPermission::kBackground)) |
| 421 | return false; |
| 422 | |
| 423 | // Hosted apps that have the background permission must use process per site, |
| 424 | // since all instances can make synchronous calls to the background window. |
| 425 | // Other extensions should use process per site as well. |
| 426 | return true; |
| 427 | } |
| 428 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 429 | bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { |
| 430 | return ProfileIOData::IsHandledURL(url); |
| 431 | } |
| 432 | |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 433 | bool ChromeContentBrowserClient::IsSuitableHost( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 434 | content::RenderProcessHost* process_host, |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 435 | const GURL& site_url) { |
| 436 | Profile* profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 437 | Profile::FromBrowserContext(process_host->GetBrowserContext()); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 438 | ExtensionService* service = profile->GetExtensionService(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 439 | extensions::ProcessMap* process_map = service->process_map(); |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 440 | |
[email protected] | ffa9760 | 2011-11-17 17:55:52 | [diff] [blame] | 441 | // Don't allow the Task Manager to share a process with anything else. |
| 442 | // Otherwise it can affect the renderers it is observing. |
| 443 | // Note: we could create another RenderProcessHostPrivilege bucket for |
| 444 | // this to allow multiple chrome://tasks instances to share, but that's |
| 445 | // a very unlikely case without serious consequences. |
| 446 | if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin()) |
| 447 | return false; |
| 448 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 449 | // These may be NULL during tests. In that case, just assume any site can |
| 450 | // share any host. |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 451 | if (!service || !process_map) |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 452 | return true; |
| 453 | |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 454 | // Experimental: |
| 455 | // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages |
| 456 | // to share a renderer process. (We could allow pages from the same site or |
| 457 | // extensions of the same type to share, if we knew what the given process |
| 458 | // was dedicated to. Allowing no sharing is simpler for now.) This may |
| 459 | // cause resource exhaustion issues if too many sites are open at once. |
| 460 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 461 | if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation)) |
| 462 | return false; |
| 463 | |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 464 | // An isolated app is only allowed to share with the exact same app in order |
| 465 | // to provide complete renderer process isolation. This also works around |
| 466 | // issue http://crbug.com/85588, where different isolated apps in the same |
| 467 | // process would end up using the first app's storage contexts. |
| 468 | RenderProcessHostPrivilege privilege_required = |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 469 | GetPrivilegeRequiredByUrl(site_url, service); |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 470 | if (privilege_required == PRIV_ISOLATED) |
| 471 | return IsIsolatedAppInProcess(site_url, process_host, process_map, service); |
| 472 | |
| 473 | // Otherwise, just make sure the process privilege matches the privilege |
| 474 | // required by the site. |
| 475 | return GetProcessPrivilege(process_host, process_map, service) == |
| 476 | privilege_required; |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 477 | } |
| 478 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 479 | void ChromeContentBrowserClient::SiteInstanceGotProcess( |
| 480 | SiteInstance* site_instance) { |
| 481 | CHECK(site_instance->HasProcess()); |
| 482 | |
| 483 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 484 | site_instance->GetBrowserContext()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 485 | ExtensionService* service = profile->GetExtensionService(); |
| 486 | if (!service) |
| 487 | return; |
| 488 | |
| 489 | const Extension* extension = |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 490 | service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo( |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 491 | site_instance->GetSite())); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 492 | if (!extension) |
| 493 | return; |
| 494 | |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 495 | service->process_map()->Insert(extension->id(), |
| 496 | site_instance->GetProcess()->GetID(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 497 | site_instance->GetId()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 498 | BrowserThread::PostTask( |
| 499 | BrowserThread::IO, FROM_HERE, |
| 500 | base::Bind(&ExtensionInfoMap::RegisterExtensionProcess, |
| 501 | profile->GetExtensionInfoMap(), |
| 502 | extension->id(), |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 503 | site_instance->GetProcess()->GetID(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 504 | site_instance->GetId())); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | void ChromeContentBrowserClient::SiteInstanceDeleting( |
| 508 | SiteInstance* site_instance) { |
| 509 | if (!site_instance->HasProcess()) |
| 510 | return; |
| 511 | |
| 512 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 513 | site_instance->GetBrowserContext()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 514 | ExtensionService* service = profile->GetExtensionService(); |
| 515 | if (!service) |
| 516 | return; |
| 517 | |
| 518 | const Extension* extension = |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 519 | service->extensions()->GetExtensionOrAppByURL( |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 520 | ExtensionURLInfo(site_instance->GetSite())); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 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(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 526 | site_instance->GetId()); |
[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(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 533 | site_instance->GetId())); |
[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] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 599 | if (process) { |
| 600 | Profile* profile = Profile::FromBrowserContext( |
| 601 | process->GetBrowserContext()); |
| 602 | extensions::ProcessMap* process_map = |
| 603 | profile->GetExtensionService()->process_map(); |
| 604 | if (process_map && process_map->Contains(process->GetID())) |
| 605 | command_line->AppendSwitch(switches::kExtensionProcess); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 606 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 607 | PrefService* prefs = profile->GetPrefs(); |
| 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 | } |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 614 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 615 | // Disable client-side phishing detection in the renderer if it is |
| 616 | // disabled in the Profile preferences or the browser process. |
| 617 | if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) || |
| 618 | !g_browser_process->safe_browsing_detection_service()) { |
| 619 | command_line->AppendSwitch( |
| 620 | switches::kDisableClientSidePhishingDetection); |
| 621 | } |
[email protected] | 8c40da6 | 2011-07-13 22:58:46 | [diff] [blame] | 622 | } |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 623 | { |
| 624 | PrefService* local_state = g_browser_process->local_state(); |
| 625 | if (local_state && |
| 626 | !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) { |
| 627 | command_line->AppendSwitch(switches::kRendererPrintPreview); |
| 628 | } |
| 629 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 630 | |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 631 | // Please keep this in alphabetical order. |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 632 | static const char* const kSwitchNames[] = { |
| 633 | switches::kAllowHTTPBackgroundPage, |
[email protected] | 70f48c0 | 2011-12-02 21:27:48 | [diff] [blame] | 634 | switches::kAllowLegacyExtensionManifests, |
[email protected] | ef5e98e | 2011-12-06 09:49:18 | [diff] [blame] | 635 | switches::kAllowNaClSocketAPI, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 636 | switches::kAllowScriptingGallery, |
| 637 | switches::kAppsCheckoutURL, |
| 638 | switches::kAppsGalleryURL, |
[email protected] | be9d9c8 | 2011-07-13 04:17:31 | [diff] [blame] | 639 | switches::kCloudPrintServiceURL, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 640 | switches::kDebugPrint, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 641 | switches::kDumpHistogramsOnExit, |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 642 | switches::kEnableBenchmarking, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 643 | switches::kEnableCrxlessWebApps, |
| 644 | switches::kEnableExperimentalExtensionApis, |
| 645 | switches::kEnableInBrowserThumbnailing, |
| 646 | switches::kEnableIPCFuzzing, |
| 647 | switches::kEnableNaCl, |
[email protected] | 9776e82e | 2011-11-15 02:17:53 | [diff] [blame] | 648 | switches::kEnablePlatformApps, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 649 | switches::kEnableWatchdog, |
| 650 | switches::kExperimentalSpellcheckerFeatures, |
| 651 | switches::kMemoryProfiling, |
| 652 | switches::kMessageLoopHistogrammer, |
[email protected] | 2a6bb0b1 | 2011-10-05 19:18:04 | [diff] [blame] | 653 | switches::kNoRunningInsecureContent, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 654 | switches::kPpapiFlashArgs, |
| 655 | switches::kPpapiFlashInProcess, |
| 656 | switches::kPpapiFlashPath, |
| 657 | switches::kPpapiFlashVersion, |
| 658 | switches::kProfilingAtStart, |
| 659 | switches::kProfilingFile, |
| 660 | switches::kProfilingFlush, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 661 | switches::kSilentDumpOnDCHECK, |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 662 | switches::kWhitelistedExtensionID, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 663 | }; |
| 664 | |
| 665 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 666 | arraysize(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 667 | } else if (process_type == switches::kUtilityProcess) { |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 668 | static const char* const kSwitchNames[] = { |
| 669 | switches::kEnableExperimentalExtensionApis, |
| 670 | switches::kWhitelistedExtensionID, |
| 671 | }; |
| 672 | |
| 673 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 674 | arraysize(kSwitchNames)); |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 675 | } else if (process_type == switches::kPluginProcess) { |
| 676 | static const char* const kSwitchNames[] = { |
| 677 | #if defined(OS_CHROMEOS) |
| 678 | switches::kLoginProfile, |
| 679 | #endif |
| 680 | switches::kMemoryProfiling, |
| 681 | switches::kSilentDumpOnDCHECK, |
| 682 | switches::kUserDataDir, |
| 683 | }; |
| 684 | |
| 685 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 686 | arraysize(kSwitchNames)); |
| 687 | } else if (process_type == switches::kZygoteProcess) { |
| 688 | static const char* const kSwitchNames[] = { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 689 | switches::kUserDataDir, // Make logs go to the right file. |
| 690 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
| 691 | switches::kPpapiFlashInProcess, |
| 692 | switches::kPpapiFlashPath, |
| 693 | switches::kPpapiFlashVersion, |
| 694 | }; |
| 695 | |
| 696 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 697 | arraysize(kSwitchNames)); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 698 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 699 | |
| 700 | // The command line switch kEnableBenchmarking needs to be specified along |
| 701 | // with the kEnableStatsTable switch to ensure that the stats table global |
| 702 | // is initialized correctly. |
| 703 | if (command_line->HasSwitch(switches::kEnableBenchmarking)) |
| 704 | DCHECK(command_line->HasSwitch(switches::kEnableStatsTable)); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
| 708 | return g_browser_process->GetApplicationLocale(); |
| 709 | } |
| 710 | |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 711 | std::string ChromeContentBrowserClient::GetAcceptLangs( |
| 712 | content::BrowserContext* context) { |
| 713 | Profile* profile = Profile::FromBrowserContext(context); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 714 | return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 715 | } |
| 716 | |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 717 | SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() { |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 718 | ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 719 | return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 720 | } |
| 721 | |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 722 | bool ChromeContentBrowserClient::AllowAppCache( |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 723 | const GURL& manifest_url, |
[email protected] | 0a60884 | 2011-09-08 10:55:19 | [diff] [blame] | 724 | const GURL& first_party, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 725 | content::ResourceContext* context) { |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 726 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 727 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 728 | return io_data->GetCookieSettings()-> |
| 729 | IsSettingCookieAllowed(manifest_url, first_party); |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 730 | } |
| 731 | |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 732 | bool ChromeContentBrowserClient::AllowGetCookie( |
| 733 | const GURL& url, |
| 734 | const GURL& first_party, |
| 735 | const net::CookieList& cookie_list, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 736 | content::ResourceContext* context, |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 737 | int render_process_id, |
| 738 | int render_view_id) { |
| 739 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 740 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 741 | bool allow = io_data->GetCookieSettings()-> |
| 742 | IsReadingCookieAllowed(url, first_party); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 743 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 744 | BrowserThread::PostTask( |
| 745 | BrowserThread::UI, FROM_HERE, |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 746 | base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id, |
| 747 | render_view_id, url, cookie_list, !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 748 | return allow; |
| 749 | } |
| 750 | |
| 751 | bool ChromeContentBrowserClient::AllowSetCookie( |
| 752 | const GURL& url, |
| 753 | const GURL& first_party, |
| 754 | const std::string& cookie_line, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 755 | content::ResourceContext* context, |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 756 | int render_process_id, |
| 757 | int render_view_id, |
| 758 | net::CookieOptions* options) { |
| 759 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 760 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 761 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 762 | bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); |
| 763 | |
| 764 | if (cookie_settings->IsCookieSessionOnly(url)) |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 765 | options->set_force_session(); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 766 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 767 | BrowserThread::PostTask( |
| 768 | BrowserThread::UI, FROM_HERE, |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 769 | base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, |
| 770 | render_view_id, url, cookie_line, *options, !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 771 | return allow; |
| 772 | } |
| 773 | |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 774 | bool ChromeContentBrowserClient::AllowSaveLocalState( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 775 | content::ResourceContext* context) { |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 776 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 777 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 778 | return !io_data->clear_local_state_on_exit()->GetValue(); |
| 779 | } |
| 780 | |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 781 | bool ChromeContentBrowserClient::AllowWorkerDatabase( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 782 | const GURL& url, |
| 783 | const string16& name, |
| 784 | const string16& display_name, |
| 785 | unsigned long estimated_size, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 786 | content::ResourceContext* context, |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 787 | const std::vector<std::pair<int, int> >& render_views) { |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 788 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 789 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 790 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 791 | bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
| 792 | |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 793 | // Record access to database for potential display in UI. |
| 794 | std::vector<std::pair<int, int> >::const_iterator i; |
| 795 | for (i = render_views.begin(); i != render_views.end(); ++i) { |
| 796 | BrowserThread::PostTask( |
| 797 | BrowserThread::UI, FROM_HERE, |
| 798 | base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed, |
| 799 | i->first, i->second, url, name, display_name, !allow)); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | return allow; |
| 803 | } |
| 804 | |
| 805 | bool ChromeContentBrowserClient::AllowWorkerFileSystem( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 806 | const GURL& url, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 807 | content::ResourceContext* context, |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 808 | const std::vector<std::pair<int, int> >& render_views) { |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 809 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 810 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 811 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 812 | bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
| 813 | |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 814 | // Record access to file system for potential display in UI. |
| 815 | std::vector<std::pair<int, int> >::const_iterator i; |
| 816 | for (i = render_views.begin(); i != render_views.end(); ++i) { |
| 817 | BrowserThread::PostTask( |
| 818 | BrowserThread::UI, FROM_HERE, |
| 819 | base::Bind(&TabSpecificContentSettings::FileSystemAccessed, |
| 820 | i->first, i->second, url, !allow)); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | return allow; |
| 824 | } |
| 825 | |
[email protected] | 6133f92 | 2011-07-01 21:34:34 | [diff] [blame] | 826 | net::URLRequestContext* |
| 827 | ChromeContentBrowserClient::OverrideRequestContextForURL( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 828 | const GURL& url, content::ResourceContext* context) { |
[email protected] | 6133f92 | 2011-07-01 21:34:34 | [diff] [blame] | 829 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 830 | if (url.SchemeIs(chrome::kExtensionScheme)) { |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 831 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 6133f92 | 2011-07-01 21:34:34 | [diff] [blame] | 832 | return io_data->extensions_request_context(); |
| 833 | } |
| 834 | |
| 835 | return NULL; |
| 836 | } |
| 837 | |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 838 | QuotaPermissionContext* |
| 839 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
| 840 | return new ChromeQuotaPermissionContext(); |
| 841 | } |
| 842 | |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 843 | void ChromeContentBrowserClient::OpenItem(const FilePath& path) { |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 844 | platform_util::OpenItem(path); |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 845 | } |
| 846 | |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 847 | void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) { |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 848 | platform_util::ShowItemInFolder(path); |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 849 | } |
| 850 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 851 | void ChromeContentBrowserClient::AllowCertificateError( |
| 852 | SSLCertErrorHandler* handler, |
| 853 | bool overridable, |
[email protected] | 8a27abf | 2011-09-30 21:59:58 | [diff] [blame] | 854 | const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) { |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 855 | // If the tab is being prerendered, cancel the prerender and the request. |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 856 | WebContents* tab = tab_util::GetWebContentsByID( |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 857 | handler->render_process_host_id(), |
| 858 | handler->tab_contents_id()); |
| 859 | if (!tab) { |
| 860 | NOTREACHED(); |
| 861 | return; |
| 862 | } |
| 863 | prerender::PrerenderManager* prerender_manager = |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 864 | prerender::PrerenderManagerFactory::GetForProfile( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 865 | Profile::FromBrowserContext(tab->GetBrowserContext())); |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 866 | if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) { |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 867 | if (prerender_manager->prerender_tracker()->TryCancel( |
| 868 | handler->render_process_host_id(), |
| 869 | handler->tab_contents_id(), |
| 870 | prerender::FINAL_STATUS_SSL_ERROR)) { |
| 871 | handler->CancelRequest(); |
| 872 | return; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | // Otherwise, display an SSL blocking page. |
[email protected] | 85f0a57 | 2012-02-07 22:20:13 | [diff] [blame] | 877 | new SSLBlockingPage(handler, overridable, callback); |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 878 | } |
| 879 | |
[email protected] | c99c442e | 2011-08-24 11:37:30 | [diff] [blame] | 880 | void ChromeContentBrowserClient::SelectClientCertificate( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 881 | int render_process_id, |
| 882 | int render_view_id, |
| 883 | SSLClientAuthHandler* handler) { |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 884 | WebContents* tab = tab_util::GetWebContentsByID( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 885 | render_process_id, render_view_id); |
| 886 | if (!tab) { |
| 887 | NOTREACHED(); |
| 888 | return; |
| 889 | } |
| 890 | |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 891 | net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info(); |
| 892 | GURL requesting_url("https://" + cert_request_info->host_and_port); |
| 893 | DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://" |
| 894 | << cert_request_info->host_and_port; |
| 895 | |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 896 | Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 897 | DCHECK(profile); |
| 898 | scoped_ptr<Value> filter( |
| 899 | profile->GetHostContentSettingsMap()->GetWebsiteSetting( |
| 900 | requesting_url, |
| 901 | requesting_url, |
| 902 | CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 903 | std::string(), NULL)); |
| 904 | |
| 905 | if (filter.get()) { |
| 906 | // Try to automatically select a client certificate. |
| 907 | if (filter->IsType(Value::TYPE_DICTIONARY)) { |
| 908 | DictionaryValue* filter_dict = |
| 909 | static_cast<DictionaryValue*>(filter.get()); |
| 910 | |
| 911 | const std::vector<scoped_refptr<net::X509Certificate> >& |
| 912 | all_client_certs = cert_request_info->client_certs; |
| 913 | for (size_t i = 0; i < all_client_certs.size(); ++i) { |
| 914 | if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) { |
| 915 | // Use the first certificate that is matched by the filter. |
| 916 | handler->CertificateSelected(all_client_certs[i]); |
| 917 | return; |
| 918 | } |
| 919 | } |
| 920 | } else { |
| 921 | NOTREACHED(); |
| 922 | } |
| 923 | } |
| 924 | |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 925 | TabContentsWrapper* wrapper = |
| 926 | TabContentsWrapper::GetCurrentWrapperForContents(tab); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 927 | if (!wrapper) { |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 928 | // If there is no TabContentsWrapper for the given WebContents then we can't |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 929 | // show the user a dialog to select a client certificate. So we simply |
[email protected] | 2a349e9 | 2011-12-07 12:00:14 | [diff] [blame] | 930 | // proceed with no client certificate. |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 931 | handler->CertificateSelected(NULL); |
| 932 | return; |
| 933 | } |
| 934 | wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | void ChromeContentBrowserClient::AddNewCertificate( |
| 938 | net::URLRequest* request, |
| 939 | net::X509Certificate* cert, |
| 940 | int render_process_id, |
| 941 | int render_view_id) { |
| 942 | // The handler will run the UI and delete itself when it's finished. |
| 943 | new SSLAddCertHandler(request, cert, render_process_id, render_view_id); |
| 944 | } |
| 945 | |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 946 | void ChromeContentBrowserClient::RequestDesktopNotificationPermission( |
| 947 | const GURL& source_origin, |
| 948 | int callback_context, |
| 949 | int render_process_id, |
| 950 | int render_view_id) { |
| 951 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 952 | render_process_id, render_view_id); |
| 953 | if (!rvh) { |
| 954 | NOTREACHED(); |
| 955 | return; |
| 956 | } |
| 957 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 958 | content::RenderProcessHost* process = rvh->process(); |
| 959 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 960 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 961 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 962 | service->RequestPermission( |
| 963 | source_origin, render_process_id, render_view_id, callback_context, |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 964 | tab_util::GetWebContentsByID(render_process_id, render_view_id)); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | WebKit::WebNotificationPresenter::Permission |
| 968 | ChromeContentBrowserClient::CheckDesktopNotificationPermission( |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 969 | const GURL& source_origin, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 970 | content::ResourceContext* context, |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 971 | int render_process_id) { |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 972 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 973 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 974 | if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission( |
| 975 | source_origin, render_process_id, |
| 976 | ExtensionAPIPermission::kNotification)) |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 977 | return WebKit::WebNotificationPresenter::PermissionAllowed; |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 978 | |
| 979 | // Fall back to the regular notification preferences, which works on an |
| 980 | // origin basis. |
| 981 | return io_data->GetNotificationService() ? |
[email protected] | c7df61b | 2011-11-07 22:06:37 | [diff] [blame] | 982 | io_data->GetNotificationService()->HasPermission(source_origin) : |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 983 | WebKit::WebNotificationPresenter::PermissionNotAllowed; |
| 984 | } |
| 985 | |
| 986 | void ChromeContentBrowserClient::ShowDesktopNotification( |
[email protected] | 0ee57e2 | 2011-11-12 01:59:17 | [diff] [blame] | 987 | const content::ShowDesktopNotificationHostMsgParams& params, |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 988 | int render_process_id, |
| 989 | int render_view_id, |
| 990 | bool worker) { |
| 991 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 992 | render_process_id, render_view_id); |
| 993 | if (!rvh) { |
| 994 | NOTREACHED(); |
| 995 | return; |
| 996 | } |
| 997 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 998 | content::RenderProcessHost* process = rvh->process(); |
| 999 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1000 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1001 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1002 | service->ShowDesktopNotification( |
| 1003 | params, render_process_id, render_view_id, |
| 1004 | worker ? DesktopNotificationService::WorkerNotification : |
| 1005 | DesktopNotificationService::PageNotification); |
| 1006 | } |
| 1007 | |
| 1008 | void ChromeContentBrowserClient::CancelDesktopNotification( |
| 1009 | int render_process_id, |
| 1010 | int render_view_id, |
| 1011 | int notification_id) { |
| 1012 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 1013 | render_process_id, render_view_id); |
| 1014 | if (!rvh) { |
| 1015 | NOTREACHED(); |
| 1016 | return; |
| 1017 | } |
| 1018 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1019 | content::RenderProcessHost* process = rvh->process(); |
| 1020 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1021 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1022 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1023 | service->CancelDesktopNotification( |
| 1024 | render_process_id, render_view_id, notification_id); |
| 1025 | } |
| 1026 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1027 | bool ChromeContentBrowserClient::CanCreateWindow( |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1028 | const GURL& source_origin, |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1029 | WindowContainerType container_type, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 1030 | content::ResourceContext* context, |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1031 | int render_process_id) { |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1032 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1033 | // If the opener is trying to create a background window but doesn't have |
| 1034 | // the appropriate permission, fail the attempt. |
| 1035 | if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 1036 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1037 | return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission( |
| 1038 | source_origin, render_process_id, ExtensionAPIPermission::kBackground); |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1039 | } |
| 1040 | return true; |
| 1041 | } |
| 1042 | |
| 1043 | std::string ChromeContentBrowserClient::GetWorkerProcessTitle( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 1044 | const GURL& url, content::ResourceContext* context) { |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1045 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1046 | // Check if it's an extension-created worker, in which case we want to use |
| 1047 | // the name of the extension. |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame^] | 1048 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1049 | const Extension* extension = |
| 1050 | io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); |
| 1051 | return extension ? extension->name() : std::string(); |
| 1052 | } |
| 1053 | |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 1054 | void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { |
| 1055 | return g_browser_process->ResourceDispatcherHostCreated(); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | ui::Clipboard* ChromeContentBrowserClient::GetClipboard() { |
| 1059 | return g_browser_process->clipboard(); |
| 1060 | } |
| 1061 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 1062 | MHTMLGenerationManager* |
| 1063 | ChromeContentBrowserClient::GetMHTMLGenerationManager() { |
| 1064 | return g_browser_process->mhtml_generation_manager(); |
| 1065 | } |
| 1066 | |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 1067 | net::NetLog* ChromeContentBrowserClient::GetNetLog() { |
| 1068 | return g_browser_process->net_log(); |
| 1069 | } |
| 1070 | |
[email protected] | 3bc0b56 | 2011-08-24 23:51:04 | [diff] [blame] | 1071 | speech_input::SpeechInputManager* |
| 1072 | ChromeContentBrowserClient::GetSpeechInputManager() { |
| 1073 | return speech_input::ChromeSpeechInputManager::GetInstance(); |
| 1074 | } |
| 1075 | |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 1076 | AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() { |
| 1077 | return new ChromeAccessTokenStore(); |
| 1078 | } |
| 1079 | |
[email protected] | dbae6b0 | 2011-06-29 23:51:41 | [diff] [blame] | 1080 | bool ChromeContentBrowserClient::IsFastShutdownPossible() { |
| 1081 | const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 1082 | return !browser_command_line.HasSwitch(switches::kChromeFrame); |
| 1083 | } |
| 1084 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1085 | void ChromeContentBrowserClient::OverrideWebkitPrefs( |
| 1086 | RenderViewHost* rvh, WebPreferences* web_prefs) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1087 | Profile* profile = Profile::FromBrowserContext( |
| 1088 | rvh->process()->GetBrowserContext()); |
| 1089 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1090 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1091 | web_prefs->standard_font_family = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1092 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily)); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1093 | web_prefs->fixed_font_family = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1094 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily)); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1095 | web_prefs->serif_font_family = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1096 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily)); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1097 | web_prefs->sans_serif_font_family = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1098 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily)); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1099 | web_prefs->cursive_font_family = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1100 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily)); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1101 | web_prefs->fantasy_font_family = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1102 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily)); |
| 1103 | |
| 1104 | FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1105 | &web_prefs->standard_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1106 | FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1107 | &web_prefs->fixed_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1108 | FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1109 | &web_prefs->serif_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1110 | FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1111 | &web_prefs->sans_serif_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1112 | FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1113 | &web_prefs->cursive_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1114 | FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1115 | &web_prefs->fantasy_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1116 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1117 | web_prefs->default_font_size = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1118 | prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1119 | web_prefs->default_fixed_font_size = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1120 | prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1121 | web_prefs->minimum_font_size = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1122 | prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1123 | web_prefs->minimum_logical_font_size = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1124 | prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize); |
| 1125 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1126 | web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1127 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1128 | web_prefs->javascript_can_open_windows_automatically = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1129 | prefs->GetBoolean( |
| 1130 | prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1131 | web_prefs->dom_paste_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1132 | prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1133 | web_prefs->shrinks_standalone_images_to_fit = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1134 | prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit); |
| 1135 | const DictionaryValue* inspector_settings = |
| 1136 | prefs->GetDictionary(prefs::kWebKitInspectorSettings); |
| 1137 | if (inspector_settings) { |
| 1138 | for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys()); |
| 1139 | iter != inspector_settings->end_keys(); ++iter) { |
| 1140 | std::string value; |
| 1141 | if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1142 | web_prefs->inspector_settings.push_back( |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1143 | std::make_pair(*iter, value)); |
| 1144 | } |
| 1145 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1146 | web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1147 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1148 | if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled)) |
| 1149 | web_prefs->javascript_enabled = false; |
| 1150 | if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) |
| 1151 | web_prefs->web_security_enabled = false; |
| 1152 | if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled)) |
| 1153 | web_prefs->plugins_enabled = false; |
| 1154 | if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled)) |
| 1155 | web_prefs->java_enabled = false; |
| 1156 | web_prefs->loads_images_automatically = |
| 1157 | prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1158 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1159 | if (prefs->GetBoolean(prefs::kDisable3DAPIs)) |
| 1160 | web_prefs->experimental_webgl_enabled = false; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1161 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1162 | web_prefs->memory_info_enabled = |
| 1163 | prefs->GetBoolean(prefs::kEnableMemoryInfo); |
| 1164 | web_prefs->allow_displaying_insecure_content = |
| 1165 | prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent); |
| 1166 | web_prefs->allow_running_insecure_content = |
| 1167 | prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1168 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1169 | // The user stylesheet watcher may not exist in a testing profile. |
| 1170 | if (profile->GetUserStyleSheetWatcher()) { |
| 1171 | web_prefs->user_style_sheet_enabled = true; |
| 1172 | web_prefs->user_style_sheet_location = |
| 1173 | profile->GetUserStyleSheetWatcher()->user_style_sheet(); |
| 1174 | } else { |
| 1175 | web_prefs->user_style_sheet_enabled = false; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1176 | } |
| 1177 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1178 | web_prefs->unified_textchecker_enabled = CommandLine::ForCurrentProcess()-> |
| 1179 | HasSwitch(switches::kExperimentalSpellcheckerFeatures); |
[email protected] | dd5d0fb | 2012-01-18 03:37:57 | [diff] [blame] | 1180 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1181 | web_prefs->uses_universal_detector = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1182 | prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1183 | web_prefs->text_areas_are_resizable = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1184 | prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1185 | web_prefs->hyperlink_auditing_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1186 | prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); |
| 1187 | |
| 1188 | // Make sure we will set the default_encoding with canonical encoding name. |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1189 | web_prefs->default_encoding = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1190 | CharacterEncoding::GetCanonicalEncodingNameByAliasName( |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1191 | web_prefs->default_encoding); |
| 1192 | if (web_prefs->default_encoding.empty()) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1193 | prefs->ClearPref(prefs::kGlobalDefaultCharset); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1194 | web_prefs->default_encoding = |
| 1195 | prefs->GetString(prefs::kGlobalDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1196 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1197 | DCHECK(!web_prefs->default_encoding.empty()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1198 | |
| 1199 | ExtensionService* service = profile->GetExtensionService(); |
| 1200 | if (service) { |
| 1201 | const Extension* extension = service->extensions()->GetByID( |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1202 | rvh->site_instance()->GetSite().host()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1203 | extension_webkit_preferences::SetPreferences( |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1204 | extension, rvh->delegate()->GetRenderViewType(), web_prefs); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1208 | web_prefs->allow_scripts_to_close_windows = true; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1209 | } else if (rvh->delegate()->GetRenderViewType() == |
| 1210 | chrome::VIEW_TYPE_BACKGROUND_CONTENTS) { |
| 1211 | // Disable all kinds of acceleration for background pages. |
| 1212 | // See http://crbug.com/96005 and http://crbug.com/96006 |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1213 | web_prefs->force_compositing_mode = false; |
| 1214 | web_prefs->accelerated_compositing_enabled = false; |
| 1215 | web_prefs->accelerated_2d_canvas_enabled = false; |
| 1216 | web_prefs->accelerated_video_enabled = false; |
| 1217 | web_prefs->accelerated_painting_enabled = false; |
| 1218 | web_prefs->accelerated_plugins_enabled = false; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1219 | } |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | void ChromeContentBrowserClient::UpdateInspectorSetting( |
| 1223 | RenderViewHost* rvh, const std::string& key, const std::string& value) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1224 | content::BrowserContext* browser_context = |
| 1225 | rvh->process()->GetBrowserContext(); |
| 1226 | DictionaryPrefUpdate update( |
| 1227 | Profile::FromBrowserContext(browser_context)->GetPrefs(), |
| 1228 | prefs::kWebKitInspectorSettings); |
| 1229 | DictionaryValue* inspector_settings = update.Get(); |
| 1230 | inspector_settings->SetWithoutPathExpansion(key, |
| 1231 | Value::CreateStringValue(value)); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1235 | content::BrowserContext* browser_context = |
| 1236 | rvh->process()->GetBrowserContext(); |
| 1237 | Profile::FromBrowserContext(browser_context)->GetPrefs()-> |
| 1238 | ClearPref(prefs::kWebKitInspectorSettings); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 1239 | } |
| 1240 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1241 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 1242 | BrowserURLHandler* handler) { |
| 1243 | // Add the default URL handlers. |
| 1244 | handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, |
| 1245 | BrowserURLHandler::null_handler()); |
| 1246 | handler->AddHandlerPair(BrowserURLHandler::null_handler(), |
| 1247 | &ExtensionWebUI::HandleChromeURLOverrideReverse); |
| 1248 | |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 1249 | // about: handler. Must come before chrome: handler, since it will |
| 1250 | // rewrite about: urls to chrome: URLs and then expect chrome: to |
| 1251 | // actually handle them. |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1252 | handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 1253 | BrowserURLHandler::null_handler()); |
| 1254 | // chrome: & friends. |
| 1255 | handler->AddHandlerPair(&HandleWebUI, |
| 1256 | BrowserURLHandler::null_handler()); |
| 1257 | } |
| 1258 | |
| 1259 | void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1260 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1261 | rvh->site_instance()->GetProcess()->GetBrowserContext()); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1262 | BrowsingDataRemover* remover = new BrowsingDataRemover(profile, |
| 1263 | BrowsingDataRemover::EVERYTHING, |
| 1264 | base::Time()); |
| 1265 | remover->Remove(BrowsingDataRemover::REMOVE_CACHE); |
| 1266 | // BrowsingDataRemover takes care of deleting itself when done. |
| 1267 | } |
| 1268 | |
| 1269 | void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1270 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1271 | rvh->site_instance()->GetProcess()->GetBrowserContext()); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1272 | BrowsingDataRemover* remover = new BrowsingDataRemover(profile, |
| 1273 | BrowsingDataRemover::EVERYTHING, |
| 1274 | base::Time()); |
[email protected] | dceaa91 | 2011-09-06 17:17:23 | [diff] [blame] | 1275 | int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA; |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1276 | remover->Remove(remove_mask); |
| 1277 | // BrowsingDataRemover takes care of deleting itself when done. |
| 1278 | } |
| 1279 | |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 1280 | FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
| 1281 | return download_util::GetDefaultDownloadDirectory(); |
| 1282 | } |
| 1283 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 1284 | std::string ChromeContentBrowserClient::GetDefaultDownloadName() { |
| 1285 | return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 1286 | } |
| 1287 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 1288 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1289 | int ChromeContentBrowserClient::GetCrashSignalFD( |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 1290 | const CommandLine& command_line) { |
| 1291 | if (command_line.HasSwitch(switches::kExtensionProcess)) { |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 1292 | ExtensionCrashHandlerHostLinux* crash_handler = |
| 1293 | ExtensionCrashHandlerHostLinux::GetInstance(); |
| 1294 | return crash_handler->GetDeathSignalSocket(); |
| 1295 | } |
| 1296 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 1297 | std::string process_type = |
| 1298 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 1299 | |
| 1300 | if (process_type == switches::kRendererProcess) |
| 1301 | return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 1302 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1303 | if (process_type == switches::kPluginProcess) |
| 1304 | return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 1305 | |
| 1306 | if (process_type == switches::kPpapiPluginProcess) |
| 1307 | return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 1308 | |
| 1309 | if (process_type == switches::kGpuProcess) |
| 1310 | return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 1311 | |
| 1312 | return -1; |
| 1313 | } |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 1314 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1315 | |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 1316 | #if defined(OS_WIN) |
| 1317 | const wchar_t* ChromeContentBrowserClient::GetResourceDllName() { |
| 1318 | return chrome::kBrowserResourcesDll; |
| 1319 | } |
| 1320 | #endif |
| 1321 | |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 1322 | #if defined(USE_NSS) |
| 1323 | crypto::CryptoModuleBlockingPasswordDelegate* |
| 1324 | ChromeContentBrowserClient::GetCryptoPasswordDelegate( |
| 1325 | const GURL& url) { |
| 1326 | return browser::NewCryptoModuleBlockingDialogDelegate( |
| 1327 | browser::kCryptoModulePasswordKeygen, url.host()); |
| 1328 | } |
| 1329 | #endif |
| 1330 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 1331 | } // namespace chrome |