blob: ce0e4b665a21ad16a6428f7ecfa958188bd0e178 [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// 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]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]eabbfb12013-04-05 23:28:3513#include "base/lazy_instance.h"
[email protected]29699c22012-10-03 23:57:3914#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5715#include "base/prefs/pref_service.h"
[email protected]f4ebe772013-02-02 00:21:3916#include "base/strings/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0617#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3018#include "chrome/app/breakpad_mac.h"
[email protected]056efdc2013-04-06 00:14:5319#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]b8148ac2011-07-13 22:03:2520#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3021#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4722#include "chrome/browser/browsing_data/browsing_data_helper.h"
23#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1224#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4125#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4126#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5627#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0528#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4529#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3230#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0831#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3232#include "chrome/browser/download/download_util.h"
[email protected]24665682013-02-25 20:59:3833#include "chrome/browser/extensions/activity_log.h"
[email protected]2b33dcd02012-03-18 01:34:1634#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0635#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0436#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3337#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2638#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0839#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2540#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0641#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5242#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2343#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1244#include "chrome/browser/google/google_util.h"
[email protected]11158e2d2013-02-01 02:31:5645#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0446#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]0c7193742012-11-07 19:05:0347#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2848#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0449#include "chrome/browser/notifications/desktop_notification_service.h"
50#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4251#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5652#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0653#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4154#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5055#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0756#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4157#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1458#include "chrome/browser/printing/printing_message_filter.h"
59#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3260#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0661#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1462#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3863#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4364#include "chrome/browser/search/instant_service.h"
65#include "chrome/browser/search/instant_service_factory.h"
66#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1467#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]970c63e2013-03-07 00:25:3068#include "chrome/browser/signin/signin_manager.h"
69#include "chrome/browser/signin/signin_manager_factory.h"
[email protected]c52b2892012-03-07 11:01:0270#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4671#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5872#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0373#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5274#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4575#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5476#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4377#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]b5d73422012-06-02 23:46:4478#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5079#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]970c63e2013-03-07 00:25:3080#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
[email protected]f3986f82012-01-03 20:00:0681#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1582#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]b80f68432011-05-02 17:22:3083#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0184#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1485#include "chrome/common/chrome_paths.h"
[email protected]f3b357692013-03-22 05:16:1386#include "chrome/common/chrome_process_type.h"
[email protected]b80f68432011-05-02 17:22:3087#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2988#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0489#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3890#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4491#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4392#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]157cc902012-11-02 06:31:5893#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3494#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1295#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3896#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0997#include "chrome/common/url_constants.h"
[email protected]75fee372013-03-06 00:42:4498#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:4399#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30100#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38101#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:31102#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03103#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59104#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36105#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30106#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33107#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05108#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33109#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19110#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10111#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43112#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18113#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23114#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42115#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39116#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23117#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53118#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58119#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34120#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06121#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57122#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38123#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39124#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08125#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36126#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04127#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26128
[email protected]b48c9182011-10-26 18:03:30129#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38130#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18131#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38132#elif defined(OS_MACOSX)
133#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56134#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30135#elif defined(OS_CHROMEOS)
136#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49137#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]931d1042013-04-05 17:50:44138#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26139#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30140#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09141#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38142#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09143#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39144#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30145#elif defined(OS_POSIX)
146#include "chrome/browser/chrome_browser_main_posix.h"
147#endif
148
[email protected]6653c192012-04-10 22:52:44149#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30150#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12151#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43152#endif
[email protected]b80f68432011-05-02 17:22:30153
[email protected]1e87df32012-09-12 04:53:19154#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
155#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
156#endif
157
[email protected]16dc42452013-04-09 04:37:19158#if defined(ENABLE_MESSAGE_CENTER)
159#include "ui/message_center/message_center_util.h"
160#endif
161
[email protected]29699c22012-10-03 23:57:39162#if defined(OS_ANDROID)
163#include "ui/base/ui_base_paths.h"
164#endif
165
[email protected]37a72af2011-06-13 05:42:01166#if defined(USE_NSS)
167#include "chrome/browser/ui/crypto_module_password_dialog.h"
168#endif
169
[email protected]c7abd422012-09-25 00:20:08170using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47171using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03172using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39173using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31174using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59175using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08176using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00177using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11178using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33179using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13180using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06181using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34182using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40183using extensions::Manifest;
[email protected]6717bf272012-05-11 23:31:25184using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39185
[email protected]c5dbef02011-05-13 05:06:09186namespace {
187
[email protected]eabbfb12013-04-05 23:28:35188// Cached version of the locale so we can return the locale on the I/O
189// thread.
190base::LazyInstance<std::string> g_io_thread_application_locale;
191
[email protected]e461da2f2012-02-16 19:06:40192const char* kPredefinedAllowedSocketOrigins[] = {
193 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18194 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45195 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
196 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
197 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
198 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35199 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54200 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
201 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
202 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
203 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
204 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
205 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38206 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58207 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
208 "iabmpiboiopbgfabjmgeedhcmjenhbla" // see crbug.com/165080
[email protected]e461da2f2012-02-16 19:06:40209};
210
[email protected]f8f93eb2012-09-25 03:06:24211// Returns a copy of the given url with its host set to given host and path set
212// to given path. Other parts of the url will be the same.
213GURL ReplaceURLHostAndPath(const GURL& url,
214 const std::string& host,
215 const std::string& path) {
216 url_canon::Replacements<char> replacements;
217 replacements.SetHost(host.c_str(),
218 url_parse::Component(0, host.length()));
219 replacements.SetPath(path.c_str(),
220 url_parse::Component(0, path.length()));
221 return url.ReplaceComponents(replacements);
222}
223
224// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
225GURL AddUberHost(const GURL& url) {
226 const std::string uber_host = chrome::kChromeUIUberHost;
227 const std::string new_path = url.host() + url.path();
228
229 return ReplaceURLHostAndPath(url, uber_host, new_path);
230}
231
[email protected]045bf7c2012-09-28 20:27:36232// If url->host() is "chrome" and url->path() has characters other than the
233// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
234// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24235bool RemoveUberHost(GURL* url) {
236 if (url->host() != chrome::kChromeUIUberHost)
237 return false;
238
[email protected]045bf7c2012-09-28 20:27:36239 if (url->path().empty() || url->path() == "/")
240 return false;
241
[email protected]f8f93eb2012-09-25 03:06:24242 const std::string old_path = url->path();
243
244 const std::string::size_type separator = old_path.find('/', 1);
245 std::string new_host;
246 std::string new_path;
247 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36248 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24249 } else {
250 new_host = old_path.substr(1, separator - 1);
251 new_path = old_path.substr(separator);
252 }
253
254 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
255
256 return true;
257}
258
[email protected]b8148ac2011-07-13 22:03:25259// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42260bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24261 // Do not handle special URLs such as "about:foo"
262 if (!url->host().empty()) {
263 const GURL chrome_url = AddUberHost(*url);
264
265 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
266 // be called.
267 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
268 browser_context, chrome_url))
269 return true;
270 }
271
[email protected]863f70a2012-01-27 02:05:50272 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
273 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25274 return false;
275
[email protected]fe69558d2012-03-12 11:34:49276#if defined(OS_CHROMEOS)
277 // Special case : in ChromeOS in Guest mode bookmarks and history are
278 // disabled for security reasons. New tab page explains the reasons, so
279 // we redirect user to new tab page.
280 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
281 if (url->SchemeIs(chrome::kChromeUIScheme) &&
282 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
283 url->DomainIs(chrome::kChromeUIHistoryHost))) {
284 // Rewrite with new tab URL
285 *url = GURL(chrome::kChromeUINewTabURL);
286 }
287 }
288#endif
289
[email protected]b8148ac2011-07-13 22:03:25290 // Special case the new tab page. In older versions of Chrome, the new tab
291 // page was hosted at chrome-internal:<blah>. This might be in people's saved
292 // sessions or bookmarks, so we say any URL with that scheme triggers the new
293 // tab page.
294 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
295 // Rewrite it with the proper new tab URL.
296 *url = GURL(chrome::kChromeUINewTabURL);
297 }
298
299 return true;
300}
301
[email protected]f8f93eb2012-09-25 03:06:24302// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
303// "chrome://foo/".
304bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
305 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
306 return false;
307
308 return RemoveUberHost(url);
309}
310
[email protected]8d3132f62011-10-12 07:13:42311// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
312// below. Extension, and isolated apps require different privileges to be
313// granted to their RenderProcessHosts. This classification allows us to make
314// sure URLs are served by hosts with the right set of privileges.
315enum RenderProcessHostPrivilege {
316 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45317 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42318 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45319 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42320};
321
322RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
323 const GURL& url,
324 ExtensionService* service) {
325 // Default to a normal renderer cause it is lower privileged. This should only
326 // occur if the URL on a site instance is either malformed, or uninitialized.
327 // If it is malformed, then there is no need for better privileges anyways.
328 // If it is uninitialized, but eventually settles on being an a scheme other
329 // than normal webrenderer, the navigation logic will correct us out of band
330 // anyways.
331 if (!url.is_valid())
332 return PRIV_NORMAL;
333
[email protected]885c0e92012-11-13 20:27:42334 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44335 const Extension* extension =
336 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43337 if (extension &&
338 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42339 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45340 if (extension && extension->is_hosted_app())
341 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42342
343 return PRIV_EXTENSION;
344 }
345
346 return PRIV_NORMAL;
347}
348
349RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30350 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46351 extensions::ProcessMap* process_map,
352 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46353 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30354 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46355 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21356 return PRIV_NORMAL;
357
[email protected]6f371442011-11-09 06:45:46358 for (std::set<std::string>::iterator iter = extension_ids.begin();
359 iter != extension_ids.end(); ++iter) {
360 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43361 if (extension &&
362 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42363 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45364 if (extension && extension->is_hosted_app())
365 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42366 }
367
[email protected]676f6ab2011-10-19 20:23:21368 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42369}
370
[email protected]6786bf402011-12-03 15:19:45371bool CertMatchesFilter(const net::X509Certificate& cert,
372 const base::DictionaryValue& filter) {
373 // TODO(markusheintz): This is the minimal required filter implementation.
374 // Implement a better matcher.
375
376 // An empty filter matches any client certificate since no requirements are
377 // specified at all.
378 if (filter.empty())
379 return true;
380
381 std::string common_name;
382 if (filter.GetString("ISSUER.CN", &common_name) &&
383 (cert.issuer().common_name == common_name)) {
384 return true;
385 }
386 return false;
387}
388
[email protected]f3986f82012-01-03 20:00:06389// Fills |map| with the per-script font prefs under path |map_name|.
390void FillFontFamilyMap(const PrefService* prefs,
391 const char* map_name,
392 WebPreferences::ScriptFontFamilyMap* map) {
393 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
394 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
395 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
396 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23397 if (!font_family.empty())
398 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06399 }
400}
401
[email protected]a1733df2012-06-22 11:24:18402#if defined(OS_POSIX) && !defined(OS_MACOSX)
403int GetCrashSignalFD(const CommandLine& command_line) {
404 if (command_line.HasSwitch(switches::kExtensionProcess)) {
405 ExtensionCrashHandlerHostLinux* crash_handler =
406 ExtensionCrashHandlerHostLinux::GetInstance();
407 return crash_handler->GetDeathSignalSocket();
408 }
409
410 std::string process_type =
411 command_line.GetSwitchValueASCII(switches::kProcessType);
412
413 if (process_type == switches::kRendererProcess)
414 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
415
416 if (process_type == switches::kPluginProcess)
417 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
418
419 if (process_type == switches::kPpapiPluginProcess)
420 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
421
422 if (process_type == switches::kGpuProcess)
423 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
424
425 return -1;
426}
427#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
428
[email protected]7c60f5042013-02-14 03:39:32429// Transforms the input |url| into its "effective URL". The returned URL
[email protected]c5dec6292013-01-25 04:54:52430// facilitates grouping process-per-site. The |url| is transformed, for
431// example, from
432//
433// https://www.google.com/search?espv=1&q=tractors
434//
[email protected]7c60f5042013-02-14 03:39:32435// to the effective URL
[email protected]c5dec6292013-01-25 04:54:52436//
437// chrome-search://www.google.com/search?espv=1&q=tractors
438//
439// Notice the scheme change.
[email protected]7c60f5042013-02-14 03:39:32440//
441// If the input is already an effective URL then that same URL is returned.
442GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
[email protected]165fe422013-03-27 06:34:03443 CHECK(chrome::ShouldAssignURLToInstantRenderer(url, profile))
[email protected]7c60f5042013-02-14 03:39:32444 << "Error granting Instant access.";
[email protected]c5dec6292013-01-25 04:54:52445
446 if (url.SchemeIs(chrome::kChromeSearchScheme))
447 return url;
448
449 GURL effective_url(url);
450
451 // Replace the scheme with "chrome-search:".
452 url_canon::Replacements<char> replacements;
453 std::string search_scheme(chrome::kChromeSearchScheme);
454 replacements.SetScheme(search_scheme.data(),
455 url_parse::Component(0, search_scheme.length()));
456 effective_url = effective_url.ReplaceComponents(replacements);
457 return effective_url;
458}
459
[email protected]970c63e2013-03-07 00:25:30460GURL GetEffectiveURLForSignin(const GURL& url) {
461 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
462
463 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03464 // Copy the path because the argument to SetPathStr must outlive
465 // the Replacements object.
466 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30467 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03468 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30469 effective_url = effective_url.ReplaceComponents(replacements);
470 return effective_url;
471}
472
[email protected]eabbfb12013-04-05 23:28:35473void SetApplicationLocaleOnIOThread(const std::string& locale) {
474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
475 g_io_thread_application_locale.Get() = locale;
476}
477
[email protected]9dbfff12011-07-01 19:37:07478} // namespace
[email protected]c5dbef02011-05-13 05:06:09479
[email protected]d977f9c2011-03-14 16:10:26480namespace chrome {
481
[email protected]e461da2f2012-02-16 19:06:40482ChromeContentBrowserClient::ChromeContentBrowserClient() {
483 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
484 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40485}
486
487ChromeContentBrowserClient::~ChromeContentBrowserClient() {
488}
489
[email protected]bca18382012-06-25 19:15:23490// static
[email protected]c753f142013-02-10 13:14:04491void ChromeContentBrowserClient::RegisterUserPrefs(
492 PrefRegistrySyncable* registry) {
493 registry->RegisterBooleanPref(prefs::kDisable3DAPIs,
494 false,
495 PrefRegistrySyncable::UNSYNCABLE_PREF);
496 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
497 true,
498 PrefRegistrySyncable::UNSYNCABLE_PREF);
499 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo,
500 false,
501 PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23502}
503
[email protected]eabbfb12013-04-05 23:28:35504// static
505void ChromeContentBrowserClient::SetApplicationLocale(
506 const std::string& locale) {
507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
508
509 // This object is guaranteed to outlive all threads so we don't have to
510 // worry about the lack of refcounting and can just post as Unretained.
511 //
512 // The common case is that this function is called early in Chrome startup
513 // before any threads are created (it will also be called later if the user
514 // changes the pref). In this case, there will be no threads created and
515 // posting will fail. When there are no threads, we can just set the string
516 // without worrying about threadsafety.
517 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
518 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
519 g_io_thread_application_locale.Get() = locale;
520 }
521}
522
[email protected]50462bf02011-11-21 19:13:31523content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
524 const content::MainFunctionParams& parameters) {
525 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30526 // Construct the Main browser parts based on the OS type.
527#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31528 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04529#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31530 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30531#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22532 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26533#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31534 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14535#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09536 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30537#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31538 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04539#else
[email protected]b48c9182011-10-26 18:03:30540 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31541 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30542#endif
543
[email protected]c7480942011-11-08 19:18:27544 // Construct additional browser parts. Stages are called in the order in
545 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22546#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41547 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04548#endif
[email protected]c7480942011-11-08 19:18:27549
550#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41551 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27552#endif
553
[email protected]dc04be7c2012-03-15 23:57:49554#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41555 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49556#endif
557
[email protected]e050ef142012-03-21 01:04:24558#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41559 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24560#endif
561
[email protected]95132f52013-04-12 02:19:04562 chrome::AddMetricsExtraParts(main_parts);
563
[email protected]50462bf02011-11-21 19:13:31564 return main_parts;
[email protected]f967b722011-09-07 00:58:04565}
566
[email protected]e94bbcb2012-09-07 05:33:57567std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19568 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57569 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53570 std::string partition_id;
571
572 // The partition ID for webview guest processes is the string value of its
573 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
574 if (site.SchemeIs(chrome::kGuestScheme))
575 partition_id = site.spec();
576
[email protected]056efdc2013-04-06 00:14:53577 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53578 return partition_id;
579}
580
581bool ChromeContentBrowserClient::IsValidStoragePartitionId(
582 content::BrowserContext* browser_context,
583 const std::string& partition_id) {
584 // The default ID is empty and is always valid.
585 if (partition_id.empty())
586 return true;
587
588 return GURL(partition_id).is_valid();
589}
590
591void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
592 content::BrowserContext* browser_context,
593 const GURL& site,
[email protected]14acc642012-11-17 12:20:10594 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53595 std::string* partition_domain,
596 std::string* partition_name,
597 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10598 // Default to the browser-wide storage partition and override based on |site|
599 // below.
600 partition_domain->clear();
601 partition_name->clear();
602 *in_memory = false;
603
[email protected]1bc28312012-11-08 08:31:53604 // For the webview tag, we create special guest processes, which host the
605 // tag content separately from the main application that embeds the tag.
606 // A webview tag can specify both the partition name and whether the storage
607 // for that partition should be persisted. Each tag gets a SiteInstance with
608 // a specially formatted URL, based on the application it is hosted by and
609 // the partition requested by it. The format for that URL is:
610 // chrome-guest://partition_domain/persist?partition_name
611 if (site.SchemeIs(chrome::kGuestScheme)) {
612 // Since guest URLs are only used for packaged apps, there must be an app
613 // id in the URL.
614 CHECK(site.has_host());
615 *partition_domain = site.host();
616 // Since persistence is optional, the path must either be empty or the
617 // literal string.
618 *in_memory = (site.path() != "/persist");
619 // The partition name is user supplied value, which we have encoded when the
620 // URL was created, so it needs to be decoded.
621 *partition_name = net::UnescapeURLComponent(site.query(),
622 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10623 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
624 // If |can_be_default| is false, the caller is stating that the |site|
625 // should be parsed as if it had isolated storage. In particular it is
626 // important to NOT check ExtensionService for the is_storage_isolated()
627 // attribute because this code path is run during Extension uninstall
628 // to do cleanup after the Extension has already been unloaded from the
629 // ExtensionService.
630 bool is_isolated = !can_be_default;
631 if (can_be_default) {
632 const Extension* extension = NULL;
633 Profile* profile = Profile::FromBrowserContext(browser_context);
634 ExtensionService* extension_service =
635 extensions::ExtensionSystem::Get(profile)->extension_service();
636 if (extension_service) {
637 extension = extension_service->extensions()->
638 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43639 if (extension &&
640 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10641 is_isolated = true;
642 }
643 }
644 }
[email protected]1bc28312012-11-08 08:31:53645
[email protected]14acc642012-11-17 12:20:10646 if (is_isolated) {
647 CHECK(site.has_host());
648 // For extensions with isolated storage, the the host of the |site| is
649 // the |partition_domain|. The |in_memory| and |partition_name| are only
650 // used in guest schemes so they are cleared here.
651 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53652 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10653 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53654 }
[email protected]d1198fd2012-08-13 22:50:19655 }
656
[email protected]14acc642012-11-17 12:20:10657 // Assert that if |can_be_default| is false, the code above must have found a
658 // non-default partition. If this fails, the caller has a serious logic
659 // error about which StoragePartition they expect to be in and it is not
660 // safe to continue.
661 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44662}
663
[email protected]38b098f2012-03-14 21:11:57664content::WebContentsViewDelegate*
665 ChromeContentBrowserClient::GetWebContentsViewDelegate(
666 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27667 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32668}
669
[email protected]24665682013-02-25 20:59:38670// Check if the extension activity log is enabled for the profile.
671static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
672 extensions::ActivityLog* activity_log =
673 extensions::ActivityLog::GetInstance(profile);
674 return activity_log->IsLogEnabled();
675}
676
[email protected]44703cc72013-01-24 04:56:06677void ChromeContentBrowserClient::GuestWebContentsCreated(
678 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
679 Profile* profile = Profile::FromBrowserContext(
680 embedder_web_contents->GetBrowserContext());
681 ExtensionService* service =
682 extensions::ExtensionSystem::Get(profile)->extension_service();
683 if (!service)
684 return;
685 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
686 const Extension* extension = service->extensions()->
687 GetExtensionOrAppByURL(ExtensionURLInfo(url));
688 if (!extension)
689 return;
690 std::vector<ExtensionMsg_Loaded_Params> extensions;
691 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
692 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
693}
694
[email protected]f3b1a082011-11-18 00:34:30695void ChromeContentBrowserClient::RenderProcessHostCreated(
696 content::RenderProcessHost* host) {
697 int id = host->GetID();
698 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41699 net::URLRequestContextGetter* context =
700 profile->GetRequestContextForRenderProcess(id);
701
[email protected]f3b1a082011-11-18 00:34:30702 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41703 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55704#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30705 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55706#endif
[email protected]658677f2012-06-09 06:04:02707#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08708 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03709#endif
[email protected]f3b1a082011-11-18 00:34:30710 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02711 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30712 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56713#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21714 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56715#endif
[email protected]43535512013-02-20 20:41:41716 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
717 id, profile, context));
[email protected]2736c032012-05-11 18:06:07718 host->GetChannel()->AddFilter(
719 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38720
[email protected]2ccf45c2011-08-19 23:35:50721 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
722 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07723
[email protected]24665682013-02-25 20:59:38724 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
725 IsExtensionActivityLogEnabledForProfile(profile)));
726
[email protected]39a5b532011-10-22 01:47:07727 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56728
729 RendererContentSettingRules rules;
730 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
731 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14732}
733
[email protected]3d7474ff2011-07-27 17:47:37734GURL ChromeContentBrowserClient::GetEffectiveURL(
735 content::BrowserContext* browser_context, const GURL& url) {
736 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52737 if (!profile)
738 return url;
739
[email protected]7c60f5042013-02-14 03:39:32740 // If the input |url| should be assigned to the Instant renderer, make its
741 // effective URL distinct from other URLs on the search provider's domain.
[email protected]165fe422013-03-27 06:34:03742 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
[email protected]7c60f5042013-02-14 03:39:32743 return GetEffectiveURLForInstant(url, profile);
[email protected]c5dec6292013-01-25 04:54:52744
[email protected]970c63e2013-03-07 00:25:30745 // If the input |url| should be assigned to the Signin renderer, make its
746 // effective URL distinct from other URLs on the signin service's domain.
747 // Note that the signin renderer will be allowed to sign the user in to
748 // Chrome.
749 if (SigninManager::IsWebBasedSigninFlowURL(url))
750 return GetEffectiveURLForSignin(url);
751
[email protected]c5dec6292013-01-25 04:54:52752 // If the input |url| is part of an installed app, the effective URL is an
753 // extension URL with the ID of that extension as the host. This has the
754 // effect of grouping apps together in a common SiteInstance.
755 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13756 extensions::ExtensionSystem::Get(profile)->extension_service();
757 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08758 return url;
759
[email protected]06bdd2b2012-11-30 18:47:13760 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44761 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08762 if (!extension)
763 return url;
764
[email protected]15877ca2011-11-18 22:40:52765 // Bookmark apps do not use the hosted app process model, and should be
766 // treated as normal URLs.
767 if (extension->from_bookmark())
768 return url;
769
[email protected]36fb2c7c2011-04-04 15:49:08770 // If the URL is part of an extension's web extent, convert it to an
771 // extension URL.
772 return extension->GetResourceURL(url.path());
773}
774
[email protected]056ad2a2011-07-12 02:13:55775bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37776 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52777 // Non-extension, non-Instant URLs should generally use
778 // process-per-site-instance. Because we expect to use the effective URL,
779 // URLs for hosted apps (apart from bookmark apps) should have an extension
780 // scheme by now.
781
782 Profile* profile = Profile::FromBrowserContext(browser_context);
783 if (!profile)
784 return false;
785
[email protected]165fe422013-03-27 06:34:03786 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52787 return true;
788
[email protected]970c63e2013-03-07 00:25:30789 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
790 return true;
791
[email protected]885c0e92012-11-13 20:27:42792 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55793 return false;
794
[email protected]c5dec6292013-01-25 04:54:52795 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13796 extensions::ExtensionSystem::Get(profile)->extension_service();
797 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55798 return false;
799
[email protected]06bdd2b2012-11-30 18:47:13800 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44801 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55802 if (!extension)
803 return false;
804
805 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53806 // permission, or that does not allow JavaScript access to the background
807 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55808 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40809 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06810 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29811 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53812 return false;
813 }
814 }
[email protected]056ad2a2011-07-12 02:13:55815
[email protected]7b54ca02012-03-02 18:06:53816 // Hosted apps that have script access to their background page must use
817 // process per site, since all instances can make synchronous calls to the
818 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55819 return true;
820}
821
[email protected]672c8c12013-03-07 12:30:06822// These are treated as WebUI schemes but do not get WebUI bindings.
823std::vector<std::string>
824ChromeContentBrowserClient::GetAdditionalWebUISchemes() {
825 std::vector<std::string> additional_schemes;
826 additional_schemes.push_back(chrome::kChromeSearchScheme);
827 return additional_schemes;
828}
829
[email protected]6bd30072013-02-08 18:17:11830net::URLRequestContextGetter*
831ChromeContentBrowserClient::CreateRequestContext(
832 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06833 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11834 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06835 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11836}
837
838net::URLRequestContextGetter*
839ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
840 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40841 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11842 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06843 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11844 Profile* profile = Profile::FromBrowserContext(browser_context);
845 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06846 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11847}
848
[email protected]46fb9442011-12-09 17:57:47849bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
850 return ProfileIOData::IsHandledURL(url);
851}
852
[email protected]2a5221b2011-09-27 23:07:31853bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30854 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31855 const GURL& site_url) {
856 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30857 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52858 // This may be NULL during tests. In that case, just assume any site can
859 // share any host.
860 if (!profile)
861 return true;
862
[email protected]d43f99fe2013-04-03 00:20:14863 // Instant URLs should only be in the instant process and instant process
864 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52865 InstantService* instant_service =
866 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14867 if (instant_service) {
868 bool is_instant_process = instant_service->IsInstantProcess(
869 process_host->GetID());
870 bool should_be_in_instant_process =
871 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
872 if (is_instant_process || should_be_in_instant_process)
873 return is_instant_process && should_be_in_instant_process;
874 }
[email protected]c5dec6292013-01-25 04:54:52875
[email protected]970c63e2013-03-07 00:25:30876 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
877 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
878 return SigninManager::IsWebBasedSigninFlowURL(site_url);
879
[email protected]06bdd2b2012-11-30 18:47:13880 ExtensionService* service =
881 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46882 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31883
[email protected]ffa97602011-11-17 17:55:52884 // Don't allow the Task Manager to share a process with anything else.
885 // Otherwise it can affect the renderers it is observing.
886 // Note: we could create another RenderProcessHostPrivilege bucket for
887 // this to allow multiple chrome://tasks instances to share, but that's
888 // a very unlikely case without serious consequences.
889 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
890 return false;
891
[email protected]8d3132f62011-10-12 07:13:42892 // These may be NULL during tests. In that case, just assume any site can
893 // share any host.
[email protected]6f371442011-11-09 06:45:46894 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31895 return true;
896
[email protected]eec0b33c2011-12-05 22:09:45897 // Otherwise, just make sure the process privilege matches the privilege
898 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57899 RenderProcessHostPrivilege privilege_required =
900 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45901 return GetProcessPrivilege(process_host, process_map, service) ==
902 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31903}
904
[email protected]76411f412012-02-22 18:56:06905// This function is trying to limit the amount of processes used by extensions
906// with background pages. It uses a globally set percentage of processes to
907// run such extensions and if the limit is exceeded, it returns true, to
908// indicate to the content module to group extensions together.
909bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
910 content::BrowserContext* browser_context, const GURL& url) {
911 // It has to be a valid URL for us to check for an extension.
912 if (!url.is_valid())
913 return false;
914
915 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19916 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13917 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06918 if (!service)
919 return false;
920
921 // We have to have a valid extension with background page to proceed.
922 const Extension* extension =
923 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
924 if (!extension)
925 return false;
[email protected]9367eabc2013-03-01 01:29:29926 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06927 return false;
928
929 std::set<int> process_ids;
930 size_t max_process_count =
931 content::RenderProcessHost::GetMaxRendererProcessCount();
932
933 // Go through all profiles to ensure we have total count of extension
934 // processes containing background pages, otherwise one profile can
935 // starve the other.
936 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
937 GetLoadedProfiles();
938 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03939 ExtensionProcessManager* epm =
940 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32941 for (ExtensionProcessManager::const_iterator iter =
942 epm->background_hosts().begin();
943 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13944 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32945 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06946 }
947 }
948
949 if (process_ids.size() >
950 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
951 return true;
952 }
953
954 return false;
955}
956
[email protected]6f371442011-11-09 06:45:46957void ChromeContentBrowserClient::SiteInstanceGotProcess(
958 SiteInstance* site_instance) {
959 CHECK(site_instance->HasProcess());
960
961 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02962 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52963 if (!profile)
964 return;
965
966 // Remember the ID of the Instant process to signal the renderer process
967 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:03968 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:32969 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:52970 InstantService* instant_service =
971 InstantServiceFactory::GetForProfile(profile);
972 if (instant_service)
973 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
974 }
975
[email protected]970c63e2013-03-07 00:25:30976 // We only expect there to be one signin process as we use process-per-site
977 // for signin URLs. The signin process will be cleared from SigninManager
978 // when the renderer is destroyed.
979 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
980 SigninManager* signin_manager =
981 SigninManagerFactory::GetForProfile(profile);
982 if (signin_manager)
983 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
984 }
985
[email protected]06bdd2b2012-11-30 18:47:13986 ExtensionService* service =
987 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46988 if (!service)
989 return;
990
991 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44992 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59993 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46994 if (!extension)
995 return;
996
[email protected]6bc04fd82011-12-04 02:29:35997 service->process_map()->Insert(extension->id(),
998 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33999 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461000 BrowserThread::PostTask(
1001 BrowserThread::IO, FROM_HERE,
1002 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591003 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461004 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351005 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331006 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461007}
1008
1009void ChromeContentBrowserClient::SiteInstanceDeleting(
1010 SiteInstance* site_instance) {
1011 if (!site_instance->HasProcess())
1012 return;
1013
1014 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021015 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131016 ExtensionService* service =
1017 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461018 if (!service)
1019 return;
1020
1021 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441022 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591023 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461024 if (!extension)
1025 return;
1026
[email protected]6bc04fd82011-12-04 02:29:351027 service->process_map()->Remove(extension->id(),
1028 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331029 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461030 BrowserThread::PostTask(
1031 BrowserThread::IO, FROM_HERE,
1032 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591033 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461034 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351035 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331036 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461037}
1038
[email protected]f05763972012-06-06 18:17:261039bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141040 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081041 const GURL& current_url,
1042 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261043 if (current_url.is_empty()) {
1044 // Always choose a new process when navigating to extension URLs. The
1045 // process grouping logic will combine all of a given extension's pages
1046 // into the same process.
[email protected]885c0e92012-11-13 20:27:421047 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261048 return true;
[email protected]e3daf3c2011-10-05 21:17:081049
[email protected]f05763972012-06-06 18:17:261050 return false;
1051 }
1052
1053 // Also, we must switch if one is an extension and the other is not the exact
1054 // same extension.
[email protected]885c0e92012-11-13 20:27:421055 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1056 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261057 if (current_url.GetOrigin() != new_url.GetOrigin())
1058 return true;
1059 }
1060
[email protected]e9841fbd2013-02-22 23:12:141061 // The checks below only matter if we can retrieve which extensions are
1062 // installed.
1063 Profile* profile =
1064 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1065 ExtensionService* service =
1066 extensions::ExtensionSystem::Get(profile)->extension_service();
1067 if (!service)
1068 return false;
1069
1070 // We must swap if the URL is for an extension and we are not using an
1071 // extension process.
1072 const Extension* new_extension =
1073 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1074 // Ignore all hosted apps except the Chrome Web Store, since they do not
1075 // require their own BrowsingInstance (e.g., postMessage is ok).
1076 if (new_extension &&
1077 new_extension->is_hosted_app() &&
1078 new_extension->id() != extension_misc::kWebStoreAppId)
1079 new_extension = NULL;
1080 if (new_extension &&
1081 site_instance->HasProcess() &&
1082 !service->process_map()->Contains(new_extension->id(),
1083 site_instance->GetProcess()->GetID()))
1084 return true;
1085
[email protected]f05763972012-06-06 18:17:261086 return false;
[email protected]e3daf3c2011-10-05 21:17:081087}
1088
[email protected]395045c2012-05-22 15:04:381089bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1090 content::ResourceContext* resource_context, const GURL& current_url,
1091 const GURL& new_url) {
1092 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1093 return extensions::CrossesExtensionProcessBoundary(
1094 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171095 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381096}
1097
[email protected]763ec4ca2011-04-29 15:48:121098std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1099 const std::string& alias_name) {
1100 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1101}
1102
[email protected]b80f68432011-05-02 17:22:301103void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1104 CommandLine* command_line, int child_process_id) {
1105#if defined(USE_LINUX_BREAKPAD)
1106 if (IsCrashReporterEnabled()) {
1107 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1108 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1109 }
1110#elif defined(OS_MACOSX)
1111 if (IsCrashReporterEnabled()) {
1112 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1113 child_process_logging::GetClientId());
1114 }
1115#endif // OS_MACOSX
1116
[email protected]f1933792011-06-14 00:49:341117 if (logging::DialogsAreSuppressed())
1118 command_line->AppendSwitch(switches::kNoErrorDialogs);
1119
[email protected]b80f68432011-05-02 17:22:301120 std::string process_type =
1121 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171122 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321123
1124 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1125 command_line->AppendSwitch(switches::kChromeFrame);
1126
[email protected]718eab62011-10-05 21:16:521127 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451128 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301129 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1130 if (!user_data_dir.empty())
1131 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1132#if defined(OS_CHROMEOS)
1133 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441134 browser_command_line.GetSwitchValueASCII(
1135 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301136 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441137 command_line->AppendSwitchASCII(
1138 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301139#endif
1140
[email protected]f3b1a082011-11-18 00:34:301141 content::RenderProcessHost* process =
1142 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371143 if (process) {
1144 Profile* profile = Profile::FromBrowserContext(
1145 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131146 ExtensionService* extension_service =
1147 extensions::ExtensionSystem::Get(profile)->extension_service();
1148 if (extension_service) {
1149 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001150 if (process_map && process_map->Contains(process->GetID()))
1151 command_line->AppendSwitch(switches::kExtensionProcess);
1152 }
[email protected]b80f68432011-05-02 17:22:301153
[email protected]a8d851f82011-12-21 00:32:371154 PrefService* prefs = profile->GetPrefs();
1155 // Currently this pref is only registered if applied via a policy.
1156 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1157 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1158 // Turn this policy into a command line switch.
1159 command_line->AppendSwitch(switches::kDisable3DAPIs);
1160 }
[email protected]718eab62011-10-05 21:16:521161
[email protected]a8d851f82011-12-21 00:32:371162 // Disable client-side phishing detection in the renderer if it is
1163 // disabled in the Profile preferences or the browser process.
1164 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1165 !g_browser_process->safe_browsing_detection_service()) {
1166 command_line->AppendSwitch(
1167 switches::kDisableClientSidePhishingDetection);
1168 }
[email protected]0045b0f42012-07-26 11:52:081169
1170 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211171 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521172
1173 InstantService* instant_service =
1174 InstantServiceFactory::GetForProfile(profile);
1175 if (instant_service &&
1176 instant_service->IsInstantProcess(process->GetID()))
1177 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301178
1179 SigninManager* signin_manager =
1180 SigninManagerFactory::GetForProfile(profile);
1181 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1182 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]47c7ec82012-01-18 03:29:211183 }
[email protected]4287a3d2011-06-13 23:56:511184
[email protected]87552982012-11-02 17:21:401185 if (content::IsThreadedCompositingEnabled())
1186 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1187
[email protected]16dc42452013-04-09 04:37:191188#if defined(ENABLE_MESSAGE_CENTER)
1189 if (message_center::IsRichNotificationEnabled())
1190 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
1191#endif
1192
[email protected]47c7ec82012-01-18 03:29:211193 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511194 static const char* const kSwitchNames[] = {
[email protected]e217c5632013-04-12 19:11:481195 autofill::switches::kEnableExperimentalFormFilling,
[email protected]8f96cef2013-04-01 16:51:131196 switches::kAllowRequestOSFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511197 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481198 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511199 switches::kAllowScriptingGallery,
1200 switches::kAppsCheckoutURL,
1201 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311202 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511203 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501204 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531205 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111206 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511207 switches::kDumpHistogramsOnExit,
[email protected]e9cddd52013-03-23 17:37:531208 switches::kEnableAdview,
1209 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211210 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511211 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511212 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511213 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511214 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451215 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481216 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051217 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511218 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291219 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511220 switches::kMemoryProfiling,
1221 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371222 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371223 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511224 switches::kPpapiFlashArgs,
1225 switches::kPpapiFlashInProcess,
1226 switches::kPpapiFlashPath,
1227 switches::kPpapiFlashVersion,
1228 switches::kProfilingAtStart,
1229 switches::kProfilingFile,
1230 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371231 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511232 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291233 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381234 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511235 };
1236
1237 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1238 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171239 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381240 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351241 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381242 switches::kEnableExperimentalExtensionApis,
1243 switches::kWhitelistedExtensionID,
1244 };
1245
1246 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1247 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511248 } else if (process_type == switches::kPluginProcess) {
1249 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441250#if defined(OS_CHROMEOS)
1251 chromeos::switches::kLoginProfile,
1252#endif
[email protected]4287a3d2011-06-13 23:56:511253 switches::kMemoryProfiling,
1254 switches::kSilentDumpOnDCHECK,
1255 switches::kUserDataDir,
1256 };
1257
1258 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1259 arraysize(kSwitchNames));
1260 } else if (process_type == switches::kZygoteProcess) {
1261 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511262 switches::kUserDataDir, // Make logs go to the right file.
1263 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501264 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511265 switches::kPpapiFlashInProcess,
1266 switches::kPpapiFlashPath,
1267 switches::kPpapiFlashVersion,
1268 };
1269
1270 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1271 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111272 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001273 base::FilePath user_data_dir =
1274 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1275 if (!user_data_dir.empty())
1276 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111277 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1278 // because GPU is expected to be unreliable.
1279 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1280 !command_line->HasSwitch(switches::kDisableBreakpad))
1281 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301282 }
[email protected]6f08af82011-09-15 01:19:031283
1284 // The command line switch kEnableBenchmarking needs to be specified along
1285 // with the kEnableStatsTable switch to ensure that the stats table global
1286 // is initialized correctly.
1287 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1288 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301289}
1290
1291std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431292 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351293 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301294 return g_browser_process->GetApplicationLocale();
1295}
1296
[email protected]597a867b2011-11-18 18:31:201297std::string ChromeContentBrowserClient::GetAcceptLangs(
1298 content::BrowserContext* context) {
1299 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371300 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081301}
1302
[email protected]9ec0f452012-05-31 15:58:531303gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221304 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531305 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081306}
1307
[email protected]a2176792011-05-08 19:30:491308bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091309 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191310 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201311 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201313 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051314 return io_data->GetCookieSettings()->
1315 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491316}
1317
[email protected]ed24fad2011-05-10 22:44:011318bool ChromeContentBrowserClient::AllowGetCookie(
1319 const GURL& url,
1320 const GURL& first_party,
1321 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201322 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011323 int render_process_id,
1324 int render_view_id) {
1325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201326 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051327 bool allow = io_data->GetCookieSettings()->
1328 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011329
[email protected]8093a542011-05-13 07:29:321330 BrowserThread::PostTask(
1331 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031332 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431333 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011334 return allow;
1335}
1336
1337bool ChromeContentBrowserClient::AllowSetCookie(
1338 const GURL& url,
1339 const GURL& first_party,
1340 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201341 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011342 int render_process_id,
1343 int render_view_id,
1344 net::CookieOptions* options) {
1345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201346 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051347 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1348 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1349
[email protected]8093a542011-05-13 07:29:321350 BrowserThread::PostTask(
1351 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031352 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431353 render_view_id, url, first_party, cookie_line, *options,
1354 !allow));
[email protected]ed24fad2011-05-10 22:44:011355 return allow;
1356}
1357
[email protected]d5a19162011-06-30 18:51:541358bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201359 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201361 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431362 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1363 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261364
[email protected]bf510ed2012-06-05 08:31:431365 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1366 // Could we even support per-origin settings?
1367 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541368}
1369
[email protected]5c5a88e2011-11-12 00:45:351370bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351371 const GURL& url,
1372 const string16& name,
1373 const string16& display_name,
1374 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201375 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481376 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201378 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351379 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1380 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1381
[email protected]62151052012-02-01 18:40:481382 // Record access to database for potential display in UI.
1383 std::vector<std::pair<int, int> >::const_iterator i;
1384 for (i = render_views.begin(); i != render_views.end(); ++i) {
1385 BrowserThread::PostTask(
1386 BrowserThread::UI, FROM_HERE,
1387 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1388 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351389 }
1390
1391 return allow;
1392}
1393
1394bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351395 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201396 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481397 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201399 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351400 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1401 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1402
[email protected]62151052012-02-01 18:40:481403 // Record access to file system for potential display in UI.
1404 std::vector<std::pair<int, int> >::const_iterator i;
1405 for (i = render_views.begin(); i != render_views.end(); ++i) {
1406 BrowserThread::PostTask(
1407 BrowserThread::UI, FROM_HERE,
1408 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1409 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351410 }
1411
1412 return allow;
1413}
1414
[email protected]7c5ff9a2012-03-02 07:42:491415bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1416 const GURL& url,
1417 const string16& name,
1418 content::ResourceContext* context,
1419 const std::vector<std::pair<int, int> >& render_views) {
1420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1421 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1422 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1423 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1424
1425 // Record access to IndexedDB for potential display in UI.
1426 std::vector<std::pair<int, int> >::const_iterator i;
1427 for (i = render_views.begin(); i != render_views.end(); ++i) {
1428 BrowserThread::PostTask(
1429 BrowserThread::UI, FROM_HERE,
1430 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1431 i->first, i->second, url, name, !allow));
1432 }
1433
1434 return allow;
1435}
1436
[email protected]6133f922011-07-01 21:34:341437net::URLRequestContext*
1438ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201439 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421441 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201442 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341443 return io_data->extensions_request_context();
1444 }
1445
1446 return NULL;
1447}
1448
[email protected]317f96c92011-05-31 06:53:411449QuotaPermissionContext*
1450ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1451 return new ChromeQuotaPermissionContext();
1452}
1453
[email protected]848dd042011-06-04 18:24:031454void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171455 int render_process_id,
1456 int render_view_id,
1457 int cert_error,
1458 const net::SSLInfo& ssl_info,
1459 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021460 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031461 bool overridable,
[email protected]d9be47702012-05-16 03:41:221462 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171463 const base::Callback<void(bool)>& callback,
1464 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021465 if (resource_type != ResourceType::MAIN_FRAME) {
1466 // A sub-resource has a certificate error. The user doesn't really
1467 // have a context for making the right decision, so block the
1468 // request hard, without an info bar to allow showing the insecure
1469 // content.
1470 *cancel_request = true;
1471 return;
1472 }
1473
[email protected]f9034cf2011-07-21 12:43:411474 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131475 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171476 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411477 if (!tab) {
1478 NOTREACHED();
1479 return;
1480 }
1481 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501482 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301483 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011484 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1485 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411486 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171487 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411488 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171489 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411490 return;
1491 }
1492 }
1493
[email protected]1e87df32012-09-12 04:53:191494#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231495 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1496 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1497 if (captive_portal_tab_helper)
1498 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191499#endif
1500
[email protected]f9034cf2011-07-21 12:43:411501 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221502 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1503 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031504}
1505
[email protected]c99c442e2011-08-24 11:37:301506void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451507 int render_process_id,
1508 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401509 const net::HttpNetworkSession* network_session,
1510 net::SSLCertRequestInfo* cert_request_info,
1511 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131512 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451513 render_process_id, render_view_id);
1514 if (!tab) {
1515 NOTREACHED();
1516 return;
1517 }
1518
[email protected]6786bf402011-12-03 15:19:451519 GURL requesting_url("https://" + cert_request_info->host_and_port);
1520 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1521 << cert_request_info->host_and_port;
1522
[email protected]627e0512011-12-21 22:55:301523 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451524 scoped_ptr<Value> filter(
1525 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1526 requesting_url,
1527 requesting_url,
1528 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1529 std::string(), NULL));
1530
1531 if (filter.get()) {
1532 // Try to automatically select a client certificate.
1533 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1534 DictionaryValue* filter_dict =
1535 static_cast<DictionaryValue*>(filter.get());
1536
1537 const std::vector<scoped_refptr<net::X509Certificate> >&
1538 all_client_certs = cert_request_info->client_certs;
1539 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1540 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1541 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401542 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451543 return;
1544 }
1545 }
1546 } else {
1547 NOTREACHED();
1548 }
1549 }
1550
[email protected]11feec322012-09-18 03:58:521551 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1552 if (!ssl_tab_helper) {
1553 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451554 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141555 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401556 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451557 return;
1558 }
[email protected]11feec322012-09-18 03:58:521559 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401560 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451561}
1562
[email protected]3b455502012-12-11 18:22:581563void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451564 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581565 net::CertificateMimeType cert_type,
1566 const void* cert_data,
1567 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451568 int render_process_id,
1569 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581570 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1571 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451572}
1573
[email protected]dc73a7b2012-03-25 15:27:181574content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561575 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181576}
1577
[email protected]941623e2011-06-07 23:06:041578void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1579 const GURL& source_origin,
1580 int callback_context,
1581 int render_process_id,
1582 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111583#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1585 WebContents* contents =
1586 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1587 if (!contents) {
[email protected]941623e2011-06-07 23:06:041588 NOTREACHED();
1589 return;
1590 }
1591
[email protected]d0d9c3ee2012-06-19 03:07:021592 // Skip showing the infobar if the request comes from an extension, and that
1593 // extension has the 'notify' permission. (If the extension does not have the
1594 // permission, the user will still be prompted.)
1595 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131596 ExtensionService* service =
1597 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]d0d9c3ee2012-06-19 03:07:021598 const Extension* extension = !service ? NULL :
1599 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1600 source_origin));
[email protected]eb4832a2012-12-08 01:57:521601 RenderViewHost* rvh =
1602 RenderViewHost::FromID(render_process_id, render_view_id);
1603 if (IsExtensionWithPermissionOrSuggestInConsole(
1604 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021605 if (rvh)
1606 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1607 return;
1608 }
1609
1610 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371611 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021612 notifications->RequestPermission(source_origin, render_process_id,
1613 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111614#else
1615 NOTIMPLEMENTED();
1616#endif
[email protected]941623e2011-06-07 23:06:041617}
1618
1619WebKit::WebNotificationPresenter::Permission
1620 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021621 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201622 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021623 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111624#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201626 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021627 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1628 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061629 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041630 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041631
1632 // Fall back to the regular notification preferences, which works on an
1633 // origin basis.
1634 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371635 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041636 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111637#else
1638 return WebKit::WebNotificationPresenter::PermissionAllowed;
1639#endif
[email protected]941623e2011-06-07 23:06:041640}
1641
1642void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171643 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041644 int render_process_id,
1645 int render_view_id,
1646 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111647#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041648 RenderViewHost* rvh = RenderViewHost::FromID(
1649 render_process_id, render_view_id);
1650 if (!rvh) {
1651 NOTREACHED();
1652 return;
1653 }
1654
[email protected]9f76c1e2012-03-05 15:15:581655 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301656 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041657 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371658 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041659 service->ShowDesktopNotification(
1660 params, render_process_id, render_view_id,
1661 worker ? DesktopNotificationService::WorkerNotification :
1662 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111663#else
1664 NOTIMPLEMENTED();
1665#endif
[email protected]941623e2011-06-07 23:06:041666}
1667
1668void ChromeContentBrowserClient::CancelDesktopNotification(
1669 int render_process_id,
1670 int render_view_id,
1671 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111672#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041673 RenderViewHost* rvh = RenderViewHost::FromID(
1674 render_process_id, render_view_id);
1675 if (!rvh) {
1676 NOTREACHED();
1677 return;
1678 }
1679
[email protected]9f76c1e2012-03-05 15:15:581680 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301681 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041682 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371683 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041684 service->CancelDesktopNotification(
1685 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111686#else
1687 NOTIMPLEMENTED();
1688#endif
[email protected]941623e2011-06-07 23:06:041689}
1690
[email protected]9f3fba52011-06-08 20:37:191691bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351692 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021693 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191694 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201695 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011696 int render_process_id,
1697 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011699
1700 *no_javascript_access = false;
1701
[email protected]9f3fba52011-06-08 20:37:191702 // If the opener is trying to create a background window but doesn't have
1703 // the appropriate permission, fail the attempt.
1704 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201705 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531706 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1707
[email protected]03b6d552012-03-29 04:03:011708 if (!map->SecurityOriginHasAPIPermission(
1709 source_origin,
1710 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061711 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011712 return false;
1713 }
1714
[email protected]7b54ca02012-03-02 18:06:531715 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1716 // return a recently installed Extension even if this CanCreateWindow call
1717 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011718 // because the permission check above would have caused an early return
1719 // already. We must use the full URL to find hosted apps, though, and not
1720 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531721 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351722 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291723 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011724 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191725 }
[email protected]056efdc2013-04-06 00:14:531726
1727 // No new browser window (popup or tab) in app mode.
1728 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1729 chrome::IsRunningInForcedAppMode()) {
1730 return false;
1731 }
1732
[email protected]9f3fba52011-06-08 20:37:191733 return true;
1734}
1735
1736std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201737 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1739 // Check if it's an extension-created worker, in which case we want to use
1740 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201741 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191742 const Extension* extension =
1743 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1744 return extension ? extension->name() : std::string();
1745}
1746
[email protected]99907362012-01-11 05:41:401747void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1748 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171749}
1750
[email protected]c52b2892012-03-07 11:01:021751content::SpeechRecognitionManagerDelegate*
1752 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321753#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021754 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321755#else
1756 return NULL;
1757#endif
[email protected]66cfec62012-02-24 17:57:511758}
1759
[email protected]ae6e9912011-07-27 01:18:281760net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1761 return g_browser_process->net_log();
1762}
1763
[email protected]32538d92011-08-25 00:09:231764AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1765 return new ChromeAccessTokenStore();
1766}
1767
[email protected]dbae6b02011-06-29 23:51:411768bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011769 return true;
[email protected]dbae6b02011-06-29 23:51:411770}
1771
[email protected]64d69de42012-02-06 00:19:541772void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321773 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061774 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581775 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061776 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061777
[email protected]f3986f82012-01-03 20:00:061778 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541779 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061780 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541781 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061782 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541783 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061784 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541785 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061786 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541787 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061788 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541789 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031790 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1791 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061792
[email protected]64d69de42012-02-06 00:19:541793 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401794 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541795 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401796 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541797 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401798 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541799 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401800 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061801
[email protected]ddf72142012-05-22 04:52:401802 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061803
[email protected]64d69de42012-02-06 00:19:541804 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401805 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541806 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061807 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541808 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061809 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1810 const DictionaryValue* inspector_settings =
1811 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1812 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181813 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1814 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061815 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181816 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541817 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181818 std::make_pair(iter.key(), value));
1819 }
[email protected]f3986f82012-01-03 20:00:061820 }
1821 }
[email protected]64d69de42012-02-06 00:19:541822 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061823
[email protected]ddf72142012-05-22 04:52:401824 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541825 web_prefs->javascript_enabled = false;
1826 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1827 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401828 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541829 web_prefs->plugins_enabled = false;
1830 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1831 web_prefs->java_enabled = false;
1832 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401833 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061834
[email protected]64d69de42012-02-06 00:19:541835 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1836 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061837
[email protected]64d69de42012-02-06 00:19:541838 web_prefs->memory_info_enabled =
1839 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1840 web_prefs->allow_displaying_insecure_content =
1841 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1842 web_prefs->allow_running_insecure_content =
1843 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321844#if defined(OS_ANDROID)
1845 web_prefs->font_scale_factor =
1846 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1847 web_prefs->force_enable_zoom =
1848 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451849#if defined(GOOGLE_TV)
1850 web_prefs->user_gesture_required_for_media_playback = false;
1851#endif
[email protected]d3b935f2012-10-19 23:14:321852#endif
[email protected]9d06d88d2012-02-23 22:37:081853 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061854
[email protected]64d69de42012-02-06 00:19:541855 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151856 UserStyleSheetWatcher* user_style_sheet_watcher =
1857 UserStyleSheetWatcherFactory::GetForProfile(profile);
1858 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541859 web_prefs->user_style_sheet_enabled = true;
1860 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151861 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541862 } else {
1863 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061864 }
1865
[email protected]cfadadd2013-04-03 04:43:021866 web_prefs->asynchronous_spell_checking_enabled = true;
1867 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:571868
[email protected]64d69de42012-02-06 00:19:541869 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061870 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541871 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061872 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541873 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061874 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1875
1876 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541877 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061878 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541879 web_prefs->default_encoding);
1880 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401881 prefs->ClearPref(prefs::kDefaultCharset);
1882 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061883 }
[email protected]64d69de42012-02-06 00:19:541884 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061885
[email protected]88ecf66d2012-12-11 22:53:471886 if (content::IsForceCompositingModeEnabled())
1887 web_prefs->force_compositing_mode = true;
1888
[email protected]299d7f12012-05-23 05:31:151889 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:231890 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131891 ExtensionService* service =
1892 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061893 if (service) {
[email protected]1bc28312012-11-08 08:31:531894 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1895 const Extension* extension = service->extensions()->GetByID(url.host());
1896 // Ensure that we are only granting extension preferences to URLs with
1897 // the correct scheme. Without this check, chrome-guest:// schemes used by
1898 // webview tags as well as hosts that happen to match the id of an
1899 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421900 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531901 extension_webkit_preferences::SetPreferences(
1902 extension, view_type, web_prefs);
1903 }
[email protected]f3986f82012-01-03 20:00:061904 }
1905
[email protected]cb2edf22013-04-01 20:25:231906 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541907 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:231908 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061909 // Disable all kinds of acceleration for background pages.
1910 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541911 web_prefs->force_compositing_mode = false;
1912 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061913 }
[email protected]2e21fe292012-03-02 22:52:321914
1915#if defined(FILE_MANAGER_EXTENSION)
1916 // Override the default of suppressing HW compositing for WebUI pages for the
1917 // file manager, which is implemented using WebUI but wants HW acceleration
1918 // for video decode & render.
1919 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1920 web_prefs->accelerated_compositing_enabled = true;
1921 web_prefs->accelerated_2d_canvas_enabled = true;
1922 }
1923#endif
[email protected]181a95ee2011-07-12 19:26:361924}
1925
1926void ChromeContentBrowserClient::UpdateInspectorSetting(
1927 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061928 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581929 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061930 DictionaryPrefUpdate update(
1931 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1932 prefs::kWebKitInspectorSettings);
1933 DictionaryValue* inspector_settings = update.Get();
1934 inspector_settings->SetWithoutPathExpansion(key,
1935 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361936}
1937
[email protected]b8148ac2011-07-13 22:03:251938void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1939 BrowserURLHandler* handler) {
1940 // Add the default URL handlers.
1941 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1942 BrowserURLHandler::null_handler());
1943 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1944 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1945
[email protected]b3adbd02011-11-30 22:23:271946 // about: handler. Must come before chrome: handler, since it will
1947 // rewrite about: urls to chrome: URLs and then expect chrome: to
1948 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251949 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1950 BrowserURLHandler::null_handler());
1951 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241952 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251953}
1954
1955void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371956 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581957 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471958 BrowsingDataRemover* remover =
1959 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551960 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1961 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251962 // BrowsingDataRemover takes care of deleting itself when done.
1963}
1964
1965void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371966 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581967 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471968 BrowsingDataRemover* remover =
1969 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231970 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551971 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251972 // BrowsingDataRemover takes care of deleting itself when done.
1973}
1974
[email protected]650b2d52013-02-10 03:41:451975base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:321976 return download_util::GetDefaultDownloadDirectory();
1977}
1978
[email protected]c9b6eb62011-10-18 20:49:391979std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1980 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1981}
1982
[email protected]b7631cc2012-09-15 05:08:381983void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1984 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:541985#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:381986 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1987 scoped_ptr<ppapi::host::HostFactory>(
1988 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:541989#endif
[email protected]b7631cc2012-09-15 05:08:381990}
1991
[email protected]0c7193742012-11-07 19:05:031992content::BrowserPpapiHost*
1993 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
1994 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:131995 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:031996 while (!iter.Done()) {
1997 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
1998 if (host->process() &&
1999 host->process()->GetData().id == plugin_process_id) {
2000 // Found the plugin.
2001 return host->browser_ppapi_host();
2002 }
2003 ++iter;
2004 }
2005 return NULL;
2006}
2007
[email protected]7b38b192013-03-23 18:39:312008bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2009 content::BrowserContext* browser_context, const GURL& site_url) {
2010 if (CommandLine::ForCurrentProcess()->HasSwitch(
2011 switches::kEnableBrowserPluginForAllViewTypes))
2012 return true;
2013
2014 Profile* profile = Profile::FromBrowserContext(browser_context);
2015 ExtensionService* service =
2016 extensions::ExtensionSystem::Get(profile)->extension_service();
2017 if (!service)
2018 return false;
2019
2020 const Extension* extension = service->extensions()->
2021 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2022 if (!extension)
2023 return false;
2024
2025 return extension->HasAPIPermission(APIPermission::kWebView);
2026}
2027
[email protected]38cd8f7f2012-06-15 22:06:072028bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582029 content::BrowserContext* browser_context,
2030 const GURL& url,
2031 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:292032 if (!url.is_valid())
2033 return false;
2034
2035 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:422036 if (url.SchemeIs(extensions::kExtensionScheme) &&
2037 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:292038 return true;
[email protected]885c0e92012-11-13 20:27:422039 }
[email protected]a658d452012-03-02 12:45:292040
[email protected]9a5940d2012-04-27 19:16:232041 Profile* profile = Profile::FromBrowserContext(browser_context);
2042 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:192043 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:132044 extensions::ExtensionSystem::Get(profile)->extension_service();
2045 if (extension_service) {
2046 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:232047 GetExtensionOrAppByURL(ExtensionURLInfo(url));
2048 }
2049
[email protected]f237c0f2012-03-10 07:49:102050 // Need to check this now and not on construction because otherwise it won't
2051 // work with browser_tests.
2052 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2053 std::string allowed_list =
2054 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:232055 if (allowed_list == "*") {
2056 // The wildcard allows socket API only for packaged and platform apps.
2057 return extension &&
[email protected]1d5e58b2013-01-31 08:41:402058 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
2059 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:232060 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:392061 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:102062 while (t.GetNext()) {
2063 if (t.token() == host)
2064 return true;
2065 }
2066 }
2067
[email protected]a658d452012-03-02 12:45:292068 if (!extension)
2069 return false;
2070
[email protected]157cc902012-11-02 06:31:582071 extensions::SocketPermission::CheckParam extension_params(
2072 params.type, params.host, params.port);
2073 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
2074 &extension_params))
[email protected]a658d452012-03-02 12:45:292075 return true;
2076
2077 return false;
[email protected]e461da2f2012-02-16 19:06:402078}
2079
[email protected]650b2d52013-02-10 03:41:452080base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2081 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142082 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2083 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2084}
2085
[email protected]a28e3302013-02-03 03:50:432086ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2087 WebContents* web_contents) {
2088 return new ChromeSelectFilePolicy(web_contents);
2089}
2090
[email protected]7d9424702013-04-14 13:14:162091void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2092 std::vector<std::string>* additional_allowed_schemes) {
2093 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2094 additional_allowed_schemes);
2095 additional_allowed_schemes->push_back(kChromeUIScheme);
2096 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2097}
2098
[email protected]e60c0232011-11-11 19:56:352099#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182100void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2101 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382102 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082103 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392104#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452105 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392106 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2107 DCHECK(!data_path.empty());
2108
2109 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452110 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392111 base::PlatformFile f =
2112 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2113 DCHECK(f != base::kInvalidPlatformFileValue);
2114 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2115 FileDescriptor(f, true)));
2116
[email protected]650b2d52013-02-10 03:41:452117 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392118 data_path.AppendASCII("chrome_100_percent.pak");
2119 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2120 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372121 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392122 FileDescriptor(f, true)));
2123
2124 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452125 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392126 GetLocaleFilePath(locale, false);
2127 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2128 DCHECK(f != base::kInvalidPlatformFileValue);
2129 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2130 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382131
[email protected]650b2d52013-02-10 03:41:452132 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372133 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2134 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2135 DCHECK(f != base::kInvalidPlatformFileValue);
2136 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2137 FileDescriptor(f, true)));
2138
[email protected]40da3e0c2012-10-24 22:03:382139#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432140 if (IsCrashReporterEnabled()) {
2141 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2142 if (f == base::kInvalidPlatformFileValue) {
2143 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2144 "be disabled for this process.";
2145 } else {
2146 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2147 FileDescriptor(f, true)));
2148 }
[email protected]40da3e0c2012-10-24 22:03:382149 }
2150#endif // defined(USE_LINUX_BREAKPAD)
2151
2152#else
2153 int crash_signal_fd = GetCrashSignalFD(command_line);
2154 if (crash_signal_fd >= 0) {
2155 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2156 FileDescriptor(crash_signal_fd,
2157 false)));
2158 }
[email protected]29699c22012-10-03 23:57:392159#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302160}
[email protected]e60c0232011-11-11 19:56:352161#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302162
[email protected]4a65826d2011-08-25 16:04:012163#if defined(OS_WIN)
2164const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2165 return chrome::kBrowserResourcesDll;
2166}
[email protected]34f48682013-03-20 00:30:182167
2168void ChromeContentBrowserClient::PreSpawnRenderer(
2169 sandbox::TargetPolicy* policy,
2170 bool* success) {
2171 // This code is duplicated in nacl_exe_win_64.cc.
2172 // Allow the server side of a pipe restricted to the "chrome.nacl."
2173 // namespace so that it cannot impersonate other system or other chrome
2174 // service pipes.
2175 sandbox::ResultCode result = policy->AddRule(
2176 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2177 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2178 L"\\\\.\\pipe\\chrome.nacl.*");
2179 if (result != sandbox::SBOX_ALL_OK) {
2180 *success = false;
2181 return;
2182 }
2183
2184 // Renderers need to send named pipe handles and shared memory
2185 // segment handles to NaCl loader processes.
2186 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2187 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2188 L"File");
2189 if (result != sandbox::SBOX_ALL_OK) {
2190 *success = false;
2191 return;
2192 }
2193}
[email protected]4a65826d2011-08-25 16:04:012194#endif
2195
[email protected]37a72af2011-06-13 05:42:012196#if defined(USE_NSS)
2197crypto::CryptoModuleBlockingPasswordDelegate*
2198 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2199 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292200 return chrome::NewCryptoModuleBlockingDialogDelegate(
2201 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012202}
2203#endif
2204
[email protected]d977f9c2011-03-14 16:10:262205} // namespace chrome