[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/chrome_content_browser_client.h" |
| 6 | |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 7 | #include <set> |
[email protected] | 1033acd | 2012-02-08 08:46:27 | [diff] [blame] | 8 | #include <utility> |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 11 | #include "base/bind.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 13 | #include "base/string_tokenizer.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 14 | #include "base/utf_string_conversions.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 15 | #include "chrome/app/breakpad_mac.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 16 | #include "chrome/browser/browser_about_handler.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 17 | #include "chrome/browser/browser_process.h" |
[email protected] | 3b8f7e3 | 2011-07-13 11:52:23 | [diff] [blame] | 18 | #include "chrome/browser/browsing_data_remover.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 19 | #include "chrome/browser/character_encoding.h" |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 20 | #include "chrome/browser/chrome_benchmarking_message_filter.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 21 | #include "chrome/browser/chrome_quota_permission_context.h" |
[email protected] | edece21 | 2011-11-16 11:56:56 | [diff] [blame] | 22 | #include "chrome/browser/content_settings/content_settings_utils.h" |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 23 | #include "chrome/browser/content_settings/cookie_settings.h" |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 24 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 25 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 26 | #include "chrome/browser/defaults.h" |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 27 | #include "chrome/browser/download/download_util.h" |
[email protected] | 6e672df | 2012-01-25 10:39:47 | [diff] [blame] | 28 | #include "chrome/browser/extensions/api/webrequest/webrequest_api.h" |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 29 | #include "chrome/browser/extensions/extension_host.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 30 | #include "chrome/browser/extensions/extension_info_map.h" |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 31 | #include "chrome/browser/extensions/extension_process_manager.h" |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 32 | #include "chrome/browser/extensions/extension_message_handler.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 33 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 34 | #include "chrome/browser/extensions/extension_web_ui.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 35 | #include "chrome/browser/extensions/extension_webkit_preferences.h" |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 36 | #include "chrome/browser/geolocation/chrome_access_token_store.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 37 | #include "chrome/browser/google/google_util.h" |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 38 | #include "chrome/browser/net/chrome_net_log.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 39 | #include "chrome/browser/notifications/desktop_notification_service.h" |
| 40 | #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 41 | #include "chrome/browser/platform_util.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 42 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 43 | #include "chrome/browser/prefs/scoped_user_pref_update.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 44 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 45 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 46 | #include "chrome/browser/prerender/prerender_tracker.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 47 | #include "chrome/browser/printing/printing_message_filter.h" |
| 48 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 49 | #include "chrome/browser/profiles/profile_io_data.h" |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 50 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 51 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | 53a0afa | 2011-04-28 02:09:33 | [diff] [blame] | 52 | #include "chrome/browser/renderer_host/chrome_render_view_host_observer.h" |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 53 | #include "chrome/browser/renderer_host/plugin_info_message_filter.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 54 | #include "chrome/browser/search_engines/search_provider_install_state_message_filter.h" |
[email protected] | 66cfec6 | 2012-02-24 17:57:51 | [diff] [blame] | 55 | #include "chrome/browser/speech/chrome_speech_input_manager_delegate.h" |
[email protected] | 8ec7126 | 2011-07-28 08:12:46 | [diff] [blame] | 56 | #include "chrome/browser/spellchecker/spellcheck_message_filter.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 57 | #include "chrome/browser/ssl/ssl_add_cert_handler.h" |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 58 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 59 | #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" |
| 60 | #include "chrome/browser/tab_contents/tab_util.h" |
| 61 | #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 62 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 63 | #include "chrome/browser/user_style_sheet_watcher.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 64 | #include "chrome/common/child_process_logging.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 65 | #include "chrome/common/chrome_constants.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 66 | #include "chrome/common/chrome_switches.h" |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 67 | #include "chrome/common/extensions/extension.h" |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 68 | #include "chrome/common/extensions/extension_set.h" |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 69 | #include "chrome/common/logging_chrome.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 70 | #include "chrome/common/pref_names.h" |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 71 | #include "chrome/common/render_messages.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 72 | #include "chrome/common/url_constants.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 73 | #include "content/browser/browser_url_handler.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 74 | #include "content/browser/renderer_host/render_view_host.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 75 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 76 | #include "content/public/browser/child_process_security_policy.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 77 | #include "content/public/browser/render_process_host.h" |
[email protected] | ce96786 | 2012-02-09 22:47:05 | [diff] [blame] | 78 | #include "content/public/browser/resource_context.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] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 86 | #include "net/base/ssl_cert_request_info.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] | cce3ab7 | 2012-02-04 18:05:16 | [diff] [blame] | 127 | #include "chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.h" |
[email protected] | eb668c9 | 2012-02-06 15:35:29 | [diff] [blame] | 128 | #include "content/browser/tab_contents/web_contents_view_mac.h" |
[email protected] | 6e677a34 | 2012-02-11 01:21:14 | [diff] [blame] | 129 | #elif defined(OS_ANDROID) |
[email protected] | 82c9f44b | 2012-02-14 21:02:52 | [diff] [blame] | 130 | #include "content/browser/tab_contents/web_contents_view_android.h" |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 131 | #endif |
| 132 | |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 133 | #if defined(USE_NSS) |
| 134 | #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 135 | #endif |
| 136 | |
[email protected] | c8c7718 | 2011-12-21 15:04:47 | [diff] [blame] | 137 | using content::AccessTokenStore; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 138 | using content::BrowserThread; |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 139 | using content::ChildProcessSecurityPolicy; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 140 | using content::SiteInstance; |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 141 | using content::WebContents; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 142 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 143 | namespace { |
| 144 | |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 145 | const char* kPredefinedAllowedSocketOrigins[] = { |
| 146 | "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client |
| 147 | "pnhechapfaindjhompbnflcldabbghjo" // HTerm App (SSH Client) |
| 148 | }; |
| 149 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 150 | // Handles rewriting Web UI URLs. |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 151 | bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) { |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 152 | if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 153 | browser_context, *url)) |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 154 | return false; |
| 155 | |
| 156 | // Special case the new tab page. In older versions of Chrome, the new tab |
| 157 | // page was hosted at chrome-internal:<blah>. This might be in people's saved |
| 158 | // sessions or bookmarks, so we say any URL with that scheme triggers the new |
| 159 | // tab page. |
| 160 | if (url->SchemeIs(chrome::kChromeInternalScheme)) { |
| 161 | // Rewrite it with the proper new tab URL. |
| 162 | *url = GURL(chrome::kChromeUINewTabURL); |
| 163 | } |
| 164 | |
| 165 | return true; |
| 166 | } |
| 167 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 168 | // Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions |
| 169 | // below. Extension, and isolated apps require different privileges to be |
| 170 | // granted to their RenderProcessHosts. This classification allows us to make |
| 171 | // sure URLs are served by hosts with the right set of privileges. |
| 172 | enum RenderProcessHostPrivilege { |
| 173 | PRIV_NORMAL, |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 174 | PRIV_HOSTED, |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 175 | PRIV_ISOLATED, |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 176 | PRIV_EXTENSION, |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( |
| 180 | const GURL& url, |
| 181 | ExtensionService* service) { |
| 182 | // Default to a normal renderer cause it is lower privileged. This should only |
| 183 | // occur if the URL on a site instance is either malformed, or uninitialized. |
| 184 | // If it is malformed, then there is no need for better privileges anyways. |
| 185 | // If it is uninitialized, but eventually settles on being an a scheme other |
| 186 | // than normal webrenderer, the navigation logic will correct us out of band |
| 187 | // anyways. |
| 188 | if (!url.is_valid()) |
| 189 | return PRIV_NORMAL; |
| 190 | |
| 191 | if (url.SchemeIs(chrome::kExtensionScheme)) { |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 192 | const Extension* extension = |
| 193 | service->extensions()->GetByID(url.host()); |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 194 | if (extension && extension->is_storage_isolated()) |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 195 | return PRIV_ISOLATED; |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 196 | if (extension && extension->is_hosted_app()) |
| 197 | return PRIV_HOSTED; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 198 | |
| 199 | return PRIV_EXTENSION; |
| 200 | } |
| 201 | |
| 202 | return PRIV_NORMAL; |
| 203 | } |
| 204 | |
| 205 | RenderProcessHostPrivilege GetProcessPrivilege( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 206 | content::RenderProcessHost* process_host, |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 207 | extensions::ProcessMap* process_map, |
| 208 | ExtensionService* service) { |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 209 | std::set<std::string> extension_ids = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 210 | process_map->GetExtensionsInProcess(process_host->GetID()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 211 | if (extension_ids.empty()) |
[email protected] | 676f6ab | 2011-10-19 20:23:21 | [diff] [blame] | 212 | return PRIV_NORMAL; |
| 213 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 214 | for (std::set<std::string>::iterator iter = extension_ids.begin(); |
| 215 | iter != extension_ids.end(); ++iter) { |
| 216 | const Extension* extension = service->GetExtensionById(*iter, false); |
| 217 | if (extension && extension->is_storage_isolated()) |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 218 | return PRIV_ISOLATED; |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 219 | if (extension && extension->is_hosted_app()) |
| 220 | return PRIV_HOSTED; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 221 | } |
| 222 | |
[email protected] | 676f6ab | 2011-10-19 20:23:21 | [diff] [blame] | 223 | return PRIV_EXTENSION; |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 224 | } |
| 225 | |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 226 | bool IsIsolatedAppInProcess(const GURL& site_url, |
| 227 | content::RenderProcessHost* process_host, |
| 228 | extensions::ProcessMap* process_map, |
| 229 | ExtensionService* service) { |
| 230 | std::set<std::string> extension_ids = |
| 231 | process_map->GetExtensionsInProcess(process_host->GetID()); |
| 232 | if (extension_ids.empty()) |
| 233 | return false; |
| 234 | |
| 235 | for (std::set<std::string>::iterator iter = extension_ids.begin(); |
| 236 | iter != extension_ids.end(); ++iter) { |
| 237 | const Extension* extension = service->GetExtensionById(*iter, false); |
| 238 | if (extension && |
| 239 | extension->is_storage_isolated() && |
| 240 | extension->url() == site_url) |
| 241 | return true; |
| 242 | } |
| 243 | |
| 244 | return false; |
| 245 | } |
| 246 | |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 247 | bool CertMatchesFilter(const net::X509Certificate& cert, |
| 248 | const base::DictionaryValue& filter) { |
| 249 | // TODO(markusheintz): This is the minimal required filter implementation. |
| 250 | // Implement a better matcher. |
| 251 | |
| 252 | // An empty filter matches any client certificate since no requirements are |
| 253 | // specified at all. |
| 254 | if (filter.empty()) |
| 255 | return true; |
| 256 | |
| 257 | std::string common_name; |
| 258 | if (filter.GetString("ISSUER.CN", &common_name) && |
| 259 | (cert.issuer().common_name == common_name)) { |
| 260 | return true; |
| 261 | } |
| 262 | return false; |
| 263 | } |
| 264 | |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 265 | // Fills |map| with the per-script font prefs under path |map_name|. |
| 266 | void FillFontFamilyMap(const PrefService* prefs, |
| 267 | const char* map_name, |
| 268 | WebPreferences::ScriptFontFamilyMap* map) { |
| 269 | for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { |
| 270 | const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; |
| 271 | std::string pref_name = base::StringPrintf("%s.%s", map_name, script); |
| 272 | std::string font_family = prefs->GetString(pref_name.c_str()); |
| 273 | if (!font_family.empty()) |
| 274 | map->push_back(std::make_pair(script, UTF8ToUTF16(font_family))); |
| 275 | } |
| 276 | } |
| 277 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 278 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 279 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 280 | namespace chrome { |
| 281 | |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 282 | ChromeContentBrowserClient::ChromeContentBrowserClient() { |
| 283 | for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i) |
| 284 | allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); |
| 285 | |
| 286 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 287 | std::string allowed_list = |
| 288 | command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI); |
| 289 | if (!allowed_list.empty()) { |
| 290 | StringTokenizer t(allowed_list, ","); |
| 291 | while (t.GetNext()) { |
| 292 | allowed_socket_origins_.insert(t.token()); |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | ChromeContentBrowserClient::~ChromeContentBrowserClient() { |
| 298 | } |
| 299 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 300 | content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts( |
| 301 | const content::MainFunctionParams& parameters) { |
| 302 | ChromeBrowserMainParts* main_parts; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 303 | // Construct the Main browser parts based on the OS type. |
| 304 | #if defined(OS_WIN) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 305 | main_parts = new ChromeBrowserMainPartsWin(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 306 | #elif defined(OS_MACOSX) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 307 | main_parts = new ChromeBrowserMainPartsMac(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 308 | #elif defined(OS_CHROMEOS) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 309 | main_parts = new ChromeBrowserMainPartsChromeos(parameters); |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 310 | #elif defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 311 | main_parts = new ChromeBrowserMainPartsLinux(parameters); |
[email protected] | 6e677a34 | 2012-02-11 01:21:14 | [diff] [blame] | 312 | #elif defined(OS_ANDROID) |
| 313 | // Do nothing for Android. |
| 314 | // TODO(klobag): Android initialization should use the |
| 315 | // *BrowserMainParts class-hierarchy for setting up custom initialization. |
| 316 | main_parts = NULL; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 317 | #elif defined(OS_POSIX) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 318 | main_parts = new ChromeBrowserMainPartsPosix(parameters); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 319 | #else |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 320 | NOTREACHED(); |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 321 | main_parts = new ChromeBrowserMainParts(parameters); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 322 | #endif |
| 323 | |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 324 | // Construct additional browser parts. Stages are called in the order in |
| 325 | // which they are added. |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 326 | #if defined(TOOLKIT_USES_GTK) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 327 | main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk()); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 328 | #endif |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 329 | |
| 330 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 331 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 332 | #endif |
| 333 | |
| 334 | #if defined(USE_AURA) |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 335 | main_parts->AddParts(new ChromeBrowserMainExtraPartsAura()); |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 336 | #endif |
| 337 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 338 | return main_parts; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 339 | } |
| 340 | |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 341 | content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView( |
[email protected] | 8dad546b | 2012-01-17 21:47:35 | [diff] [blame] | 342 | WebContents* web_contents) { |
[email protected] | 080f34f | 2011-09-20 05:39:26 | [diff] [blame] | 343 | #if defined(TOOLKIT_VIEWS) |
[email protected] | 8dad546b | 2012-01-17 21:47:35 | [diff] [blame] | 344 | return new TabContentsViewViews(web_contents); |
[email protected] | c92f4ed | 2011-10-21 19:50:21 | [diff] [blame] | 345 | #elif defined(TOOLKIT_USES_GTK) |
[email protected] | 8dad546b | 2012-01-17 21:47:35 | [diff] [blame] | 346 | return new content::TabContentsViewGtk(web_contents, |
[email protected] | 9058042 | 2012-01-12 00:26:22 | [diff] [blame] | 347 | new ChromeTabContentsViewWrapperGtk); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 348 | #elif defined(OS_MACOSX) |
[email protected] | eb668c9 | 2012-02-06 15:35:29 | [diff] [blame] | 349 | return web_contents_view_mac::CreateWebContentsView( |
[email protected] | cce3ab7 | 2012-02-04 18:05:16 | [diff] [blame] | 350 | web_contents, |
| 351 | chrome_web_contents_view_mac_delegate::CreateWebContentsViewMacDelegate( |
| 352 | web_contents)); |
[email protected] | 6e677a34 | 2012-02-11 01:21:14 | [diff] [blame] | 353 | #elif defined(OS_ANDROID) |
[email protected] | 82c9f44b | 2012-02-14 21:02:52 | [diff] [blame] | 354 | return new WebContentsViewAndroid(web_contents); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 355 | #else |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 356 | #error Need to create your platform WebContentsView here. |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 357 | #endif |
| 358 | } |
| 359 | |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 360 | void ChromeContentBrowserClient::RenderViewHostCreated( |
| 361 | RenderViewHost* render_view_host) { |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 362 | |
| 363 | SiteInstance* site_instance = render_view_host->site_instance(); |
| 364 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 365 | site_instance->GetBrowserContext()); |
[email protected] | 67372ecf | 2011-09-10 01:30:46 | [diff] [blame] | 366 | |
| 367 | new ChromeRenderViewHostObserver(render_view_host, |
| 368 | profile->GetNetworkPredictor()); |
[email protected] | f364d139 | 2011-04-08 21:03:10 | [diff] [blame] | 369 | new ExtensionMessageHandler(render_view_host); |
[email protected] | 85f0a57 | 2012-02-07 22:20:13 | [diff] [blame] | 370 | |
| 371 | if (render_view_host->delegate()->GetRenderViewType() == |
| 372 | content::VIEW_TYPE_INTERSTITIAL_PAGE) { |
| 373 | render_view_host->Send(new ChromeViewMsg_SetAsInterstitial( |
| 374 | render_view_host->routing_id())); |
| 375 | } |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 376 | } |
| 377 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 378 | void ChromeContentBrowserClient::RenderProcessHostCreated( |
| 379 | content::RenderProcessHost* host) { |
| 380 | int id = host->GetID(); |
| 381 | Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
| 382 | host->GetChannel()->AddFilter(new ChromeRenderMessageFilter( |
[email protected] | c47cfd6 | 2011-04-29 21:27:02 | [diff] [blame] | 383 | id, profile, profile->GetRequestContextForRenderProcess(id))); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 384 | host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile)); |
| 385 | host->GetChannel()->AddFilter(new PrintingMessageFilter()); |
| 386 | host->GetChannel()->AddFilter( |
[email protected] | c47cfd6 | 2011-04-29 21:27:02 | [diff] [blame] | 387 | new SearchProviderInstallStateMessageFilter(id, profile)); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 388 | host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id)); |
[email protected] | 7ceb9901 | 2011-12-21 08:05:56 | [diff] [blame] | 389 | #if defined(OS_MACOSX) |
| 390 | host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac()); |
| 391 | #endif |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 392 | host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter( |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 393 | id, profile, profile->GetRequestContextForRenderProcess(id))); |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 394 | |
[email protected] | 2ccf45c | 2011-08-19 23:35:50 | [diff] [blame] | 395 | host->Send(new ChromeViewMsg_SetIsIncognitoProcess( |
| 396 | profile->IsOffTheRecord())); |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 397 | |
| 398 | SendExtensionWebRequestStatusToHost(host); |
[email protected] | edece21 | 2011-11-16 11:56:56 | [diff] [blame] | 399 | |
| 400 | RendererContentSettingRules rules; |
| 401 | GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules); |
| 402 | host->Send(new ChromeViewMsg_SetContentSettingRules(rules)); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 403 | } |
| 404 | |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 405 | content::WebUIControllerFactory* |
| 406 | ChromeContentBrowserClient::GetWebUIControllerFactory() { |
| 407 | return ChromeWebUIControllerFactory::GetInstance(); |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 408 | } |
| 409 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 410 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
| 411 | content::BrowserContext* browser_context, const GURL& url) { |
| 412 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 413 | // Get the effective URL for the given actual URL. If the URL is part of an |
| 414 | // installed app, the effective URL is an extension URL with the ID of that |
| 415 | // extension as the host. This has the effect of grouping apps together in |
| 416 | // a common SiteInstance. |
| 417 | if (!profile || !profile->GetExtensionService()) |
| 418 | return url; |
| 419 | |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 420 | const Extension* extension = profile->GetExtensionService()->extensions()-> |
| 421 | GetHostedAppByURL(ExtensionURLInfo(url)); |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 422 | if (!extension) |
| 423 | return url; |
| 424 | |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 425 | // Bookmark apps do not use the hosted app process model, and should be |
| 426 | // treated as normal URLs. |
| 427 | if (extension->from_bookmark()) |
| 428 | return url; |
| 429 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 430 | // If the URL is part of an extension's web extent, convert it to an |
| 431 | // extension URL. |
| 432 | return extension->GetResourceURL(url.path()); |
| 433 | } |
| 434 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 435 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 436 | content::BrowserContext* browser_context, const GURL& effective_url) { |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 437 | // Non-extension URLs should generally use process-per-site-instance. |
[email protected] | 15877ca | 2011-11-18 22:40:52 | [diff] [blame] | 438 | // Because we expect to use the effective URL, URLs for hosted apps (apart |
| 439 | // from bookmark apps) should have an extension scheme by now. |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 440 | if (!effective_url.SchemeIs(chrome::kExtensionScheme)) |
| 441 | return false; |
| 442 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 443 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 444 | if (!profile || !profile->GetExtensionService()) |
| 445 | return false; |
| 446 | |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 447 | const Extension* extension = profile->GetExtensionService()->extensions()-> |
| 448 | GetExtensionOrAppByURL(ExtensionURLInfo(effective_url)); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 449 | if (!extension) |
| 450 | return false; |
| 451 | |
| 452 | // If the URL is part of a hosted app that does not have the background |
| 453 | // permission, we want to give each instance its own process to improve |
| 454 | // responsiveness. |
| 455 | if (extension->GetType() == Extension::TYPE_HOSTED_APP && |
| 456 | !extension->HasAPIPermission(ExtensionAPIPermission::kBackground)) |
| 457 | return false; |
| 458 | |
| 459 | // Hosted apps that have the background permission must use process per site, |
| 460 | // since all instances can make synchronous calls to the background window. |
| 461 | // Other extensions should use process per site as well. |
| 462 | return true; |
| 463 | } |
| 464 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 465 | bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { |
| 466 | return ProfileIOData::IsHandledURL(url); |
| 467 | } |
| 468 | |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 469 | bool ChromeContentBrowserClient::IsSuitableHost( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 470 | content::RenderProcessHost* process_host, |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 471 | const GURL& site_url) { |
| 472 | Profile* profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 473 | Profile::FromBrowserContext(process_host->GetBrowserContext()); |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 474 | ExtensionService* service = profile->GetExtensionService(); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 475 | extensions::ProcessMap* process_map = service->process_map(); |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 476 | |
[email protected] | ffa9760 | 2011-11-17 17:55:52 | [diff] [blame] | 477 | // Don't allow the Task Manager to share a process with anything else. |
| 478 | // Otherwise it can affect the renderers it is observing. |
| 479 | // Note: we could create another RenderProcessHostPrivilege bucket for |
| 480 | // this to allow multiple chrome://tasks instances to share, but that's |
| 481 | // a very unlikely case without serious consequences. |
| 482 | if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin()) |
| 483 | return false; |
| 484 | |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 485 | // These may be NULL during tests. In that case, just assume any site can |
| 486 | // share any host. |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 487 | if (!service || !process_map) |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 488 | return true; |
| 489 | |
[email protected] | a8c269a | 2011-10-25 20:17:22 | [diff] [blame] | 490 | // Experimental: |
| 491 | // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages |
| 492 | // to share a renderer process. (We could allow pages from the same site or |
| 493 | // extensions of the same type to share, if we knew what the given process |
| 494 | // was dedicated to. Allowing no sharing is simpler for now.) This may |
| 495 | // cause resource exhaustion issues if too many sites are open at once. |
| 496 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 497 | if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation)) |
| 498 | return false; |
| 499 | |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 500 | // An isolated app is only allowed to share with the exact same app in order |
| 501 | // to provide complete renderer process isolation. This also works around |
| 502 | // issue http://crbug.com/85588, where different isolated apps in the same |
| 503 | // process would end up using the first app's storage contexts. |
| 504 | RenderProcessHostPrivilege privilege_required = |
[email protected] | 8d3132f6 | 2011-10-12 07:13:42 | [diff] [blame] | 505 | GetPrivilegeRequiredByUrl(site_url, service); |
[email protected] | eec0b33c | 2011-12-05 22:09:45 | [diff] [blame] | 506 | if (privilege_required == PRIV_ISOLATED) |
| 507 | return IsIsolatedAppInProcess(site_url, process_host, process_map, service); |
| 508 | |
| 509 | // Otherwise, just make sure the process privilege matches the privilege |
| 510 | // required by the site. |
| 511 | return GetProcessPrivilege(process_host, process_map, service) == |
| 512 | privilege_required; |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 513 | } |
| 514 | |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 515 | // This function is trying to limit the amount of processes used by extensions |
| 516 | // with background pages. It uses a globally set percentage of processes to |
| 517 | // run such extensions and if the limit is exceeded, it returns true, to |
| 518 | // indicate to the content module to group extensions together. |
| 519 | bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( |
| 520 | content::BrowserContext* browser_context, const GURL& url) { |
| 521 | // It has to be a valid URL for us to check for an extension. |
| 522 | if (!url.is_valid()) |
| 523 | return false; |
| 524 | |
| 525 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 526 | ExtensionService* service = profile->GetExtensionService(); |
| 527 | if (!service) |
| 528 | return false; |
| 529 | |
| 530 | // We have to have a valid extension with background page to proceed. |
| 531 | const Extension* extension = |
| 532 | service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url)); |
| 533 | if (!extension) |
| 534 | return false; |
| 535 | if (!extension->has_background_page()) |
| 536 | return false; |
| 537 | |
| 538 | std::set<int> process_ids; |
| 539 | size_t max_process_count = |
| 540 | content::RenderProcessHost::GetMaxRendererProcessCount(); |
| 541 | |
| 542 | // Go through all profiles to ensure we have total count of extension |
| 543 | // processes containing background pages, otherwise one profile can |
| 544 | // starve the other. |
| 545 | std::vector<Profile*> profiles = g_browser_process->profile_manager()-> |
| 546 | GetLoadedProfiles(); |
| 547 | for (size_t i = 0; i < profiles.size(); ++i) { |
| 548 | ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager(); |
| 549 | for (ExtensionProcessManager::const_iterator iter = epm->begin(); |
| 550 | iter != epm->end(); |
| 551 | ++iter) { |
| 552 | ExtensionHost* host = *iter; |
| 553 | if (host->extension()->has_background_page()) { |
| 554 | process_ids.insert(host->render_process_host()->GetID()); |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | if (process_ids.size() > |
| 560 | (max_process_count * chrome::kMaxShareOfExtensionProcesses)) { |
| 561 | return true; |
| 562 | } |
| 563 | |
| 564 | return false; |
| 565 | } |
| 566 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 567 | void ChromeContentBrowserClient::SiteInstanceGotProcess( |
| 568 | SiteInstance* site_instance) { |
| 569 | CHECK(site_instance->HasProcess()); |
| 570 | |
| 571 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 572 | site_instance->GetBrowserContext()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 573 | ExtensionService* service = profile->GetExtensionService(); |
| 574 | if (!service) |
| 575 | return; |
| 576 | |
| 577 | const Extension* extension = |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 578 | service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo( |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 579 | site_instance->GetSite())); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 580 | if (!extension) |
| 581 | return; |
| 582 | |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 583 | service->process_map()->Insert(extension->id(), |
| 584 | site_instance->GetProcess()->GetID(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 585 | site_instance->GetId()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 586 | BrowserThread::PostTask( |
| 587 | BrowserThread::IO, FROM_HERE, |
| 588 | base::Bind(&ExtensionInfoMap::RegisterExtensionProcess, |
| 589 | profile->GetExtensionInfoMap(), |
| 590 | extension->id(), |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 591 | site_instance->GetProcess()->GetID(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 592 | site_instance->GetId())); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | void ChromeContentBrowserClient::SiteInstanceDeleting( |
| 596 | SiteInstance* site_instance) { |
| 597 | if (!site_instance->HasProcess()) |
| 598 | return; |
| 599 | |
| 600 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 601 | site_instance->GetBrowserContext()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 602 | ExtensionService* service = profile->GetExtensionService(); |
| 603 | if (!service) |
| 604 | return; |
| 605 | |
| 606 | const Extension* extension = |
[email protected] | 615d88f | 2011-12-13 01:47:44 | [diff] [blame] | 607 | service->extensions()->GetExtensionOrAppByURL( |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 608 | ExtensionURLInfo(site_instance->GetSite())); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 609 | if (!extension) |
| 610 | return; |
| 611 | |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 612 | service->process_map()->Remove(extension->id(), |
| 613 | site_instance->GetProcess()->GetID(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 614 | site_instance->GetId()); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 615 | BrowserThread::PostTask( |
| 616 | BrowserThread::IO, FROM_HERE, |
| 617 | base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess, |
| 618 | profile->GetExtensionInfoMap(), |
| 619 | extension->id(), |
[email protected] | 6bc04fd8 | 2011-12-04 02:29:35 | [diff] [blame] | 620 | site_instance->GetProcess()->GetID(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 621 | site_instance->GetId())); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 622 | } |
| 623 | |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 624 | bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation( |
| 625 | const GURL& current_url, |
| 626 | const GURL& new_url) { |
| 627 | if (current_url.is_empty()) { |
| 628 | // Always choose a new process when navigating to extension URLs. The |
| 629 | // process grouping logic will combine all of a given extension's pages |
| 630 | // into the same process. |
| 631 | if (new_url.SchemeIs(chrome::kExtensionScheme)) |
| 632 | return true; |
| 633 | |
| 634 | return false; |
| 635 | } |
| 636 | |
| 637 | // Also, we must switch if one is an extension and the other is not the exact |
| 638 | // same extension. |
| 639 | if (current_url.SchemeIs(chrome::kExtensionScheme) || |
| 640 | new_url.SchemeIs(chrome::kExtensionScheme)) { |
| 641 | if (current_url.GetOrigin() != new_url.GetOrigin()) |
| 642 | return true; |
| 643 | } |
| 644 | |
| 645 | return false; |
| 646 | } |
| 647 | |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 648 | std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName( |
| 649 | const std::string& alias_name) { |
| 650 | return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name); |
| 651 | } |
| 652 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 653 | void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( |
| 654 | CommandLine* command_line, int child_process_id) { |
| 655 | #if defined(USE_LINUX_BREAKPAD) |
| 656 | if (IsCrashReporterEnabled()) { |
| 657 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
| 658 | child_process_logging::GetClientId() + "," + base::GetLinuxDistro()); |
| 659 | } |
| 660 | #elif defined(OS_MACOSX) |
| 661 | if (IsCrashReporterEnabled()) { |
| 662 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
| 663 | child_process_logging::GetClientId()); |
| 664 | } |
| 665 | #endif // OS_MACOSX |
| 666 | |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 667 | if (logging::DialogsAreSuppressed()) |
| 668 | command_line->AppendSwitch(switches::kNoErrorDialogs); |
| 669 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 670 | std::string process_type = |
| 671 | command_line->GetSwitchValueASCII(switches::kProcessType); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 672 | const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 673 | if (process_type == switches::kRendererProcess) { |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 674 | FilePath user_data_dir = |
| 675 | browser_command_line.GetSwitchValuePath(switches::kUserDataDir); |
| 676 | if (!user_data_dir.empty()) |
| 677 | command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir); |
| 678 | #if defined(OS_CHROMEOS) |
| 679 | const std::string& login_profile = |
| 680 | browser_command_line.GetSwitchValueASCII(switches::kLoginProfile); |
| 681 | if (!login_profile.empty()) |
| 682 | command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile); |
| 683 | #endif |
| 684 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 685 | content::RenderProcessHost* process = |
| 686 | content::RenderProcessHost::FromID(child_process_id); |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 687 | if (process) { |
| 688 | Profile* profile = Profile::FromBrowserContext( |
| 689 | process->GetBrowserContext()); |
| 690 | extensions::ProcessMap* process_map = |
| 691 | profile->GetExtensionService()->process_map(); |
| 692 | if (process_map && process_map->Contains(process->GetID())) |
| 693 | command_line->AppendSwitch(switches::kExtensionProcess); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 694 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 695 | PrefService* prefs = profile->GetPrefs(); |
| 696 | // Currently this pref is only registered if applied via a policy. |
| 697 | if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && |
| 698 | prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 699 | // Turn this policy into a command line switch. |
| 700 | command_line->AppendSwitch(switches::kDisable3DAPIs); |
| 701 | } |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 702 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 703 | // Disable client-side phishing detection in the renderer if it is |
| 704 | // disabled in the Profile preferences or the browser process. |
| 705 | if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) || |
| 706 | !g_browser_process->safe_browsing_detection_service()) { |
| 707 | command_line->AppendSwitch( |
| 708 | switches::kDisableClientSidePhishingDetection); |
| 709 | } |
[email protected] | 8c40da6 | 2011-07-13 22:58:46 | [diff] [blame] | 710 | } |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 711 | { |
| 712 | PrefService* local_state = g_browser_process->local_state(); |
| 713 | if (local_state && |
| 714 | !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) { |
| 715 | command_line->AppendSwitch(switches::kRendererPrintPreview); |
| 716 | } |
| 717 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 718 | |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 719 | // Please keep this in alphabetical order. |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 720 | static const char* const kSwitchNames[] = { |
| 721 | switches::kAllowHTTPBackgroundPage, |
[email protected] | 70f48c0 | 2011-12-02 21:27:48 | [diff] [blame] | 722 | switches::kAllowLegacyExtensionManifests, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 723 | switches::kAllowScriptingGallery, |
| 724 | switches::kAppsCheckoutURL, |
| 725 | switches::kAppsGalleryURL, |
[email protected] | be9d9c8 | 2011-07-13 04:17:31 | [diff] [blame] | 726 | switches::kCloudPrintServiceURL, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 727 | switches::kDebugPrint, |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 728 | switches::kDisableBundledPpapiFlash, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 729 | switches::kDumpHistogramsOnExit, |
[email protected] | b7e44ff | 2012-02-16 03:37:34 | [diff] [blame] | 730 | switches::kEnableAsynchronousSpellChecking, |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 731 | switches::kEnableBenchmarking, |
[email protected] | b50368b | 2012-02-18 00:02:13 | [diff] [blame] | 732 | switches::kEnableBundledPpapiFlash, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 733 | switches::kEnableCrxlessWebApps, |
| 734 | switches::kEnableExperimentalExtensionApis, |
| 735 | switches::kEnableInBrowserThumbnailing, |
| 736 | switches::kEnableIPCFuzzing, |
| 737 | switches::kEnableNaCl, |
[email protected] | bcbe765 | 2012-02-22 00:08:48 | [diff] [blame] | 738 | switches::kEnablePasswordGeneration, |
[email protected] | 9776e82e | 2011-11-15 02:17:53 | [diff] [blame] | 739 | switches::kEnablePlatformApps, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 740 | switches::kEnableWatchdog, |
| 741 | switches::kExperimentalSpellcheckerFeatures, |
| 742 | switches::kMemoryProfiling, |
| 743 | switches::kMessageLoopHistogrammer, |
[email protected] | 2a6bb0b1 | 2011-10-05 19:18:04 | [diff] [blame] | 744 | switches::kNoRunningInsecureContent, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 745 | switches::kPpapiFlashArgs, |
| 746 | switches::kPpapiFlashInProcess, |
| 747 | switches::kPpapiFlashPath, |
| 748 | switches::kPpapiFlashVersion, |
| 749 | switches::kProfilingAtStart, |
| 750 | switches::kProfilingFile, |
| 751 | switches::kProfilingFlush, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 752 | switches::kSilentDumpOnDCHECK, |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 753 | switches::kWhitelistedExtensionID, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 754 | }; |
| 755 | |
| 756 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 757 | arraysize(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 758 | } else if (process_type == switches::kUtilityProcess) { |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 759 | static const char* const kSwitchNames[] = { |
| 760 | switches::kEnableExperimentalExtensionApis, |
| 761 | switches::kWhitelistedExtensionID, |
| 762 | }; |
| 763 | |
| 764 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 765 | arraysize(kSwitchNames)); |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 766 | } else if (process_type == switches::kPluginProcess) { |
| 767 | static const char* const kSwitchNames[] = { |
| 768 | #if defined(OS_CHROMEOS) |
| 769 | switches::kLoginProfile, |
| 770 | #endif |
| 771 | switches::kMemoryProfiling, |
| 772 | switches::kSilentDumpOnDCHECK, |
| 773 | switches::kUserDataDir, |
| 774 | }; |
| 775 | |
| 776 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 777 | arraysize(kSwitchNames)); |
| 778 | } else if (process_type == switches::kZygoteProcess) { |
| 779 | static const char* const kSwitchNames[] = { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 780 | switches::kUserDataDir, // Make logs go to the right file. |
| 781 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 782 | switches::kDisableBundledPpapiFlash, |
[email protected] | b50368b | 2012-02-18 00:02:13 | [diff] [blame] | 783 | switches::kEnableBundledPpapiFlash, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 784 | switches::kPpapiFlashInProcess, |
| 785 | switches::kPpapiFlashPath, |
| 786 | switches::kPpapiFlashVersion, |
| 787 | }; |
| 788 | |
| 789 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 790 | arraysize(kSwitchNames)); |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 791 | } else if (process_type == switches::kGpuProcess) { |
| 792 | // If --ignore-gpu-blacklist is passed in, don't send in crash reports |
| 793 | // because GPU is expected to be unreliable. |
| 794 | if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) && |
| 795 | !command_line->HasSwitch(switches::kDisableBreakpad)) |
| 796 | command_line->AppendSwitch(switches::kDisableBreakpad); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 797 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 798 | |
| 799 | // The command line switch kEnableBenchmarking needs to be specified along |
| 800 | // with the kEnableStatsTable switch to ensure that the stats table global |
| 801 | // is initialized correctly. |
| 802 | if (command_line->HasSwitch(switches::kEnableBenchmarking)) |
| 803 | DCHECK(command_line->HasSwitch(switches::kEnableStatsTable)); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
| 807 | return g_browser_process->GetApplicationLocale(); |
| 808 | } |
| 809 | |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 810 | std::string ChromeContentBrowserClient::GetAcceptLangs( |
| 811 | content::BrowserContext* context) { |
| 812 | Profile* profile = Profile::FromBrowserContext(context); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 813 | return profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 814 | } |
| 815 | |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 816 | SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() { |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 817 | ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 818 | return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 819 | } |
| 820 | |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 821 | bool ChromeContentBrowserClient::AllowAppCache( |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 822 | const GURL& manifest_url, |
[email protected] | 0a60884 | 2011-09-08 10:55:19 | [diff] [blame] | 823 | const GURL& first_party, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 824 | content::ResourceContext* context) { |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 825 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 826 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 827 | return io_data->GetCookieSettings()-> |
| 828 | IsSettingCookieAllowed(manifest_url, first_party); |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 829 | } |
| 830 | |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 831 | bool ChromeContentBrowserClient::AllowGetCookie( |
| 832 | const GURL& url, |
| 833 | const GURL& first_party, |
| 834 | const net::CookieList& cookie_list, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 835 | content::ResourceContext* context, |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 836 | int render_process_id, |
| 837 | int render_view_id) { |
| 838 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 839 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 840 | bool allow = io_data->GetCookieSettings()-> |
| 841 | IsReadingCookieAllowed(url, first_party); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 842 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 843 | BrowserThread::PostTask( |
| 844 | BrowserThread::UI, FROM_HERE, |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 845 | base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id, |
| 846 | render_view_id, url, cookie_list, !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 847 | return allow; |
| 848 | } |
| 849 | |
| 850 | bool ChromeContentBrowserClient::AllowSetCookie( |
| 851 | const GURL& url, |
| 852 | const GURL& first_party, |
| 853 | const std::string& cookie_line, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 854 | content::ResourceContext* context, |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 855 | int render_process_id, |
| 856 | int render_view_id, |
| 857 | net::CookieOptions* options) { |
| 858 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 859 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 30fde82 | 2011-10-28 09:49:05 | [diff] [blame] | 860 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 861 | bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party); |
| 862 | |
| 863 | if (cookie_settings->IsCookieSessionOnly(url)) |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 864 | options->set_force_session(); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 865 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 866 | BrowserThread::PostTask( |
| 867 | BrowserThread::UI, FROM_HERE, |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 868 | base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id, |
| 869 | render_view_id, url, cookie_line, *options, !allow)); |
[email protected] | ed24fad | 2011-05-10 22:44:01 | [diff] [blame] | 870 | return allow; |
| 871 | } |
| 872 | |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 873 | bool ChromeContentBrowserClient::AllowSaveLocalState( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 874 | content::ResourceContext* context) { |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 875 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 876 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 1848cdc | 2012-02-17 10:48:26 | [diff] [blame] | 877 | |
| 878 | if (!io_data->clear_local_state_on_exit()->GetValue()) |
| 879 | return true; |
| 880 | |
[email protected] | 068b7b5 | 2012-02-27 12:41:44 | [diff] [blame^] | 881 | // Disable clearing the local state on exit if the browsing session is going |
[email protected] | 1848cdc | 2012-02-17 10:48:26 | [diff] [blame] | 882 | // to be restored on the next startup. |
| 883 | SessionStartupPref::Type startup_pref = |
| 884 | SessionStartupPref::PrefValueToType( |
| 885 | io_data->session_startup_pref()->GetValue()); |
| 886 | return (startup_pref == SessionStartupPref::LAST && |
[email protected] | 068b7b5 | 2012-02-27 12:41:44 | [diff] [blame^] | 887 | !CommandLine::ForCurrentProcess()->HasSwitch( |
| 888 | switches::kDisableRestoreSessionState)); |
[email protected] | d5a1916 | 2011-06-30 18:51:54 | [diff] [blame] | 889 | } |
| 890 | |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 891 | bool ChromeContentBrowserClient::AllowWorkerDatabase( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 892 | const GURL& url, |
| 893 | const string16& name, |
| 894 | const string16& display_name, |
| 895 | unsigned long estimated_size, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 896 | content::ResourceContext* context, |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 897 | const std::vector<std::pair<int, int> >& render_views) { |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 898 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 899 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 900 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 901 | bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
| 902 | |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 903 | // Record access to database for potential display in UI. |
| 904 | std::vector<std::pair<int, int> >::const_iterator i; |
| 905 | for (i = render_views.begin(); i != render_views.end(); ++i) { |
| 906 | BrowserThread::PostTask( |
| 907 | BrowserThread::UI, FROM_HERE, |
| 908 | base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed, |
| 909 | i->first, i->second, url, name, display_name, !allow)); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | return allow; |
| 913 | } |
| 914 | |
| 915 | bool ChromeContentBrowserClient::AllowWorkerFileSystem( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 916 | const GURL& url, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 917 | content::ResourceContext* context, |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 918 | const std::vector<std::pair<int, int> >& render_views) { |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 919 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 920 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 921 | CookieSettings* cookie_settings = io_data->GetCookieSettings(); |
| 922 | bool allow = cookie_settings->IsSettingCookieAllowed(url, url); |
| 923 | |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 924 | // Record access to file system for potential display in UI. |
| 925 | std::vector<std::pair<int, int> >::const_iterator i; |
| 926 | for (i = render_views.begin(); i != render_views.end(); ++i) { |
| 927 | BrowserThread::PostTask( |
| 928 | BrowserThread::UI, FROM_HERE, |
| 929 | base::Bind(&TabSpecificContentSettings::FileSystemAccessed, |
| 930 | i->first, i->second, url, !allow)); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | return allow; |
| 934 | } |
| 935 | |
[email protected] | 6133f92 | 2011-07-01 21:34:34 | [diff] [blame] | 936 | net::URLRequestContext* |
| 937 | ChromeContentBrowserClient::OverrideRequestContextForURL( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 938 | const GURL& url, content::ResourceContext* context) { |
[email protected] | 6133f92 | 2011-07-01 21:34:34 | [diff] [blame] | 939 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 940 | if (url.SchemeIs(chrome::kExtensionScheme)) { |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 941 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 6133f92 | 2011-07-01 21:34:34 | [diff] [blame] | 942 | return io_data->extensions_request_context(); |
| 943 | } |
| 944 | |
| 945 | return NULL; |
| 946 | } |
| 947 | |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 948 | QuotaPermissionContext* |
| 949 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
| 950 | return new ChromeQuotaPermissionContext(); |
| 951 | } |
| 952 | |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 953 | void ChromeContentBrowserClient::OpenItem(const FilePath& path) { |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 954 | platform_util::OpenItem(path); |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 955 | } |
| 956 | |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 957 | void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) { |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 958 | platform_util::ShowItemInFolder(path); |
[email protected] | a0ce328 | 2011-08-19 20:49:52 | [diff] [blame] | 959 | } |
| 960 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 961 | void ChromeContentBrowserClient::AllowCertificateError( |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 962 | int render_process_id, |
| 963 | int render_view_id, |
| 964 | int cert_error, |
| 965 | const net::SSLInfo& ssl_info, |
| 966 | const GURL& request_url, |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 967 | bool overridable, |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 968 | const base::Callback<void(bool)>& callback, |
| 969 | bool* cancel_request) { |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 970 | // If the tab is being prerendered, cancel the prerender and the request. |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 971 | WebContents* tab = tab_util::GetWebContentsByID( |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 972 | render_process_id, render_view_id); |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 973 | if (!tab) { |
| 974 | NOTREACHED(); |
| 975 | return; |
| 976 | } |
| 977 | prerender::PrerenderManager* prerender_manager = |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 978 | prerender::PrerenderManagerFactory::GetForProfile( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 979 | Profile::FromBrowserContext(tab->GetBrowserContext())); |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 980 | if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) { |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 981 | if (prerender_manager->prerender_tracker()->TryCancel( |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 982 | render_process_id, render_view_id, |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 983 | prerender::FINAL_STATUS_SSL_ERROR)) { |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 984 | *cancel_request = true; |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 985 | return; |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | // Otherwise, display an SSL blocking page. |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 990 | new SSLBlockingPage( |
| 991 | tab, cert_error, ssl_info, request_url, overridable, callback); |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 992 | } |
| 993 | |
[email protected] | c99c442e | 2011-08-24 11:37:30 | [diff] [blame] | 994 | void ChromeContentBrowserClient::SelectClientCertificate( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 995 | int render_process_id, |
| 996 | int render_view_id, |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 997 | const net::HttpNetworkSession* network_session, |
| 998 | net::SSLCertRequestInfo* cert_request_info, |
| 999 | const base::Callback<void(net::X509Certificate*)>& callback) { |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 1000 | WebContents* tab = tab_util::GetWebContentsByID( |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1001 | render_process_id, render_view_id); |
| 1002 | if (!tab) { |
| 1003 | NOTREACHED(); |
| 1004 | return; |
| 1005 | } |
| 1006 | |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1007 | GURL requesting_url("https://" + cert_request_info->host_and_port); |
| 1008 | DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://" |
| 1009 | << cert_request_info->host_and_port; |
| 1010 | |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 1011 | Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1012 | scoped_ptr<Value> filter( |
| 1013 | profile->GetHostContentSettingsMap()->GetWebsiteSetting( |
| 1014 | requesting_url, |
| 1015 | requesting_url, |
| 1016 | CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, |
| 1017 | std::string(), NULL)); |
| 1018 | |
| 1019 | if (filter.get()) { |
| 1020 | // Try to automatically select a client certificate. |
| 1021 | if (filter->IsType(Value::TYPE_DICTIONARY)) { |
| 1022 | DictionaryValue* filter_dict = |
| 1023 | static_cast<DictionaryValue*>(filter.get()); |
| 1024 | |
| 1025 | const std::vector<scoped_refptr<net::X509Certificate> >& |
| 1026 | all_client_certs = cert_request_info->client_certs; |
| 1027 | for (size_t i = 0; i < all_client_certs.size(); ++i) { |
| 1028 | if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) { |
| 1029 | // Use the first certificate that is matched by the filter. |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 1030 | callback.Run(all_client_certs[i]); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1031 | return; |
| 1032 | } |
| 1033 | } |
| 1034 | } else { |
| 1035 | NOTREACHED(); |
| 1036 | } |
| 1037 | } |
| 1038 | |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1039 | TabContentsWrapper* wrapper = |
| 1040 | TabContentsWrapper::GetCurrentWrapperForContents(tab); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1041 | if (!wrapper) { |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 1042 | // If there is no TabContentsWrapper for the given WebContents then we can't |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1043 | // show the user a dialog to select a client certificate. So we simply |
[email protected] | 2a349e9 | 2011-12-07 12:00:14 | [diff] [blame] | 1044 | // proceed with no client certificate. |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 1045 | callback.Run(NULL); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 1046 | return; |
| 1047 | } |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 1048 | wrapper->ssl_helper()->ShowClientCertificateRequestDialog( |
| 1049 | network_session, cert_request_info, callback); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | void ChromeContentBrowserClient::AddNewCertificate( |
| 1053 | net::URLRequest* request, |
| 1054 | net::X509Certificate* cert, |
| 1055 | int render_process_id, |
| 1056 | int render_view_id) { |
| 1057 | // The handler will run the UI and delete itself when it's finished. |
| 1058 | new SSLAddCertHandler(request, cert, render_process_id, render_view_id); |
| 1059 | } |
| 1060 | |
[email protected] | a93670ab | 2012-02-24 03:46:39 | [diff] [blame] | 1061 | void ChromeContentBrowserClient::RequestMediaAccessPermission( |
| 1062 | const content::MediaStreamRequest* request, |
| 1063 | const content::MediaResponseCallback& callback) { |
| 1064 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1065 | |
| 1066 | content::MediaStreamDeviceArray devices; |
| 1067 | for (content::MediaStreamDeviceMap::const_iterator it = |
| 1068 | request->devices.begin(); it != request->devices.end(); ++it) { |
| 1069 | devices.push_back(*it->second.begin()); |
| 1070 | } |
| 1071 | |
| 1072 | // TODO(macourteau): This is temporary. The base::Callback object will be |
| 1073 | // passed to the Infobar, which will Run it with the request's label and the |
| 1074 | // list of accepted devices (if any), or an empty list of devices if the user |
| 1075 | // has denied the request. |
| 1076 | callback.Run(devices); |
| 1077 | } |
| 1078 | |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1079 | void ChromeContentBrowserClient::RequestDesktopNotificationPermission( |
| 1080 | const GURL& source_origin, |
| 1081 | int callback_context, |
| 1082 | int render_process_id, |
| 1083 | int render_view_id) { |
| 1084 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 1085 | render_process_id, render_view_id); |
| 1086 | if (!rvh) { |
| 1087 | NOTREACHED(); |
| 1088 | return; |
| 1089 | } |
| 1090 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1091 | content::RenderProcessHost* process = rvh->process(); |
| 1092 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1093 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1094 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1095 | service->RequestPermission( |
| 1096 | source_origin, render_process_id, render_view_id, callback_context, |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 1097 | tab_util::GetWebContentsByID(render_process_id, render_view_id)); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | WebKit::WebNotificationPresenter::Permission |
| 1101 | ChromeContentBrowserClient::CheckDesktopNotificationPermission( |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1102 | const GURL& source_origin, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1103 | content::ResourceContext* context, |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1104 | int render_process_id) { |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1105 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1106 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1107 | if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission( |
| 1108 | source_origin, render_process_id, |
| 1109 | ExtensionAPIPermission::kNotification)) |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1110 | return WebKit::WebNotificationPresenter::PermissionAllowed; |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1111 | |
| 1112 | // Fall back to the regular notification preferences, which works on an |
| 1113 | // origin basis. |
| 1114 | return io_data->GetNotificationService() ? |
[email protected] | c7df61b | 2011-11-07 22:06:37 | [diff] [blame] | 1115 | io_data->GetNotificationService()->HasPermission(source_origin) : |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1116 | WebKit::WebNotificationPresenter::PermissionNotAllowed; |
| 1117 | } |
| 1118 | |
| 1119 | void ChromeContentBrowserClient::ShowDesktopNotification( |
[email protected] | 0ee57e2 | 2011-11-12 01:59:17 | [diff] [blame] | 1120 | const content::ShowDesktopNotificationHostMsgParams& params, |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1121 | int render_process_id, |
| 1122 | int render_view_id, |
| 1123 | bool worker) { |
| 1124 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 1125 | render_process_id, render_view_id); |
| 1126 | if (!rvh) { |
| 1127 | NOTREACHED(); |
| 1128 | return; |
| 1129 | } |
| 1130 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1131 | content::RenderProcessHost* process = rvh->process(); |
| 1132 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1133 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1134 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1135 | service->ShowDesktopNotification( |
| 1136 | params, render_process_id, render_view_id, |
| 1137 | worker ? DesktopNotificationService::WorkerNotification : |
| 1138 | DesktopNotificationService::PageNotification); |
| 1139 | } |
| 1140 | |
| 1141 | void ChromeContentBrowserClient::CancelDesktopNotification( |
| 1142 | int render_process_id, |
| 1143 | int render_view_id, |
| 1144 | int notification_id) { |
| 1145 | RenderViewHost* rvh = RenderViewHost::FromID( |
| 1146 | render_process_id, render_view_id); |
| 1147 | if (!rvh) { |
| 1148 | NOTREACHED(); |
| 1149 | return; |
| 1150 | } |
| 1151 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1152 | content::RenderProcessHost* process = rvh->process(); |
| 1153 | Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext()); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1154 | DesktopNotificationService* service = |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1155 | DesktopNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 1156 | service->CancelDesktopNotification( |
| 1157 | render_process_id, render_view_id, notification_id); |
| 1158 | } |
| 1159 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1160 | bool ChromeContentBrowserClient::CanCreateWindow( |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1161 | const GURL& source_origin, |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1162 | WindowContainerType container_type, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1163 | content::ResourceContext* context, |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1164 | int render_process_id) { |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1165 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1166 | // If the opener is trying to create a background window but doesn't have |
| 1167 | // the appropriate permission, fail the attempt. |
| 1168 | if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) { |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1169 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 34eec7ffe3 | 2011-11-02 23:49:02 | [diff] [blame] | 1170 | return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission( |
| 1171 | source_origin, render_process_id, ExtensionAPIPermission::kBackground); |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1172 | } |
| 1173 | return true; |
| 1174 | } |
| 1175 | |
| 1176 | std::string ChromeContentBrowserClient::GetWorkerProcessTitle( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1177 | const GURL& url, content::ResourceContext* context) { |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1178 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1179 | // Check if it's an extension-created worker, in which case we want to use |
| 1180 | // the name of the extension. |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 1181 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 1182 | const Extension* extension = |
| 1183 | io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); |
| 1184 | return extension ? extension->name() : std::string(); |
| 1185 | } |
| 1186 | |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 1187 | void ChromeContentBrowserClient::ResourceDispatcherHostCreated() { |
| 1188 | return g_browser_process->ResourceDispatcherHostCreated(); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 1189 | } |
| 1190 | |
[email protected] | 66cfec6 | 2012-02-24 17:57:51 | [diff] [blame] | 1191 | content::SpeechInputManagerDelegate* |
| 1192 | ChromeContentBrowserClient::GetSpeechInputManagerDelegate() { |
| 1193 | return new speech_input::ChromeSpeechInputManagerDelegate(); |
| 1194 | } |
| 1195 | |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 1196 | ui::Clipboard* ChromeContentBrowserClient::GetClipboard() { |
| 1197 | return g_browser_process->clipboard(); |
| 1198 | } |
| 1199 | |
[email protected] | 8f6a3b85 | 2011-07-19 16:48:56 | [diff] [blame] | 1200 | MHTMLGenerationManager* |
| 1201 | ChromeContentBrowserClient::GetMHTMLGenerationManager() { |
| 1202 | return g_browser_process->mhtml_generation_manager(); |
| 1203 | } |
| 1204 | |
[email protected] | ae6e991 | 2011-07-27 01:18:28 | [diff] [blame] | 1205 | net::NetLog* ChromeContentBrowserClient::GetNetLog() { |
| 1206 | return g_browser_process->net_log(); |
| 1207 | } |
| 1208 | |
[email protected] | 32538d9 | 2011-08-25 00:09:23 | [diff] [blame] | 1209 | AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() { |
| 1210 | return new ChromeAccessTokenStore(); |
| 1211 | } |
| 1212 | |
[email protected] | dbae6b0 | 2011-06-29 23:51:41 | [diff] [blame] | 1213 | bool ChromeContentBrowserClient::IsFastShutdownPossible() { |
| 1214 | const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
| 1215 | return !browser_command_line.HasSwitch(switches::kChromeFrame); |
| 1216 | } |
| 1217 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1218 | void ChromeContentBrowserClient::OverrideWebkitPrefs( |
| 1219 | RenderViewHost* rvh, WebPreferences* web_prefs) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1220 | Profile* profile = Profile::FromBrowserContext( |
| 1221 | rvh->process()->GetBrowserContext()); |
| 1222 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1223 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1224 | web_prefs->standard_font_family = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1225 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily)); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1226 | web_prefs->fixed_font_family = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1227 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily)); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1228 | web_prefs->serif_font_family = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1229 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily)); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1230 | web_prefs->sans_serif_font_family = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1231 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily)); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1232 | web_prefs->cursive_font_family = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1233 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily)); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1234 | web_prefs->fantasy_font_family = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1235 | UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily)); |
| 1236 | |
| 1237 | FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1238 | &web_prefs->standard_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1239 | FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1240 | &web_prefs->fixed_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1241 | FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1242 | &web_prefs->serif_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1243 | FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1244 | &web_prefs->sans_serif_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1245 | FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1246 | &web_prefs->cursive_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1247 | FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap, |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1248 | &web_prefs->fantasy_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1249 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1250 | web_prefs->default_font_size = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1251 | prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1252 | web_prefs->default_fixed_font_size = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1253 | prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1254 | web_prefs->minimum_font_size = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1255 | prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1256 | web_prefs->minimum_logical_font_size = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1257 | prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize); |
| 1258 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1259 | web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1260 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1261 | web_prefs->javascript_can_open_windows_automatically = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1262 | prefs->GetBoolean( |
| 1263 | prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1264 | web_prefs->dom_paste_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1265 | prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1266 | web_prefs->shrinks_standalone_images_to_fit = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1267 | prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit); |
| 1268 | const DictionaryValue* inspector_settings = |
| 1269 | prefs->GetDictionary(prefs::kWebKitInspectorSettings); |
| 1270 | if (inspector_settings) { |
| 1271 | for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys()); |
| 1272 | iter != inspector_settings->end_keys(); ++iter) { |
| 1273 | std::string value; |
| 1274 | if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1275 | web_prefs->inspector_settings.push_back( |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1276 | std::make_pair(*iter, value)); |
| 1277 | } |
| 1278 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1279 | web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1280 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1281 | if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled)) |
| 1282 | web_prefs->javascript_enabled = false; |
| 1283 | if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) |
| 1284 | web_prefs->web_security_enabled = false; |
| 1285 | if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled)) |
| 1286 | web_prefs->plugins_enabled = false; |
| 1287 | if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled)) |
| 1288 | web_prefs->java_enabled = false; |
| 1289 | web_prefs->loads_images_automatically = |
| 1290 | prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1291 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1292 | if (prefs->GetBoolean(prefs::kDisable3DAPIs)) |
| 1293 | web_prefs->experimental_webgl_enabled = false; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1294 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1295 | web_prefs->memory_info_enabled = |
| 1296 | prefs->GetBoolean(prefs::kEnableMemoryInfo); |
| 1297 | web_prefs->allow_displaying_insecure_content = |
| 1298 | prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent); |
| 1299 | web_prefs->allow_running_insecure_content = |
| 1300 | prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 1301 | web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1302 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1303 | // The user stylesheet watcher may not exist in a testing profile. |
| 1304 | if (profile->GetUserStyleSheetWatcher()) { |
| 1305 | web_prefs->user_style_sheet_enabled = true; |
| 1306 | web_prefs->user_style_sheet_location = |
| 1307 | profile->GetUserStyleSheetWatcher()->user_style_sheet(); |
| 1308 | } else { |
| 1309 | web_prefs->user_style_sheet_enabled = false; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1310 | } |
| 1311 | |
[email protected] | b7e44ff | 2012-02-16 03:37:34 | [diff] [blame] | 1312 | web_prefs->asynchronous_spell_checking_enabled = |
| 1313 | CommandLine::ForCurrentProcess()-> |
| 1314 | HasSwitch(switches::kEnableAsynchronousSpellChecking); |
| 1315 | web_prefs->unified_textchecker_enabled = |
| 1316 | web_prefs->asynchronous_spell_checking_enabled || |
| 1317 | CommandLine::ForCurrentProcess()-> |
| 1318 | HasSwitch(switches::kExperimentalSpellcheckerFeatures); |
[email protected] | dd5d0fb | 2012-01-18 03:37:57 | [diff] [blame] | 1319 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1320 | web_prefs->uses_universal_detector = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1321 | prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1322 | web_prefs->text_areas_are_resizable = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1323 | prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1324 | web_prefs->hyperlink_auditing_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1325 | prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); |
| 1326 | |
| 1327 | // Make sure we will set the default_encoding with canonical encoding name. |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1328 | web_prefs->default_encoding = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1329 | CharacterEncoding::GetCanonicalEncodingNameByAliasName( |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1330 | web_prefs->default_encoding); |
| 1331 | if (web_prefs->default_encoding.empty()) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1332 | prefs->ClearPref(prefs::kGlobalDefaultCharset); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1333 | web_prefs->default_encoding = |
| 1334 | prefs->GetString(prefs::kGlobalDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1335 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1336 | DCHECK(!web_prefs->default_encoding.empty()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1337 | |
| 1338 | ExtensionService* service = profile->GetExtensionService(); |
| 1339 | if (service) { |
| 1340 | const Extension* extension = service->extensions()->GetByID( |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1341 | rvh->site_instance()->GetSite().host()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1342 | extension_webkit_preferences::SetPreferences( |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1343 | extension, rvh->delegate()->GetRenderViewType(), web_prefs); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1347 | web_prefs->allow_scripts_to_close_windows = true; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1348 | } else if (rvh->delegate()->GetRenderViewType() == |
| 1349 | chrome::VIEW_TYPE_BACKGROUND_CONTENTS) { |
| 1350 | // Disable all kinds of acceleration for background pages. |
| 1351 | // See http://crbug.com/96005 and http://crbug.com/96006 |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 1352 | web_prefs->force_compositing_mode = false; |
| 1353 | web_prefs->accelerated_compositing_enabled = false; |
| 1354 | web_prefs->accelerated_2d_canvas_enabled = false; |
| 1355 | web_prefs->accelerated_video_enabled = false; |
| 1356 | web_prefs->accelerated_painting_enabled = false; |
| 1357 | web_prefs->accelerated_plugins_enabled = false; |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1358 | } |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | void ChromeContentBrowserClient::UpdateInspectorSetting( |
| 1362 | RenderViewHost* rvh, const std::string& key, const std::string& value) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1363 | content::BrowserContext* browser_context = |
| 1364 | rvh->process()->GetBrowserContext(); |
| 1365 | DictionaryPrefUpdate update( |
| 1366 | Profile::FromBrowserContext(browser_context)->GetPrefs(), |
| 1367 | prefs::kWebKitInspectorSettings); |
| 1368 | DictionaryValue* inspector_settings = update.Get(); |
| 1369 | inspector_settings->SetWithoutPathExpansion(key, |
| 1370 | Value::CreateStringValue(value)); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1374 | content::BrowserContext* browser_context = |
| 1375 | rvh->process()->GetBrowserContext(); |
| 1376 | Profile::FromBrowserContext(browser_context)->GetPrefs()-> |
| 1377 | ClearPref(prefs::kWebKitInspectorSettings); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 1378 | } |
| 1379 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1380 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 1381 | BrowserURLHandler* handler) { |
| 1382 | // Add the default URL handlers. |
| 1383 | handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride, |
| 1384 | BrowserURLHandler::null_handler()); |
| 1385 | handler->AddHandlerPair(BrowserURLHandler::null_handler(), |
| 1386 | &ExtensionWebUI::HandleChromeURLOverrideReverse); |
| 1387 | |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 1388 | // about: handler. Must come before chrome: handler, since it will |
| 1389 | // rewrite about: urls to chrome: URLs and then expect chrome: to |
| 1390 | // actually handle them. |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1391 | handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 1392 | BrowserURLHandler::null_handler()); |
| 1393 | // chrome: & friends. |
| 1394 | handler->AddHandlerPair(&HandleWebUI, |
| 1395 | BrowserURLHandler::null_handler()); |
| 1396 | } |
| 1397 | |
| 1398 | void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1399 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1400 | rvh->site_instance()->GetProcess()->GetBrowserContext()); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1401 | BrowsingDataRemover* remover = new BrowsingDataRemover(profile, |
| 1402 | BrowsingDataRemover::EVERYTHING, |
| 1403 | base::Time()); |
| 1404 | remover->Remove(BrowsingDataRemover::REMOVE_CACHE); |
| 1405 | // BrowsingDataRemover takes care of deleting itself when done. |
| 1406 | } |
| 1407 | |
| 1408 | void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1409 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1410 | rvh->site_instance()->GetProcess()->GetBrowserContext()); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1411 | BrowsingDataRemover* remover = new BrowsingDataRemover(profile, |
| 1412 | BrowsingDataRemover::EVERYTHING, |
| 1413 | base::Time()); |
[email protected] | dceaa91 | 2011-09-06 17:17:23 | [diff] [blame] | 1414 | int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA; |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 1415 | remover->Remove(remove_mask); |
| 1416 | // BrowsingDataRemover takes care of deleting itself when done. |
| 1417 | } |
| 1418 | |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 1419 | FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
| 1420 | return download_util::GetDefaultDownloadDirectory(); |
| 1421 | } |
| 1422 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 1423 | std::string ChromeContentBrowserClient::GetDefaultDownloadName() { |
| 1424 | return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 1425 | } |
| 1426 | |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1427 | bool ChromeContentBrowserClient::AllowSocketAPI(const GURL& url) { |
| 1428 | return url.is_valid() && |
| 1429 | allowed_socket_origins_.find(url.host()) != allowed_socket_origins_.end(); |
| 1430 | } |
| 1431 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 1432 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1433 | int ChromeContentBrowserClient::GetCrashSignalFD( |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 1434 | const CommandLine& command_line) { |
[email protected] | 6e677a34 | 2012-02-11 01:21:14 | [diff] [blame] | 1435 | #if defined(OS_ANDROID) |
| 1436 | // TODO(carlosvaldivia): Upstream breakpad code for Android and remove this |
| 1437 | // fork. http://crbug.com/113560 |
| 1438 | NOTIMPLEMENTED(); |
| 1439 | #else |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 1440 | if (command_line.HasSwitch(switches::kExtensionProcess)) { |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 1441 | ExtensionCrashHandlerHostLinux* crash_handler = |
| 1442 | ExtensionCrashHandlerHostLinux::GetInstance(); |
| 1443 | return crash_handler->GetDeathSignalSocket(); |
| 1444 | } |
| 1445 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 1446 | std::string process_type = |
| 1447 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 1448 | |
| 1449 | if (process_type == switches::kRendererProcess) |
| 1450 | return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 1451 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1452 | if (process_type == switches::kPluginProcess) |
| 1453 | return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 1454 | |
| 1455 | if (process_type == switches::kPpapiPluginProcess) |
| 1456 | return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
| 1457 | |
| 1458 | if (process_type == switches::kGpuProcess) |
| 1459 | return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket(); |
[email protected] | 6e677a34 | 2012-02-11 01:21:14 | [diff] [blame] | 1460 | #endif // defined(OS_ANDROID) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1461 | |
| 1462 | return -1; |
| 1463 | } |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 1464 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1465 | |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 1466 | #if defined(OS_WIN) |
| 1467 | const wchar_t* ChromeContentBrowserClient::GetResourceDllName() { |
| 1468 | return chrome::kBrowserResourcesDll; |
| 1469 | } |
| 1470 | #endif |
| 1471 | |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 1472 | #if defined(USE_NSS) |
| 1473 | crypto::CryptoModuleBlockingPasswordDelegate* |
| 1474 | ChromeContentBrowserClient::GetCryptoPasswordDelegate( |
| 1475 | const GURL& url) { |
| 1476 | return browser::NewCryptoModuleBlockingDialogDelegate( |
| 1477 | browser::kCryptoModulePasswordKeygen, url.host()); |
| 1478 | } |
| 1479 | #endif |
| 1480 | |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 1481 | } // namespace chrome |