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