[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> |
| 8 | #include <vector> |
| 9 | |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 10 | #include "base/bind.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 12 | #include "base/utf_string_conversions.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 13 | #include "chrome/app/breakpad_mac.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 14 | #include "chrome/browser/browser_about_handler.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 15 | #include "chrome/browser/browser_process.h" |
[email protected] | 3b8f7e3 | 2011-07-13 11:52:23 | [diff] [blame] | 16 | #include "chrome/browser/browsing_data_remover.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 17 | #include "chrome/browser/character_encoding.h" |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 18 | #include "chrome/browser/chrome_benchmarking_message_filter.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 19 | #include "chrome/browser/chrome_quota_permission_context.h" |
[email protected] | edece21 | 2011-11-16 11:56:56 | [diff] [blame] | 20 | #include "chrome/browser/content_settings/content_settings_utils.h" |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 21 | #include "chrome/browser/content_settings/cookie_settings.h" |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 22 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 23 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 24 | #include "chrome/browser/download/download_util.h" |
[email protected] | 6e672df | 2012-01-25 10:39:47 | [diff] [blame] | 25 | #include "chrome/browser/extensions/api/webrequest/webrequest_api.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 26 | #include "chrome/browser/extensions/extension_info_map.h" |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_message_handler.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 28 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 29 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_webkit_preferences.h" |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 31 | #include "chrome/browser/geolocation/chrome_access_token_store.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 32 | #include "chrome/browser/google/google_util.h" |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 33 | #include "chrome/browser/net/chrome_net_log.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 34 | #include "chrome/browser/notifications/desktop_notification_service.h" |
| 35 | #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 36 | #include "chrome/browser/platform_util.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 37 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 38 | #include "chrome/browser/prefs/scoped_user_pref_update.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 39 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 40 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 41 | #include "chrome/browser/prerender/prerender_tracker.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 42 | #include "chrome/browser/printing/printing_message_filter.h" |
| 43 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 44 | #include "chrome/browser/profiles/profile_io_data.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 45 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | 53a0afa | 2011-04-28 02:09:33 | [diff] [blame] | 46 | #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 47 | #include "chrome/browser/renderer_host/plugin_info_message_filter.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 48 | #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" |
[email protected] | 3bc0b56 | 2011-08-24 23:51:04 | [diff] [blame] | 49 | #include "chrome/browser/speech/chrome_speech_input_manager.h" |
[email protected] | 8ec7126 | 2011-07-28 08:12:46 | [diff] [blame] | 50 | #include "chrome/browser/spellchecker/spellcheck_message_filter.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 51 | #include "chrome/browser/ssl/ssl_add_cert_handler.h" |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 52 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 53 | #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" |
| 54 | #include "chrome/browser/tab_contents/tab_util.h" |
| 55 | #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame^] | 56 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 57 | #include "chrome/browser/user_style_sheet_watcher.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 58 | #include "chrome/common/child_process_logging.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 59 | #include "chrome/common/chrome_constants.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 60 | #include "chrome/common/chrome_switches.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 61 | #include "chrome/common/extensions/extension.h" |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 62 | #include "chrome/common/extensions/extension_set.h" |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 63 | #include "chrome/common/logging_chrome.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 64 | #include "chrome/common/pref_names.h" |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 65 | #include "chrome/common/render_messages.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 66 | #include "chrome/common/url_constants.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 67 | #include "content/browser/browser_url_handler.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 68 | #include "content/browser/child_process_security_policy.h" |
| 69 | #include "content/browser/gpu/gpu_data_manager.h" |
| 70 | #include "content/browser/gpu/gpu_process_host.h" |
[email protected] | 97e6c4c | 2011-05-18 16:08:51 | [diff] [blame] | 71 | #include "content/browser/plugin_process_host.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 72 | #include "content/browser/renderer_host/render_view_host.h" |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 73 | #include "content/browser/resource_context.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 74 | #include "content/browser/ssl/ssl_cert_error_handler.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 75 | #include "content/browser/ssl/ssl_client_auth_handler.h" |
[email protected] | 5327dfb | 2011-05-03 17:50:36 | [diff] [blame] | 76 | #include "content/browser/worker_host/worker_process_host.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 77 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 78 | #include "content/public/browser/render_process_host.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 79 | #include "content/public/browser/site_instance.h" |
[email protected] | 91ee368 | 2012-01-19 15:02:19 | [diff] [blame] | 80 | #include "content/public/browser/web_contents.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 81 | #include "content/public/browser/web_contents_view.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 82 | #include "grit/generated_resources.h" |
[email protected] | 29b25d09 | 2011-06-29 20:57:34 | [diff] [blame] | 83 | #include "grit/ui_resources.h" |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 84 | #include "net/base/cookie_monster.h" |
| 85 | #include "net/base/cookie_options.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 86 | #include "net/base/network_change_notifier.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 87 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 88 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | 4fdf674 | 2012-01-10 20:14:36 | [diff] [blame] | 89 | #include "webkit/glue/webpreferences.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 90 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 91 | #if defined(OS_WIN) |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 92 | #include "chrome/browser/chrome_browser_main_win.h" |
| 93 | #elif defined(OS_MACOSX) |
| 94 | #include "chrome/browser/chrome_browser_main_mac.h" |
[email protected] | 7ceb9901 | 2011-12-21 08:05:56 | [diff] [blame] | 95 | #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 96 | #elif defined(OS_CHROMEOS) |
| 97 | #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 98 | #elif defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 99 | #include "chrome/browser/chrome_browser_main_linux.h" |
| 100 | #elif defined(OS_POSIX) |
| 101 | #include "chrome/browser/chrome_browser_main_posix.h" |
| 102 | #endif |
| 103 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 104 | #if defined(TOOLKIT_USES_GTK) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 105 | #include "chrome/browser/chrome_browser_main_extra_parts_gtk.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 106 | #endif |
| 107 | |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 108 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 109 | #include "chrome/browser/chrome_browser_main_extra_parts_views.h" |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 110 | #endif |
| 111 | |
| 112 | #if defined(USE_AURA) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 113 | #include "chrome/browser/chrome_browser_main_extra_parts_aura.h" |
| 114 | #endif |
| 115 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 116 | #if defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 117 | #include "base/linux_util.h" |
| 118 | #include "chrome/browser/crash_handler_host_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 119 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 120 | |
[email protected] | 080f34f | 2011-09-20 05:39:26 | [diff] [blame] | 121 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 122 | #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" |
[email protected] | c92f4ed | 2011-10-21 19:50:21 | [diff] [blame] | 123 | #elif defined(TOOLKIT_USES_GTK) |
[email protected] | 9bce777 | 2011-11-16 01:24:45 | [diff] [blame] | 124 | #include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h" |
[email protected] | 9058042 | 2012-01-12 00:26:22 | [diff] [blame] | 125 | #include "content/browser/tab_contents/tab_contents_view_gtk.h" |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 126 | #elif defined(OS_MACOSX) |
[email protected] | 8dad546b | 2012-01-17 21:47:35 | [diff] [blame] | 127 | #include "chrome/browser/tab_contents/moving_to_content/tab_contents_view_mac.h" |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 128 | #endif |
| 129 | |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 130 | #if defined(USE_NSS) |
| 131 | #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 132 | #endif |
| 133 | |
[email protected] | c8c7718 | 2011-12-21 15:04:47 | [diff] [blame] | 134 | using content::AccessTokenStore; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 135 | using content::BrowserThread; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 136 | using content::SiteInstance; |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 137 | using content::WebContents; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 138 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 139 | namespace { |
| 140 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 141 | // Handles rewriting Web UI URLs. |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 142 | bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame^] | 143 | if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 144 | browser_context, *url)) |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 145 | return false; |
| 146 | |
| 147 | // Special case the new tab page. In older versions of Chrome, the new tab |
| 148 | // page was hosted at chrome-internal:<blah>. This might be in people's saved |
| 149 | // sessions or bookmarks, so we say any URL with that scheme triggers the new |
| 150 | // tab page. |
| 151 | if (url->SchemeIs(chrome::kChromeInternalScheme)) { |
| 152 | // Rewrite it with the proper new tab URL. |
| 153 | *url = GURL(chrome::kChromeUINewTabURL); |
| 154 | } |
| 155 | |
| 156 | return true; |
| 157 | } |
| 158 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 159 | // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions |
| 160 | // below. Extension, and isolated apps require different privileges to be |
| 161 | // granted to their RenderProcessHosts. This classification allows us to make |
| 162 | // sure URLs are served by hosts with the right set of privileges. |
| 163 | enum RenderProcessHostPrivilege { |
| 164 | PRIV_NORMAL, |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 165 | PRIV_HOSTED, |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 166 | PRIV_ISOLATED, |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 167 | PRIV_EXTENSION, |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( |
| 171 | const GURL& url, |
| 172 | ExtensionService* service) { |
| 173 | // Default to a normal renderer cause it is lower privileged. This should only |
| 174 | // occur if the URL on a site instance is either malformed, or uninitialized. |
| 175 | // If it is malformed, then there is no need for better privileges anyways. |
| 176 | // If it is uninitialized, but eventually settles on being an a scheme other |
| 177 | // than normal webrenderer, the navigation logic will correct us out of band |
| 178 | // anyways. |
| 179 | if (!url.is_valid()) |
| 180 | return PRIV_NORMAL; |
| 181 | |
| 182 | if (url.SchemeIs(chrome::kExtensionScheme)) { |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 183 | const Extension* extension = |
| 184 | service->extensions()->GetByID(url.host()); |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 185 | if (extension && extension->is_storage_isolated()) |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 186 | return PRIV_ISOLATED; |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 187 | if (extension && extension->is_hosted_app()) |
| 188 | return PRIV_HOSTED; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 189 | |
| 190 | return PRIV_EXTENSION; |
| 191 | } |
| 192 | |
| 193 | return PRIV_NORMAL; |
| 194 | } |
| 195 | |
| 196 | RenderProcessHostPrivilege GetProcessPrivilege( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 197 | content::RenderProcessHost* process_host, |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 198 | extensions::ProcessMap* process_map, |
| 199 | ExtensionService* service) { |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 200 | std::set<std::string> extension_ids = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 201 | process_map->GetExtensionsInProcess(process_host->GetID()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 202 | if (extension_ids.empty()) |
[email protected] | 676f6ab | 2011-10-19 20:23:21 | [diff] [blame] | 203 | return PRIV_NORMAL; |
| 204 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 205 | for (std::set<std::string>::iterator iter = extension_ids.begin(); |
| 206 | iter != extension_ids.end(); ++iter) { |
| 207 | const Extension* extension = service->GetExtensionById(*iter, false); |
| 208 | if (extension && extension->is_storage_isolated()) |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 209 | return PRIV_ISOLATED; |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 210 | if (extension && extension->is_hosted_app()) |
| 211 | return PRIV_HOSTED; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 212 | } |
| 213 | |
[email protected] | 676f6ab | 2011-10-19 20:23:21 | [diff] [blame] | 214 | return PRIV_EXTENSION; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 215 | } |
| 216 | |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 217 | bool IsIsolatedAppInProcess(const GURL& site_url, |
| 218 | content::RenderProcessHost* process_host, |
| 219 | extensions::ProcessMap* process_map, |
| 220 | ExtensionService* service) { |
| 221 | std::set<std::string> extension_ids = |
| 222 | process_map->GetExtensionsInProcess(process_host->GetID()); |
| 223 | if (extension_ids.empty()) |
| 224 | return false; |
| 225 | |
| 226 | for (std::set<std::string>::iterator iter = extension_ids.begin(); |
| 227 | iter != extension_ids.end(); ++iter) { |
| 228 | const Extension* extension = service->GetExtensionById(*iter, false); |
| 229 | if (extension && |
| 230 | extension->is_storage_isolated() && |
| 231 | extension->url() == site_url) |
| 232 | return true; |
| 233 | } |
| 234 | |
| 235 | return false; |
| 236 | } |
| 237 | |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 238 | bool CertMatchesFilter(const net::X509Certificate& cert, |
| 239 | const base::DictionaryValue& filter) { |
| 240 | // TODO(markusheintz): This is the minimal required filter implementation. |
| 241 | // Implement a better matcher. |
| 242 | |
| 243 | // An empty filter matches any client certificate since no requirements are |
| 244 | // specified at all. |
| 245 | if (filter.empty()) |
| 246 | return true; |
| 247 | |
| 248 | std::string common_name; |
| 249 | if (filter.GetString("ISSUER.CN", &common_name) && |
| 250 | (cert.issuer().common_name == common_name)) { |
| 251 | return true; |
| 252 | } |
| 253 | return false; |
| 254 | } |
| 255 | |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 256 | // Fills |map| with the per-script font prefs under path |map_name|. |
| 257 | void FillFontFamilyMap(const PrefService* prefs, |
| 258 | const char* map_name, |
| 259 | WebPreferences::ScriptFontFamilyMap* map) { |
| 260 | for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { |
| 261 | const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; |
| 262 | std::string pref_name = base::StringPrintf("%s.%s", map_name, script); |
| 263 | std::string font_family = prefs->GetString(pref_name.c_str()); |
| 264 | if (!font_family.empty()) |
| 265 | map->push_back(std::make_pair(script, UTF8ToUTF16(font_family))); |
| 266 | } |
| 267 | } |
| 268 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 269 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 270 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 271 | namespace chrome { |
| 272 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 273 | content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( |
| 274 | const content::MainFunctionParams& parameters) { |
| 275 | ChromeBrowserMainParts* main_parts; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 276 | // Construct the Main browser parts based on the OS type. |
| 277 | #if defined(OS_WIN) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 278 | main_parts = new ChromeBrowserMainPartsWin(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 279 | #elif defined(OS_MACOSX) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 280 | main_parts = new ChromeBrowserMainPartsMac(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 281 | #elif defined(OS_CHROMEOS) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 282 | main_parts = new ChromeBrowserMainPartsChromeos(parameters); |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 283 | #elif defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 284 | main_parts = new ChromeBrowserMainPartsLinux(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 285 | #elif defined(OS_POSIX) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 286 | main_parts = new ChromeBrowserMainPartsPosix(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 287 | #else |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 288 | NOTREACHED(); |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 289 | main_parts = new ChromeBrowserMainParts(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 290 | #endif |
| 291 | |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 292 | // Construct additional browser parts. Stages are called in the order in |
| 293 | // which they are added. |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 294 | #if defined(TOOLKIT_USES_GTK) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 295 | main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk()); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 296 | #endif |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 297 | |
| 298 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 299 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 300 | #endif |
| 301 | |
| 302 | #if defined(USE_AURA) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 303 | main_parts->AddParts(new ChromeBrowserMainExtraPartsAura()); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 304 | #endif |
| 305 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 306 | return main_parts; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 307 | } |
| 308 | |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 309 | content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView( |
[email protected] | 8dad546b | 2012-01-17 21:47:35 | [diff] [blame] | 310 | WebContents* web_contents) { |
[email protected] | 080f34f | 2011-09-20 05:39:26 | [diff] [blame] | 311 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 8dad546b | 2012-01-17 21:47:35 | [diff] [blame] | 312 | return new TabContentsViewViews(web_contents); |
[email protected] | c92f4ed | 2011-10-21 19:50:21 | [diff] [blame] | 313 | #elif defined(TOOLKIT_USES_GTK) |
[email protected] | 8dad546b | 2012-01-17 21:47:35 | [diff] [blame] | 314 | return new content::TabContentsViewGtk(web_contents, |
[email protected] | 9058042 | 2012-01-12 00:26:22 | [diff] [blame] | 315 | new ChromeTabContentsViewWrapperGtk); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 316 | #elif defined(OS_MACOSX) |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 317 | return tab_contents_view_mac::CreateWebContentsView(web_contents); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 318 | #else |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 319 | #error Need to create your platform WebContentsView here. |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 320 | #endif |
| 321 | } |
| 322 | |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 323 | void ChromeContentBrowserClient::RenderViewHostCreated( |
| 324 | RenderViewHost* render_view_host) { |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 325 | |
| 326 | SiteInstance* site_instance = render_view_host->site_instance(); |
| 327 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 328 | site_instance->GetBrowserContext()); |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 329 | |
| 330 | new ChromeRenderViewHostObserver(render_view_host, |
| 331 | profile->GetNetworkPredictor()); |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 332 | new ExtensionMessageHandler(render_view_host); |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 333 | } |
| 334 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 335 | void ChromeContentBrowserClient::RenderProcessHostCreated( |
| 336 | content::RenderProcessHost* host) { |
| 337 | int id = host->GetID(); |
| 338 | Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
| 339 | host->GetChannel()->AddFilter(new ChromeRenderMessageFilter( |
[email protected] | c47cfd6 | 2011-04-29 21:27:02 | [diff] [blame] | 340 | id, profile, profile->GetRequestContextForRenderProcess(id))); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 341 | host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile)); |
| 342 | host->GetChannel()->AddFilter(new PrintingMessageFilter()); |
| 343 | host->GetChannel()->AddFilter( |
[email protected] | c47cfd6 | 2011-04-29 21:27:02 | [diff] [blame] | 344 | new SearchProviderInstallStateMessageFilter(id, profile)); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 345 | host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id)); |
[email protected] | 7ceb9901 | 2011-12-21 08:05:56 | [diff] [blame] | 346 | #if defined(OS_MACOSX) |
| 347 | host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac()); |
| 348 | #endif |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 349 | host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter( |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 350 | id, profile, profile->GetRequestContextForRenderProcess(id))); |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 351 | |
[email protected] | 2ccf45c | 2011-08-19 23:35:50 | [diff] [blame] | 352 | host->Send(new ChromeViewMsg_SetIsIncognitoProcess( |
| 353 | profile->IsOffTheRecord())); |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 354 | |
| 355 | SendExtensionWebRequestStatusToHost(host); |
[email protected] | edece21 | 2011-11-16 11:56:56 | [diff] [blame] | 356 | |
| 357 | RendererContentSettingRules rules; |
| 358 | GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules); |
| 359 | host->Send(new ChromeViewMsg_SetContentSettingRules(rules)); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 360 | } |
| 361 | |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame^] | 362 | content::WebUIControllerFactory* |
| 363 | ChromeContentBrowserClient::GetWebUIControllerFactory() { |
| 364 | return ChromeWebUIControllerFactory::GetInstance(); |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 365 | } |
| 366 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 367 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
| 368 | content::BrowserContext* browser_context, const GURL& url) { |
| 369 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 370 | // Get the effective URL for the given actual URL. If the URL is part of an |
| 371 | // installed app, the effective URL is an extension URL with the ID of that |
| 372 | // extension as the host. This has the effect of grouping apps together in |
| 373 | // a common SiteInstance. |
| 374 | if (!profile || !profile->GetExtensionService()) |
| 375 | return url; |
| 376 | |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 377 | const Extension* extension = profile->GetExtensionService()->extensions()-> |
| 378 | GetHostedAppByURL(ExtensionURLInfo(url)); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 379 | if (!extension) |
| 380 | return url; |
| 381 | |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 382 | // Bookmark apps do not use the hosted app process model, and should be |
| 383 | // treated as normal URLs. |
| 384 | if (extension->from_bookmark()) |
| 385 | return url; |
| 386 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 387 | // If the URL is part of an extension's web extent, convert it to an |
| 388 | // extension URL. |
| 389 | return extension->GetResourceURL(url.path()); |
| 390 | } |
| 391 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 392 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 393 | content::BrowserContext* browser_context, const GURL& effective_url) { |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 394 | // Non-extension URLs should generally use process-per-site-instance. |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 395 | // Because we expect to use the effective URL, URLs for hosted apps (apart |
| 396 | // from bookmark apps) should have an extension scheme by now. |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 397 | if (!effective_url.SchemeIs(chrome::kExtensionScheme)) |
| 398 | return false; |
| 399 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 400 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 401 | if (!profile || !profile->GetExtensionService()) |
| 402 | return false; |
| 403 | |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 404 | const Extension* extension = profile->GetExtensionService()->extensions()-> |
| 405 | GetExtensionOrAppByURL(ExtensionURLInfo(effective_url)); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 406 | if (!extension) |
| 407 | return false; |
| 408 | |
| 409 | // If the URL is part of a hosted app that does not have the background |
| 410 | // permission, we want to give each instance its own process to improve |
| 411 | // responsiveness. |
| 412 | if (extension->GetType() == Extension::TYPE_HOSTED_APP && |
| 413 | !extension->HasAPIPermission(ExtensionAPIPermission::kBackground)) |
| 414 | return false; |
| 415 | |
| 416 | // Hosted apps that have the background permission must use process per site, |
| 417 | // since all instances can make synchronous calls to the background window. |
| 418 | // Other extensions should use process per site as well. |
| 419 | return true; |
| 420 | } |
| 421 | |
[email protected] | 0f012df8 | 2011-05-19 14:15:29 | [diff] [blame] | 422 | bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) { |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 423 | return url == GURL(chrome::kChromeUICrashURL) || |
| 424 | url == GURL(chrome::kChromeUIKillURL) || |
| 425 | url == GURL(chrome::kChromeUIHangURL) || |
| 426 | url == GURL(chrome::kChromeUIShorthangURL); |
[email protected] | 0f012df8 | 2011-05-19 14:15:29 | [diff] [blame] | 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::kDomAutomationController, |
| 642 | switches::kDumpHistogramsOnExit, |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 643 | switches::kEnableBenchmarking, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 644 | switches::kEnableClickToPlay, |
| 645 | switches::kEnableCrxlessWebApps, |
| 646 | switches::kEnableExperimentalExtensionApis, |
| 647 | switches::kEnableInBrowserThumbnailing, |
| 648 | switches::kEnableIPCFuzzing, |
| 649 | switches::kEnableNaCl, |
[email protected] | 9776e82e | 2011-11-15 02:17:53 | [diff] [blame] | 650 | switches::kEnablePlatformApps, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 651 | switches::kEnableSearchProviderApiV2, |
| 652 | switches::kEnableWatchdog, |
| 653 | switches::kExperimentalSpellcheckerFeatures, |
| 654 | switches::kMemoryProfiling, |
| 655 | switches::kMessageLoopHistogrammer, |
[email protected] | 2a6bb0b1 | 2011-10-05 19:18:04 | [diff] [blame] | 656 | switches::kNoRunningInsecureContent, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 657 | switches::kPpapiFlashArgs, |
| 658 | switches::kPpapiFlashInProcess, |
| 659 | switches::kPpapiFlashPath, |
| 660 | switches::kPpapiFlashVersion, |
| 661 | switches::kProfilingAtStart, |
| 662 | switches::kProfilingFile, |
| 663 | switches::kProfilingFlush, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 664 | switches::kSilentDumpOnDCHECK, |
| 665 | }; |
| 666 | |
| 667 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 668 | arraysize(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 669 | } else if (process_type == switches::kUtilityProcess) { |
| 670 | if (browser_command_line.HasSwitch( |
| 671 | switches::kEnableExperimentalExtensionApis)) { |
| 672 | command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 673 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 674 | } else if (process_type == switches::kPluginProcess) { |
| 675 | static const char* const kSwitchNames[] = { |
| 676 | #if defined(OS_CHROMEOS) |
| 677 | switches::kLoginProfile, |
| 678 | #endif |
| 679 | switches::kMemoryProfiling, |
| 680 | switches::kSilentDumpOnDCHECK, |
| 681 | switches::kUserDataDir, |
| 682 | }; |
| 683 | |
| 684 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 685 | arraysize(kSwitchNames)); |
| 686 | } else if (process_type == switches::kZygoteProcess) { |
| 687 | static const char* const kSwitchNames[] = { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 688 | switches::kUserDataDir, // Make logs go to the right file. |
| 689 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
| 690 | switches::kPpapiFlashInProcess, |
| 691 | switches::kPpapiFlashPath, |
| 692 | switches::kPpapiFlashVersion, |
| 693 | }; |
| 694 | |
| 695 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 696 | arraysize(kSwitchNames)); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 697 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 698 | |
| 699 | // The command line switch kEnableBenchmarking needs to be specified along |
| 700 | // with the kEnableStatsTable switch to ensure that the stats table global |
| 701 | // is initialized correctly. |
| 702 | if (command_line->HasSwitch(switches::kEnableBenchmarking)) |
| 703 | DCHECK(command_line->HasSwitch(switches::kEnableStatsTable)); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
| 707 | return g_browser_process->GetApplicationLocale(); |
| 708 | } |
| 709 | |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 710 | std::string ChromeContentBrowserClient::GetAcceptLangs( |
| 711 | content::BrowserContext* context) { |
| 712 | Profile* profile = Profile::FromBrowserContext(context); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 713 | return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 714 | } |
| 715 | |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 716 | SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() { |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 717 | ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 718 | return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 719 | } |
| 720 | |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 721 | bool ChromeContentBrowserClient::AllowAppCache( |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 722 | const GURL& manifest_url, |
[email protected] | 0a60884 | 2011-09-08 10:55:19 | [diff] [blame] | 723 | const GURL& first_party, |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 724 | const content::ResourceContext& context) { |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 725 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 726 | ProfileIOData* io_data = |
| 727 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
[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, |
| 736 | const content::ResourceContext& context, |
| 737 | int render_process_id, |
| 738 | int render_view_id) { |
| 739 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 740 | ProfileIOData* io_data = |
| 741 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 742 | bool allow = io_data->GetCookieSettings()-> |
| 743 | IsReadingCookieAllowed(url, first_party); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 744 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 745 | BrowserThread::PostTask( |
| 746 | BrowserThread::UI, FROM_HERE, |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 747 | base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id, |
| 748 | render_view_id, url, cookie_list, !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 749 | return allow; |
| 750 | } |
| 751 | |
| 752 | bool ChromeContentBrowserClient::AllowSetCookie( |
| 753 | const GURL& url, |
| 754 | const GURL& first_party, |
| 755 | const std::string& cookie_line, |
| 756 | const content::ResourceContext& context, |
| 757 | int render_process_id, |
| 758 | int render_view_id, |
| 759 | net::CookieOptions* options) { |
| 760 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 761 | ProfileIOData* io_data = |
| 762 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 763 | |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 764 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 765 | bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); |
| 766 | |
| 767 | if (cookie_settings->IsCookieSessionOnly(url)) |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 768 | options->set_force_session(); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 769 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 770 | BrowserThread::PostTask( |
| 771 | BrowserThread::UI, FROM_HERE, |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 772 | base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, |
| 773 | render_view_id, url, cookie_line, *options, !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 774 | return allow; |
| 775 | } |
| 776 | |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 777 | bool ChromeContentBrowserClient::AllowSaveLocalState( |
| 778 | const content::ResourceContext& context) { |
| 779 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 780 | ProfileIOData* io_data = |
| 781 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 782 | return !io_data->clear_local_state_on_exit()->GetValue(); |
| 783 | } |
| 784 | |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 785 | bool ChromeContentBrowserClient::AllowWorkerDatabase( |
| 786 | int worker_route_id, |
| 787 | const GURL& url, |
| 788 | const string16& name, |
| 789 | const string16& display_name, |
| 790 | unsigned long estimated_size, |
| 791 | WorkerProcessHost* worker_process_host) { |
| 792 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 793 | ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>( |
| 794 | worker_process_host->resource_context()->GetUserData(NULL)); |
| 795 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 796 | bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
| 797 | |
| 798 | // Record access to database for potential display in UI: Find the worker |
| 799 | // instance and forward the message to all attached documents. |
| 800 | WorkerProcessHost::Instances::const_iterator i; |
| 801 | for (i = worker_process_host->instances().begin(); |
| 802 | i != worker_process_host->instances().end(); ++i) { |
| 803 | if (i->worker_route_id() != worker_route_id) |
| 804 | continue; |
| 805 | const WorkerDocumentSet::DocumentInfoSet& documents = |
| 806 | i->worker_document_set()->documents(); |
| 807 | for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc = |
| 808 | documents.begin(); doc != documents.end(); ++doc) { |
| 809 | BrowserThread::PostTask( |
| 810 | BrowserThread::UI, FROM_HERE, |
| 811 | base::Bind( |
| 812 | &TabSpecificContentSettings::WebDatabaseAccessed, |
| 813 | doc->render_process_id(), doc->render_view_id(), |
| 814 | url, name, display_name, !allow)); |
| 815 | } |
| 816 | break; |
| 817 | } |
| 818 | |
| 819 | return allow; |
| 820 | } |
| 821 | |
| 822 | bool ChromeContentBrowserClient::AllowWorkerFileSystem( |
| 823 | int worker_route_id, |
| 824 | const GURL& url, |
| 825 | WorkerProcessHost* worker_process_host) { |
| 826 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 827 | ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>( |
| 828 | worker_process_host->resource_context()->GetUserData(NULL)); |
| 829 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 830 | bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
| 831 | |
| 832 | // Record access to file system for potential display in UI: Find the worker |
| 833 | // instance and forward the message to all attached documents. |
| 834 | WorkerProcessHost::Instances::const_iterator i; |
| 835 | for (i = worker_process_host->instances().begin(); |
| 836 | i != worker_process_host->instances().end(); ++i) { |
| 837 | if (i->worker_route_id() != worker_route_id) |
| 838 | continue; |
| 839 | const WorkerDocumentSet::DocumentInfoSet& documents = |
| 840 | i->worker_document_set()->documents(); |
| 841 | for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc = |
| 842 | documents.begin(); doc != documents.end(); ++doc) { |
| 843 | BrowserThread::PostTask( |
| 844 | BrowserThread::UI, FROM_HERE, |
| 845 | base::Bind( |
| 846 | &TabSpecificContentSettings::FileSystemAccessed, |
| 847 | doc->render_process_id(), doc->render_view_id(), url, !allow)); |
| 848 | } |
| 849 | break; |
| 850 | } |
| 851 | |
| 852 | return allow; |
| 853 | } |
| 854 | |
[email protected] | 6133f92 | 2011-07-01 21:34:34 | [diff] [blame] | 855 | net::URLRequestContext* |
| 856 | ChromeContentBrowserClient::OverrideRequestContextForURL( |
| 857 | const GURL& url, const content::ResourceContext& context) { |
| 858 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 859 | if (url.SchemeIs(chrome::kExtensionScheme)) { |
| 860 | ProfileIOData* io_data = |
| 861 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 862 | return io_data->extensions_request_context(); |
| 863 | } |
| 864 | |
| 865 | return NULL; |
| 866 | } |
| 867 | |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 868 | QuotaPermissionContext* |
| 869 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
| 870 | return new ChromeQuotaPermissionContext(); |
| 871 | } |
| 872 | |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 873 | void ChromeContentBrowserClient::OpenItem(const FilePath& path) { |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 874 | platform_util::OpenItem(path); |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 875 | } |
| 876 | |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 877 | void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) { |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 878 | platform_util::ShowItemInFolder(path); |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 879 | } |
| 880 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 881 | void ChromeContentBrowserClient::AllowCertificateError( |
| 882 | SSLCertErrorHandler* handler, |
| 883 | bool overridable, |
[email protected] | 8a27abf | 2011-09-30 21:59:58 | [diff] [blame] | 884 | const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) { |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 885 | // If the tab is being prerendered, cancel the prerender and the request. |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 886 | WebContents* tab = tab_util::GetWebContentsByID( |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 887 | handler->render_process_host_id(), |
| 888 | handler->tab_contents_id()); |
| 889 | if (!tab) { |
| 890 | NOTREACHED(); |
| 891 | return; |
| 892 | } |
| 893 | prerender::PrerenderManager* prerender_manager = |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 894 | prerender::PrerenderManagerFactory::GetForProfile( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 895 | Profile::FromBrowserContext(tab->GetBrowserContext())); |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 896 | if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) { |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 897 | if (prerender_manager->prerender_tracker()->TryCancel( |
| 898 | handler->render_process_host_id(), |
| 899 | handler->tab_contents_id(), |
| 900 | prerender::FINAL_STATUS_SSL_ERROR)) { |
| 901 | handler->CancelRequest(); |
| 902 | return; |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | // Otherwise, display an SSL blocking page. |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 907 | SSLBlockingPage* blocking_page = new SSLBlockingPage( |
| 908 | handler, overridable, callback); |
| 909 | blocking_page->Show(); |
| 910 | } |
| 911 | |
[email protected] | c99c442e | 2011-08-24 11:37:30 | [diff] [blame] | 912 | void ChromeContentBrowserClient::SelectClientCertificate( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 913 | int render_process_id, |
| 914 | int render_view_id, |
| 915 | SSLClientAuthHandler* handler) { |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 916 | WebContents* tab = tab_util::GetWebContentsByID( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 917 | render_process_id, render_view_id); |
| 918 | if (!tab) { |
| 919 | NOTREACHED(); |
| 920 | return; |
| 921 | } |
| 922 | |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 923 | net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info(); |
| 924 | GURL requesting_url("https://" + cert_request_info->host_and_port); |
| 925 | DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://" |
| 926 | << cert_request_info->host_and_port; |
| 927 | |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 928 | Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 929 | DCHECK(profile); |
| 930 | scoped_ptr<Value> filter( |
| 931 | profile->GetHostContentSettingsMap()->GetWebsiteSetting( |
| 932 | requesting_url, |
| 933 | requesting_url, |
| 934 | CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 935 | std::string(), NULL)); |
| 936 | |
| 937 | if (filter.get()) { |
| 938 | // Try to automatically select a client certificate. |
| 939 | if (filter->IsType(Value::TYPE_DICTIONARY)) { |
| 940 | DictionaryValue* filter_dict = |
| 941 | static_cast<DictionaryValue*>(filter.get()); |
| 942 | |
| 943 | const std::vector<scoped_refptr<net::X509Certificate> >& |
| 944 | all_client_certs = cert_request_info->client_certs; |
| 945 | for (size_t i = 0; i < all_client_certs.size(); ++i) { |
| 946 | if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) { |
| 947 | // Use the first certificate that is matched by the filter. |
| 948 | handler->CertificateSelected(all_client_certs[i]); |
| 949 | return; |
| 950 | } |
| 951 | } |
| 952 | } else { |
| 953 | NOTREACHED(); |
| 954 | } |
| 955 | } |
| 956 | |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 957 | TabContentsWrapper* wrapper = |
| 958 | TabContentsWrapper::GetCurrentWrapperForContents(tab); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 959 | if (!wrapper) { |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 960 | // If there is no TabContentsWrapper for the given WebContents then we can't |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 961 | // show the user a dialog to select a client certificate. So we simply |
[email protected] | 2a349e9 | 2011-12-07 12:00:14 | [diff] [blame] | 962 | // proceed with no client certificate. |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 963 | handler->CertificateSelected(NULL); |
| 964 | return; |
| 965 | } |
| 966 | wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | void ChromeContentBrowserClient::AddNewCertificate( |
| 970 | net::URLRequest* request, |
| 971 | net::X509Certificate* cert, |
| 972 | int render_process_id, |
| 973 | int render_view_id) { |
| 974 | // The handler will run the UI and delete itself when it's finished. |
| 975 | new SSLAddCertHandler(request, cert, render_process_id, render_view_id); |
| 976 | } |
| 977 | |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 978 | void ChromeContentBrowserClient::RequestDesktopNotificationPermission( |
| 979 | const GURL& source_origin, |
| 980 | int callback_context, |
| 981 | int render_process_id, |
| 982 | int render_view_id) { |
| 983 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 984 | render_process_id, render_view_id); |
| 985 | if (!rvh) { |
| 986 | NOTREACHED(); |
| 987 | return; |
| 988 | } |
| 989 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 990 | content::RenderProcessHost* process = rvh->process(); |
| 991 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 992 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 993 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 994 | service->RequestPermission( |
| 995 | source_origin, render_process_id, render_view_id, callback_context, |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 996 | tab_util::GetWebContentsByID(render_process_id, render_view_id)); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | WebKit::WebNotificationPresenter::Permission |
| 1000 | ChromeContentBrowserClient::CheckDesktopNotificationPermission( |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1001 | const GURL& source_origin, |
| 1002 | const content::ResourceContext& context, |
| 1003 | int render_process_id) { |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1004 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1005 | ProfileIOData* io_data = |
| 1006 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 1007 | |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1008 | if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission( |
| 1009 | source_origin, render_process_id, |
| 1010 | ExtensionAPIPermission::kNotification)) |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1011 | return WebKit::WebNotificationPresenter::PermissionAllowed; |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1012 | |
| 1013 | // Fall back to the regular notification preferences, which works on an |
| 1014 | // origin basis. |
| 1015 | return io_data->GetNotificationService() ? |
[email protected] | c7df61b | 2011-11-07 22:06:37 | [diff] [blame] | 1016 | io_data->GetNotificationService()->HasPermission(source_origin) : |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1017 | WebKit::WebNotificationPresenter::PermissionNotAllowed; |
| 1018 | } |
| 1019 | |
| 1020 | void ChromeContentBrowserClient::ShowDesktopNotification( |
[email protected] | 0ee57e2 | 2011-11-12 01:59:17 | [diff] [blame] | 1021 | const content::ShowDesktopNotificationHostMsgParams& params, |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1022 | int render_process_id, |
| 1023 | int render_view_id, |
| 1024 | bool worker) { |
| 1025 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 1026 | render_process_id, render_view_id); |
| 1027 | if (!rvh) { |
| 1028 | NOTREACHED(); |
| 1029 | return; |
| 1030 | } |
| 1031 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1032 | content::RenderProcessHost* process = rvh->process(); |
| 1033 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1034 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1035 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1036 | service->ShowDesktopNotification( |
| 1037 | params, render_process_id, render_view_id, |
| 1038 | worker ? DesktopNotificationService::WorkerNotification : |
| 1039 | DesktopNotificationService::PageNotification); |
| 1040 | } |
| 1041 | |
| 1042 | void ChromeContentBrowserClient::CancelDesktopNotification( |
| 1043 | int render_process_id, |
| 1044 | int render_view_id, |
| 1045 | int notification_id) { |
| 1046 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 1047 | render_process_id, render_view_id); |
| 1048 | if (!rvh) { |
| 1049 | NOTREACHED(); |
| 1050 | return; |
| 1051 | } |
| 1052 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1053 | content::RenderProcessHost* process = rvh->process(); |
| 1054 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1055 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1056 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1057 | service->CancelDesktopNotification( |
| 1058 | render_process_id, render_view_id, notification_id); |
| 1059 | } |
| 1060 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1061 | bool ChromeContentBrowserClient::CanCreateWindow( |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1062 | const GURL& source_origin, |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1063 | WindowContainerType container_type, |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1064 | const content::ResourceContext& context, |
| 1065 | int render_process_id) { |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1066 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1067 | // If the opener is trying to create a background window but doesn't have |
| 1068 | // the appropriate permission, fail the attempt. |
| 1069 | if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
| 1070 | ProfileIOData* io_data = |
| 1071 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1072 | return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission( |
| 1073 | source_origin, render_process_id, ExtensionAPIPermission::kBackground); |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1074 | } |
| 1075 | return true; |
| 1076 | } |
| 1077 | |
| 1078 | std::string ChromeContentBrowserClient::GetWorkerProcessTitle( |
| 1079 | const GURL& url, const content::ResourceContext& context) { |
| 1080 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1081 | // Check if it's an extension-created worker, in which case we want to use |
| 1082 | // the name of the extension. |
| 1083 | ProfileIOData* io_data = |
| 1084 | reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL)); |
| 1085 | const Extension* extension = |
| 1086 | io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); |
| 1087 | return extension ? extension->name() : std::string(); |
| 1088 | } |
| 1089 | |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 1090 | void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { |
| 1091 | return g_browser_process->ResourceDispatcherHostCreated(); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | ui::Clipboard* ChromeContentBrowserClient::GetClipboard() { |
| 1095 | return g_browser_process->clipboard(); |
| 1096 | } |
| 1097 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 1098 | MHTMLGenerationManager* |
| 1099 | ChromeContentBrowserClient::GetMHTMLGenerationManager() { |
| 1100 | return g_browser_process->mhtml_generation_manager(); |
| 1101 | } |
| 1102 | |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 1103 | net::NetLog* ChromeContentBrowserClient::GetNetLog() { |
| 1104 | return g_browser_process->net_log(); |
| 1105 | } |
| 1106 | |
[email protected] | 3bc0b56 | 2011-08-24 23:51:04 | [diff] [blame] | 1107 | speech_input::SpeechInputManager* |
| 1108 | ChromeContentBrowserClient::GetSpeechInputManager() { |
| 1109 | return speech_input::ChromeSpeechInputManager::GetInstance(); |
| 1110 | } |
| 1111 | |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 1112 | AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() { |
| 1113 | return new ChromeAccessTokenStore(); |
| 1114 | } |
| 1115 | |
[email protected] | dbae6b0 | 2011-06-29 23:51:41 | [diff] [blame] | 1116 | bool ChromeContentBrowserClient::IsFastShutdownPossible() { |
| 1117 | const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 1118 | return !browser_command_line.HasSwitch(switches::kChromeFrame); |
| 1119 | } |
| 1120 | |
[email protected] | 5092c28 | 2011-10-29 21:48:37 | [diff] [blame] | 1121 | WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(RenderViewHost* rvh) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1122 | Profile* profile = Profile::FromBrowserContext( |
| 1123 | rvh->process()->GetBrowserContext()); |
| 1124 | PrefService* prefs = profile->GetPrefs(); |
| 1125 | WebPreferences web_prefs; |
| 1126 | |
| 1127 | web_prefs.standard_font_family = |
| 1128 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily)); |
| 1129 | web_prefs.fixed_font_family = |
| 1130 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily)); |
| 1131 | web_prefs.serif_font_family = |
| 1132 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily)); |
| 1133 | web_prefs.sans_serif_font_family = |
| 1134 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily)); |
| 1135 | web_prefs.cursive_font_family = |
| 1136 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily)); |
| 1137 | web_prefs.fantasy_font_family = |
| 1138 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily)); |
| 1139 | |
| 1140 | FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap, |
| 1141 | &web_prefs.standard_font_family_map); |
| 1142 | FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap, |
| 1143 | &web_prefs.fixed_font_family_map); |
| 1144 | FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap, |
| 1145 | &web_prefs.serif_font_family_map); |
| 1146 | FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap, |
| 1147 | &web_prefs.sans_serif_font_family_map); |
| 1148 | FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap, |
| 1149 | &web_prefs.cursive_font_family_map); |
| 1150 | FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap, |
| 1151 | &web_prefs.fantasy_font_family_map); |
| 1152 | |
| 1153 | web_prefs.default_font_size = |
| 1154 | prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize); |
| 1155 | web_prefs.default_fixed_font_size = |
| 1156 | prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize); |
| 1157 | web_prefs.minimum_font_size = |
| 1158 | prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize); |
| 1159 | web_prefs.minimum_logical_font_size = |
| 1160 | prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize); |
| 1161 | |
| 1162 | web_prefs.default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset); |
| 1163 | |
| 1164 | web_prefs.javascript_can_open_windows_automatically = |
| 1165 | prefs->GetBoolean( |
| 1166 | prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically); |
| 1167 | web_prefs.dom_paste_enabled = |
| 1168 | prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); |
| 1169 | web_prefs.shrinks_standalone_images_to_fit = |
| 1170 | prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit); |
| 1171 | const DictionaryValue* inspector_settings = |
| 1172 | prefs->GetDictionary(prefs::kWebKitInspectorSettings); |
| 1173 | if (inspector_settings) { |
| 1174 | for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys()); |
| 1175 | iter != inspector_settings->end_keys(); ++iter) { |
| 1176 | std::string value; |
| 1177 | if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value)) |
| 1178 | web_prefs.inspector_settings.push_back( |
| 1179 | std::make_pair(*iter, value)); |
| 1180 | } |
| 1181 | } |
| 1182 | web_prefs.tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); |
| 1183 | |
| 1184 | { // Command line switches are used for preferences with no user interface. |
| 1185 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 1186 | web_prefs.developer_extras_enabled = true; |
| 1187 | web_prefs.javascript_enabled = |
| 1188 | !command_line.HasSwitch(switches::kDisableJavaScript) && |
| 1189 | prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1190 | web_prefs.web_security_enabled = |
| 1191 | !command_line.HasSwitch(switches::kDisableWebSecurity) && |
| 1192 | prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled); |
| 1193 | web_prefs.plugins_enabled = |
| 1194 | !command_line.HasSwitch(switches::kDisablePlugins) && |
| 1195 | prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled); |
| 1196 | web_prefs.java_enabled = |
| 1197 | !command_line.HasSwitch(switches::kDisableJava) && |
| 1198 | prefs->GetBoolean(prefs::kWebKitJavaEnabled); |
| 1199 | web_prefs.loads_images_automatically = |
| 1200 | prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically); |
| 1201 | web_prefs.uses_page_cache = |
| 1202 | command_line.HasSwitch(switches::kEnableFastback); |
| 1203 | web_prefs.remote_fonts_enabled = |
| 1204 | !command_line.HasSwitch(switches::kDisableRemoteFonts); |
| 1205 | web_prefs.xss_auditor_enabled = |
| 1206 | !command_line.HasSwitch(switches::kDisableXSSAuditor); |
| 1207 | web_prefs.application_cache_enabled = |
| 1208 | !command_line.HasSwitch(switches::kDisableApplicationCache); |
| 1209 | |
| 1210 | web_prefs.local_storage_enabled = |
| 1211 | !command_line.HasSwitch(switches::kDisableLocalStorage); |
| 1212 | web_prefs.databases_enabled = |
| 1213 | !command_line.HasSwitch(switches::kDisableDatabases); |
| 1214 | web_prefs.webaudio_enabled = |
| 1215 | !command_line.HasSwitch(switches::kDisableWebAudio); |
| 1216 | web_prefs.experimental_webgl_enabled = |
| 1217 | GpuProcessHost::gpu_enabled() && |
| 1218 | !command_line.HasSwitch(switches::kDisable3DAPIs) && |
| 1219 | !prefs->GetBoolean(prefs::kDisable3DAPIs) && |
| 1220 | !command_line.HasSwitch(switches::kDisableExperimentalWebGL); |
| 1221 | web_prefs.gl_multisampling_enabled = |
| 1222 | !command_line.HasSwitch(switches::kDisableGLMultisampling); |
| 1223 | web_prefs.privileged_webgl_extensions_enabled = |
| 1224 | command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions); |
| 1225 | web_prefs.site_specific_quirks_enabled = |
| 1226 | !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks); |
| 1227 | web_prefs.allow_file_access_from_file_urls = |
| 1228 | command_line.HasSwitch(switches::kAllowFileAccessFromFiles); |
| 1229 | web_prefs.show_composited_layer_borders = |
| 1230 | command_line.HasSwitch(switches::kShowCompositedLayerBorders); |
| 1231 | web_prefs.show_composited_layer_tree = |
| 1232 | command_line.HasSwitch(switches::kShowCompositedLayerTree); |
| 1233 | web_prefs.show_fps_counter = |
| 1234 | command_line.HasSwitch(switches::kShowFPSCounter); |
| 1235 | web_prefs.accelerated_compositing_enabled = |
| 1236 | GpuProcessHost::gpu_enabled() && |
| 1237 | !command_line.HasSwitch(switches::kDisableAcceleratedCompositing); |
| 1238 | web_prefs.threaded_compositing_enabled = |
| 1239 | command_line.HasSwitch(switches::kEnableThreadedCompositing); |
| 1240 | web_prefs.force_compositing_mode = |
| 1241 | command_line.HasSwitch(switches::kForceCompositingMode); |
| 1242 | web_prefs.fixed_position_compositing_enabled = |
| 1243 | command_line.HasSwitch(switches::kEnableCompositingForFixedPosition); |
| 1244 | web_prefs.allow_webui_compositing = |
| 1245 | command_line.HasSwitch(switches::kAllowWebUICompositing); |
| 1246 | web_prefs.accelerated_2d_canvas_enabled = |
| 1247 | GpuProcessHost::gpu_enabled() && |
| 1248 | !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas); |
| 1249 | web_prefs.accelerated_painting_enabled = |
| 1250 | GpuProcessHost::gpu_enabled() && |
| 1251 | command_line.HasSwitch(switches::kEnableAcceleratedPainting); |
| 1252 | web_prefs.accelerated_filters_enabled = |
| 1253 | GpuProcessHost::gpu_enabled() && |
| 1254 | command_line.HasSwitch(switches::kEnableAcceleratedFilters); |
| 1255 | web_prefs.accelerated_layers_enabled = |
| 1256 | !command_line.HasSwitch(switches::kDisableAcceleratedLayers); |
| 1257 | web_prefs.composite_to_texture_enabled = |
| 1258 | command_line.HasSwitch(switches::kEnableCompositeToTexture); |
| 1259 | web_prefs.accelerated_plugins_enabled = |
| 1260 | !command_line.HasSwitch(switches::kDisableAcceleratedPlugins); |
| 1261 | web_prefs.accelerated_video_enabled = |
| 1262 | !command_line.HasSwitch(switches::kDisableAcceleratedVideo); |
| 1263 | web_prefs.partial_swap_enabled = |
| 1264 | command_line.HasSwitch(switches::kEnablePartialSwap); |
| 1265 | web_prefs.memory_info_enabled = |
| 1266 | prefs->GetBoolean(prefs::kEnableMemoryInfo); |
| 1267 | web_prefs.interactive_form_validation_enabled = |
| 1268 | !command_line.HasSwitch(switches::kDisableInteractiveFormValidation); |
| 1269 | web_prefs.fullscreen_enabled = |
| 1270 | !command_line.HasSwitch(switches::kDisableFullScreen); |
| 1271 | web_prefs.allow_displaying_insecure_content = |
| 1272 | prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent); |
| 1273 | web_prefs.allow_running_insecure_content = |
| 1274 | prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); |
| 1275 | |
| 1276 | #if defined(OS_MACOSX) |
| 1277 | bool default_enable_scroll_animator = true; |
| 1278 | #else |
| 1279 | // On CrOS, the launcher always passes in the --enable flag. |
| 1280 | bool default_enable_scroll_animator = false; |
| 1281 | #endif |
| 1282 | web_prefs.enable_scroll_animator = default_enable_scroll_animator; |
| 1283 | if (command_line.HasSwitch(switches::kEnableSmoothScrolling)) |
| 1284 | web_prefs.enable_scroll_animator = true; |
| 1285 | if (command_line.HasSwitch(switches::kDisableSmoothScrolling)) |
| 1286 | web_prefs.enable_scroll_animator = false; |
| 1287 | |
| 1288 | // The user stylesheet watcher may not exist in a testing profile. |
| 1289 | if (profile->GetUserStyleSheetWatcher()) { |
| 1290 | web_prefs.user_style_sheet_enabled = true; |
| 1291 | web_prefs.user_style_sheet_location = |
| 1292 | profile->GetUserStyleSheetWatcher()->user_style_sheet(); |
| 1293 | } else { |
| 1294 | web_prefs.user_style_sheet_enabled = false; |
| 1295 | } |
| 1296 | |
| 1297 | web_prefs.visual_word_movement_enabled = |
| 1298 | command_line.HasSwitch(switches::kEnableVisualWordMovement); |
| 1299 | web_prefs.unified_textchecker_enabled = |
| 1300 | command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures); |
| 1301 | web_prefs.per_tile_painting_enabled = |
| 1302 | command_line.HasSwitch(switches::kEnablePerTilePainting); |
| 1303 | } |
| 1304 | |
| 1305 | { // Certain GPU features might have been blacklisted. |
| 1306 | GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance(); |
| 1307 | DCHECK(gpu_data_manager); |
| 1308 | uint32 blacklist_flags = gpu_data_manager->GetGpuFeatureFlags().flags(); |
| 1309 | if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing) |
| 1310 | web_prefs.accelerated_compositing_enabled = false; |
| 1311 | if (blacklist_flags & GpuFeatureFlags::kGpuFeatureWebgl) |
| 1312 | web_prefs.experimental_webgl_enabled = false; |
| 1313 | if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas) |
| 1314 | web_prefs.accelerated_2d_canvas_enabled = false; |
| 1315 | if (blacklist_flags & GpuFeatureFlags::kGpuFeatureMultisampling) |
| 1316 | web_prefs.gl_multisampling_enabled = false; |
[email protected] | dd5d0fb | 2012-01-18 03:37:57 | [diff] [blame] | 1317 | |
| 1318 | // Accelerated video is slower than regular when using a software 3d |
| 1319 | // rasterizer. |
| 1320 | if (gpu_data_manager->software_rendering()) |
| 1321 | web_prefs.accelerated_video_enabled = false; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | web_prefs.uses_universal_detector = |
| 1325 | prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector); |
| 1326 | web_prefs.text_areas_are_resizable = |
| 1327 | prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); |
| 1328 | web_prefs.hyperlink_auditing_enabled = |
| 1329 | prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); |
| 1330 | |
| 1331 | // Make sure we will set the default_encoding with canonical encoding name. |
| 1332 | web_prefs.default_encoding = |
| 1333 | CharacterEncoding::GetCanonicalEncodingNameByAliasName( |
| 1334 | web_prefs.default_encoding); |
| 1335 | if (web_prefs.default_encoding.empty()) { |
| 1336 | prefs->ClearPref(prefs::kGlobalDefaultCharset); |
| 1337 | web_prefs.default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset); |
| 1338 | } |
| 1339 | DCHECK(!web_prefs.default_encoding.empty()); |
| 1340 | |
| 1341 | if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings( |
| 1342 | rvh->process()->GetID())) { |
| 1343 | web_prefs.loads_images_automatically = true; |
| 1344 | web_prefs.javascript_enabled = true; |
| 1345 | } |
| 1346 | |
| 1347 | web_prefs.is_online = !net::NetworkChangeNotifier::IsOffline(); |
| 1348 | |
| 1349 | ExtensionService* service = profile->GetExtensionService(); |
| 1350 | if (service) { |
| 1351 | const Extension* extension = service->extensions()->GetByID( |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1352 | rvh->site_instance()->GetSite().host()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1353 | extension_webkit_preferences::SetPreferences( |
| 1354 | extension, rvh->delegate()->GetRenderViewType(), &web_prefs); |
| 1355 | } |
| 1356 | |
| 1357 | if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) { |
| 1358 | web_prefs.allow_scripts_to_close_windows = true; |
| 1359 | } else if (rvh->delegate()->GetRenderViewType() == |
| 1360 | chrome::VIEW_TYPE_BACKGROUND_CONTENTS) { |
| 1361 | // Disable all kinds of acceleration for background pages. |
| 1362 | // See http://crbug.com/96005 and http://crbug.com/96006 |
| 1363 | web_prefs.force_compositing_mode = false; |
| 1364 | web_prefs.accelerated_compositing_enabled = false; |
| 1365 | web_prefs.accelerated_2d_canvas_enabled = false; |
| 1366 | web_prefs.accelerated_video_enabled = false; |
| 1367 | web_prefs.accelerated_painting_enabled = false; |
| 1368 | web_prefs.accelerated_plugins_enabled = false; |
| 1369 | } |
| 1370 | |
| 1371 | return web_prefs; |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | void ChromeContentBrowserClient::UpdateInspectorSetting( |
| 1375 | RenderViewHost* rvh, const std::string& key, const std::string& value) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1376 | content::BrowserContext* browser_context = |
| 1377 | rvh->process()->GetBrowserContext(); |
| 1378 | DictionaryPrefUpdate update( |
| 1379 | Profile::FromBrowserContext(browser_context)->GetPrefs(), |
| 1380 | prefs::kWebKitInspectorSettings); |
| 1381 | DictionaryValue* inspector_settings = update.Get(); |
| 1382 | inspector_settings->SetWithoutPathExpansion(key, |
| 1383 | Value::CreateStringValue(value)); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1387 | content::BrowserContext* browser_context = |
| 1388 | rvh->process()->GetBrowserContext(); |
| 1389 | Profile::FromBrowserContext(browser_context)->GetPrefs()-> |
| 1390 | ClearPref(prefs::kWebKitInspectorSettings); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 1391 | } |
| 1392 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1393 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 1394 | BrowserURLHandler* handler) { |
| 1395 | // Add the default URL handlers. |
| 1396 | handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, |
| 1397 | BrowserURLHandler::null_handler()); |
| 1398 | handler->AddHandlerPair(BrowserURLHandler::null_handler(), |
| 1399 | &ExtensionWebUI::HandleChromeURLOverrideReverse); |
| 1400 | |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 1401 | // about: handler. Must come before chrome: handler, since it will |
| 1402 | // rewrite about: urls to chrome: URLs and then expect chrome: to |
| 1403 | // actually handle them. |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1404 | handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 1405 | BrowserURLHandler::null_handler()); |
| 1406 | // chrome: & friends. |
| 1407 | handler->AddHandlerPair(&HandleWebUI, |
| 1408 | BrowserURLHandler::null_handler()); |
| 1409 | } |
| 1410 | |
| 1411 | void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1412 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1413 | rvh->site_instance()->GetProcess()->GetBrowserContext()); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1414 | BrowsingDataRemover* remover = new BrowsingDataRemover(profile, |
| 1415 | BrowsingDataRemover::EVERYTHING, |
| 1416 | base::Time()); |
| 1417 | remover->Remove(BrowsingDataRemover::REMOVE_CACHE); |
| 1418 | // BrowsingDataRemover takes care of deleting itself when done. |
| 1419 | } |
| 1420 | |
| 1421 | void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1422 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1423 | rvh->site_instance()->GetProcess()->GetBrowserContext()); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1424 | BrowsingDataRemover* remover = new BrowsingDataRemover(profile, |
| 1425 | BrowsingDataRemover::EVERYTHING, |
| 1426 | base::Time()); |
[email protected] | dceaa91 | 2011-09-06 17:17:23 | [diff] [blame] | 1427 | int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA; |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1428 | remover->Remove(remove_mask); |
| 1429 | // BrowsingDataRemover takes care of deleting itself when done. |
| 1430 | } |
| 1431 | |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 1432 | FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
| 1433 | return download_util::GetDefaultDownloadDirectory(); |
| 1434 | } |
| 1435 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 1436 | std::string ChromeContentBrowserClient::GetDefaultDownloadName() { |
| 1437 | return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 1438 | } |
| 1439 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 1440 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1441 | int ChromeContentBrowserClient::GetCrashSignalFD( |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 1442 | const CommandLine& command_line) { |
| 1443 | if (command_line.HasSwitch(switches::kExtensionProcess)) { |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 1444 | ExtensionCrashHandlerHostLinux* crash_handler = |
| 1445 | ExtensionCrashHandlerHostLinux::GetInstance(); |
| 1446 | return crash_handler->GetDeathSignalSocket(); |
| 1447 | } |
| 1448 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 1449 | std::string process_type = |
| 1450 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 1451 | |
| 1452 | if (process_type == switches::kRendererProcess) |
| 1453 | return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 1454 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1455 | if (process_type == switches::kPluginProcess) |
| 1456 | return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 1457 | |
| 1458 | if (process_type == switches::kPpapiPluginProcess) |
| 1459 | return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 1460 | |
| 1461 | if (process_type == switches::kGpuProcess) |
| 1462 | return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 1463 | |
| 1464 | return -1; |
| 1465 | } |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 1466 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1467 | |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 1468 | #if defined(OS_WIN) |
| 1469 | const wchar_t* ChromeContentBrowserClient::GetResourceDllName() { |
| 1470 | return chrome::kBrowserResourcesDll; |
| 1471 | } |
| 1472 | #endif |
| 1473 | |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 1474 | #if defined(USE_NSS) |
| 1475 | crypto::CryptoModuleBlockingPasswordDelegate* |
| 1476 | ChromeContentBrowserClient::GetCryptoPasswordDelegate( |
| 1477 | const GURL& url) { |
| 1478 | return browser::NewCryptoModuleBlockingDialogDelegate( |
| 1479 | browser::kCryptoModulePasswordKeygen, url.host()); |
| 1480 | } |
| 1481 | #endif |
| 1482 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 1483 | } // namespace chrome |