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