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