blob: b03bdec4b97173cae1c5e0f57e38a47fbfcccb93 [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]40404bc2012-07-25 17:40:4942#include "chrome/browser/extensions/message_handler.h"
[email protected]eb4832a2012-12-08 01:57:5243#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2344#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1245#include "chrome/browser/google/google_util.h"
[email protected]11158e2d2013-02-01 02:31:5646#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0447#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]0c7193742012-11-07 19:05:0348#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2849#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0450#include "chrome/browser/notifications/desktop_notification_service.h"
51#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4252#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5653#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0654#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4155#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5056#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0757#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4158#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1459#include "chrome/browser/printing/printing_message_filter.h"
60#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3261#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0662#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1463#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3364#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]b7631cc2012-09-15 05:08:3865#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4366#include "chrome/browser/search/instant_service.h"
67#include "chrome/browser/search/instant_service_factory.h"
68#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1469#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]970c63e2013-03-07 00:25:3070#include "chrome/browser/signin/signin_manager.h"
71#include "chrome/browser/signin/signin_manager_factory.h"
[email protected]c52b2892012-03-07 11:01:0272#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4673#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5874#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0375#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5276#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4577#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5478#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4379#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]b5d73422012-06-02 23:46:4480#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5081#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]970c63e2013-03-07 00:25:3082#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
[email protected]f3986f82012-01-03 20:00:0683#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1584#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]b80f68432011-05-02 17:22:3085#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0186#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1487#include "chrome/common/chrome_paths.h"
[email protected]f3b357692013-03-22 05:16:1388#include "chrome/common/chrome_process_type.h"
[email protected]b80f68432011-05-02 17:22:3089#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2990#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0491#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3892#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4493#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4394#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]157cc902012-11-02 06:31:5895#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3496#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1297#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3898#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0999#include "chrome/common/url_constants.h"
[email protected]75fee372013-03-06 00:42:44100#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43101#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30102#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38103#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:31104#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03105#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59106#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36107#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30108#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33109#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05110#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33111#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19112#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10113#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43114#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18115#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23116#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42117#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39118#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23119#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53120#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58121#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34122#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06123#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57124#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38125#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39126#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08127#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36128#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04129#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26130
[email protected]b48c9182011-10-26 18:03:30131#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38132#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18133#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38134#elif defined(OS_MACOSX)
135#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56136#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30137#elif defined(OS_CHROMEOS)
138#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49139#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]931d1042013-04-05 17:50:44140#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26141#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30142#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09143#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38144#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09145#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39146#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30147#elif defined(OS_POSIX)
148#include "chrome/browser/chrome_browser_main_posix.h"
149#endif
150
[email protected]6653c192012-04-10 22:52:44151#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30152#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12153#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43154#endif
[email protected]b80f68432011-05-02 17:22:30155
[email protected]1e87df32012-09-12 04:53:19156#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
157#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
158#endif
159
[email protected]16dc42452013-04-09 04:37:19160#if defined(ENABLE_MESSAGE_CENTER)
161#include "ui/message_center/message_center_util.h"
162#endif
163
[email protected]29699c22012-10-03 23:57:39164#if defined(OS_ANDROID)
165#include "ui/base/ui_base_paths.h"
166#endif
167
[email protected]37a72af2011-06-13 05:42:01168#if defined(USE_NSS)
169#include "chrome/browser/ui/crypto_module_password_dialog.h"
170#endif
171
[email protected]c7abd422012-09-25 00:20:08172using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47173using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03174using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39175using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31176using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59177using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08178using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00179using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11180using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33181using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13182using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06183using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34184using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40185using extensions::Manifest;
[email protected]6717bf272012-05-11 23:31:25186using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39187
[email protected]c5dbef02011-05-13 05:06:09188namespace {
189
[email protected]eabbfb12013-04-05 23:28:35190// Cached version of the locale so we can return the locale on the I/O
191// thread.
192base::LazyInstance<std::string> g_io_thread_application_locale;
193
[email protected]e461da2f2012-02-16 19:06:40194const char* kPredefinedAllowedSocketOrigins[] = {
195 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18196 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45197 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
198 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
199 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
200 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35201 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54202 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
203 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
204 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
205 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
206 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
207 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38208 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58209 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
210 "iabmpiboiopbgfabjmgeedhcmjenhbla" // see crbug.com/165080
[email protected]e461da2f2012-02-16 19:06:40211};
212
[email protected]f8f93eb2012-09-25 03:06:24213// Returns a copy of the given url with its host set to given host and path set
214// to given path. Other parts of the url will be the same.
215GURL ReplaceURLHostAndPath(const GURL& url,
216 const std::string& host,
217 const std::string& path) {
218 url_canon::Replacements<char> replacements;
219 replacements.SetHost(host.c_str(),
220 url_parse::Component(0, host.length()));
221 replacements.SetPath(path.c_str(),
222 url_parse::Component(0, path.length()));
223 return url.ReplaceComponents(replacements);
224}
225
226// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
227GURL AddUberHost(const GURL& url) {
228 const std::string uber_host = chrome::kChromeUIUberHost;
229 const std::string new_path = url.host() + url.path();
230
231 return ReplaceURLHostAndPath(url, uber_host, new_path);
232}
233
[email protected]045bf7c2012-09-28 20:27:36234// If url->host() is "chrome" and url->path() has characters other than the
235// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
236// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24237bool RemoveUberHost(GURL* url) {
238 if (url->host() != chrome::kChromeUIUberHost)
239 return false;
240
[email protected]045bf7c2012-09-28 20:27:36241 if (url->path().empty() || url->path() == "/")
242 return false;
243
[email protected]f8f93eb2012-09-25 03:06:24244 const std::string old_path = url->path();
245
246 const std::string::size_type separator = old_path.find('/', 1);
247 std::string new_host;
248 std::string new_path;
249 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36250 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24251 } else {
252 new_host = old_path.substr(1, separator - 1);
253 new_path = old_path.substr(separator);
254 }
255
256 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
257
258 return true;
259}
260
[email protected]b8148ac2011-07-13 22:03:25261// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42262bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24263 // Do not handle special URLs such as "about:foo"
264 if (!url->host().empty()) {
265 const GURL chrome_url = AddUberHost(*url);
266
267 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
268 // be called.
269 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
270 browser_context, chrome_url))
271 return true;
272 }
273
[email protected]863f70a2012-01-27 02:05:50274 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
275 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25276 return false;
277
[email protected]fe69558d2012-03-12 11:34:49278#if defined(OS_CHROMEOS)
279 // Special case : in ChromeOS in Guest mode bookmarks and history are
280 // disabled for security reasons. New tab page explains the reasons, so
281 // we redirect user to new tab page.
282 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
283 if (url->SchemeIs(chrome::kChromeUIScheme) &&
284 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
285 url->DomainIs(chrome::kChromeUIHistoryHost))) {
286 // Rewrite with new tab URL
287 *url = GURL(chrome::kChromeUINewTabURL);
288 }
289 }
290#endif
291
[email protected]b8148ac2011-07-13 22:03:25292 // Special case the new tab page. In older versions of Chrome, the new tab
293 // page was hosted at chrome-internal:<blah>. This might be in people's saved
294 // sessions or bookmarks, so we say any URL with that scheme triggers the new
295 // tab page.
296 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
297 // Rewrite it with the proper new tab URL.
298 *url = GURL(chrome::kChromeUINewTabURL);
299 }
300
301 return true;
302}
303
[email protected]f8f93eb2012-09-25 03:06:24304// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
305// "chrome://foo/".
306bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
307 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
308 return false;
309
310 return RemoveUberHost(url);
311}
312
[email protected]8d3132f62011-10-12 07:13:42313// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
314// below. Extension, and isolated apps require different privileges to be
315// granted to their RenderProcessHosts. This classification allows us to make
316// sure URLs are served by hosts with the right set of privileges.
317enum RenderProcessHostPrivilege {
318 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45319 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42320 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45321 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42322};
323
324RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
325 const GURL& url,
326 ExtensionService* service) {
327 // Default to a normal renderer cause it is lower privileged. This should only
328 // occur if the URL on a site instance is either malformed, or uninitialized.
329 // If it is malformed, then there is no need for better privileges anyways.
330 // If it is uninitialized, but eventually settles on being an a scheme other
331 // than normal webrenderer, the navigation logic will correct us out of band
332 // anyways.
333 if (!url.is_valid())
334 return PRIV_NORMAL;
335
[email protected]885c0e92012-11-13 20:27:42336 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44337 const Extension* extension =
338 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43339 if (extension &&
340 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42341 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45342 if (extension && extension->is_hosted_app())
343 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42344
345 return PRIV_EXTENSION;
346 }
347
348 return PRIV_NORMAL;
349}
350
351RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30352 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46353 extensions::ProcessMap* process_map,
354 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46355 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30356 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46357 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21358 return PRIV_NORMAL;
359
[email protected]6f371442011-11-09 06:45:46360 for (std::set<std::string>::iterator iter = extension_ids.begin();
361 iter != extension_ids.end(); ++iter) {
362 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43363 if (extension &&
364 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42365 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45366 if (extension && extension->is_hosted_app())
367 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42368 }
369
[email protected]676f6ab2011-10-19 20:23:21370 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42371}
372
[email protected]6786bf402011-12-03 15:19:45373bool CertMatchesFilter(const net::X509Certificate& cert,
374 const base::DictionaryValue& filter) {
375 // TODO(markusheintz): This is the minimal required filter implementation.
376 // Implement a better matcher.
377
378 // An empty filter matches any client certificate since no requirements are
379 // specified at all.
380 if (filter.empty())
381 return true;
382
383 std::string common_name;
384 if (filter.GetString("ISSUER.CN", &common_name) &&
385 (cert.issuer().common_name == common_name)) {
386 return true;
387 }
388 return false;
389}
390
[email protected]f3986f82012-01-03 20:00:06391// Fills |map| with the per-script font prefs under path |map_name|.
392void FillFontFamilyMap(const PrefService* prefs,
393 const char* map_name,
394 WebPreferences::ScriptFontFamilyMap* map) {
395 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
396 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
397 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
398 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23399 if (!font_family.empty())
400 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06401 }
402}
403
[email protected]a1733df2012-06-22 11:24:18404#if defined(OS_POSIX) && !defined(OS_MACOSX)
405int GetCrashSignalFD(const CommandLine& command_line) {
406 if (command_line.HasSwitch(switches::kExtensionProcess)) {
407 ExtensionCrashHandlerHostLinux* crash_handler =
408 ExtensionCrashHandlerHostLinux::GetInstance();
409 return crash_handler->GetDeathSignalSocket();
410 }
411
412 std::string process_type =
413 command_line.GetSwitchValueASCII(switches::kProcessType);
414
415 if (process_type == switches::kRendererProcess)
416 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
417
418 if (process_type == switches::kPluginProcess)
419 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
420
421 if (process_type == switches::kPpapiPluginProcess)
422 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
423
424 if (process_type == switches::kGpuProcess)
425 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
426
427 return -1;
428}
429#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
430
[email protected]7c60f5042013-02-14 03:39:32431// Transforms the input |url| into its "effective URL". The returned URL
[email protected]c5dec6292013-01-25 04:54:52432// facilitates grouping process-per-site. The |url| is transformed, for
433// example, from
434//
435// https://www.google.com/search?espv=1&q=tractors
436//
[email protected]7c60f5042013-02-14 03:39:32437// to the effective URL
[email protected]c5dec6292013-01-25 04:54:52438//
439// chrome-search://www.google.com/search?espv=1&q=tractors
440//
441// Notice the scheme change.
[email protected]7c60f5042013-02-14 03:39:32442//
443// If the input is already an effective URL then that same URL is returned.
444GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
[email protected]165fe422013-03-27 06:34:03445 CHECK(chrome::ShouldAssignURLToInstantRenderer(url, profile))
[email protected]7c60f5042013-02-14 03:39:32446 << "Error granting Instant access.";
[email protected]c5dec6292013-01-25 04:54:52447
448 if (url.SchemeIs(chrome::kChromeSearchScheme))
449 return url;
450
451 GURL effective_url(url);
452
453 // Replace the scheme with "chrome-search:".
454 url_canon::Replacements<char> replacements;
455 std::string search_scheme(chrome::kChromeSearchScheme);
456 replacements.SetScheme(search_scheme.data(),
457 url_parse::Component(0, search_scheme.length()));
458 effective_url = effective_url.ReplaceComponents(replacements);
459 return effective_url;
460}
461
[email protected]970c63e2013-03-07 00:25:30462GURL GetEffectiveURLForSignin(const GURL& url) {
463 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
464
465 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03466 // Copy the path because the argument to SetPathStr must outlive
467 // the Replacements object.
468 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30469 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03470 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30471 effective_url = effective_url.ReplaceComponents(replacements);
472 return effective_url;
473}
474
[email protected]eabbfb12013-04-05 23:28:35475void SetApplicationLocaleOnIOThread(const std::string& locale) {
476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
477 g_io_thread_application_locale.Get() = locale;
478}
479
[email protected]9dbfff12011-07-01 19:37:07480} // namespace
[email protected]c5dbef02011-05-13 05:06:09481
[email protected]d977f9c2011-03-14 16:10:26482namespace chrome {
483
[email protected]e461da2f2012-02-16 19:06:40484ChromeContentBrowserClient::ChromeContentBrowserClient() {
485 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
486 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40487}
488
489ChromeContentBrowserClient::~ChromeContentBrowserClient() {
490}
491
[email protected]bca18382012-06-25 19:15:23492// static
[email protected]c753f142013-02-10 13:14:04493void ChromeContentBrowserClient::RegisterUserPrefs(
494 PrefRegistrySyncable* registry) {
495 registry->RegisterBooleanPref(prefs::kDisable3DAPIs,
496 false,
497 PrefRegistrySyncable::UNSYNCABLE_PREF);
498 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
499 true,
500 PrefRegistrySyncable::UNSYNCABLE_PREF);
501 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo,
502 false,
503 PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23504}
505
[email protected]eabbfb12013-04-05 23:28:35506// static
507void ChromeContentBrowserClient::SetApplicationLocale(
508 const std::string& locale) {
509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
510
511 // This object is guaranteed to outlive all threads so we don't have to
512 // worry about the lack of refcounting and can just post as Unretained.
513 //
514 // The common case is that this function is called early in Chrome startup
515 // before any threads are created (it will also be called later if the user
516 // changes the pref). In this case, there will be no threads created and
517 // posting will fail. When there are no threads, we can just set the string
518 // without worrying about threadsafety.
519 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
520 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
521 g_io_thread_application_locale.Get() = locale;
522 }
523}
524
[email protected]50462bf02011-11-21 19:13:31525content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
526 const content::MainFunctionParams& parameters) {
527 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30528 // Construct the Main browser parts based on the OS type.
529#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31530 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04531#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31532 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30533#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22534 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26535#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31536 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14537#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09538 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30539#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31540 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04541#else
[email protected]b48c9182011-10-26 18:03:30542 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31543 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30544#endif
545
[email protected]c7480942011-11-08 19:18:27546 // Construct additional browser parts. Stages are called in the order in
547 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22548#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41549 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04550#endif
[email protected]c7480942011-11-08 19:18:27551
552#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41553 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27554#endif
555
[email protected]dc04be7c2012-03-15 23:57:49556#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41557 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49558#endif
559
[email protected]e050ef142012-03-21 01:04:24560#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41561 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24562#endif
563
[email protected]95132f52013-04-12 02:19:04564 chrome::AddMetricsExtraParts(main_parts);
565
[email protected]50462bf02011-11-21 19:13:31566 return main_parts;
[email protected]f967b722011-09-07 00:58:04567}
568
[email protected]e94bbcb2012-09-07 05:33:57569std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19570 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57571 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53572 std::string partition_id;
573
574 // The partition ID for webview guest processes is the string value of its
575 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
576 if (site.SchemeIs(chrome::kGuestScheme))
577 partition_id = site.spec();
578
[email protected]056efdc2013-04-06 00:14:53579 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53580 return partition_id;
581}
582
583bool ChromeContentBrowserClient::IsValidStoragePartitionId(
584 content::BrowserContext* browser_context,
585 const std::string& partition_id) {
586 // The default ID is empty and is always valid.
587 if (partition_id.empty())
588 return true;
589
590 return GURL(partition_id).is_valid();
591}
592
593void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
594 content::BrowserContext* browser_context,
595 const GURL& site,
[email protected]14acc642012-11-17 12:20:10596 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53597 std::string* partition_domain,
598 std::string* partition_name,
599 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10600 // Default to the browser-wide storage partition and override based on |site|
601 // below.
602 partition_domain->clear();
603 partition_name->clear();
604 *in_memory = false;
605
[email protected]1bc28312012-11-08 08:31:53606 // For the webview tag, we create special guest processes, which host the
607 // tag content separately from the main application that embeds the tag.
608 // A webview tag can specify both the partition name and whether the storage
609 // for that partition should be persisted. Each tag gets a SiteInstance with
610 // a specially formatted URL, based on the application it is hosted by and
611 // the partition requested by it. The format for that URL is:
612 // chrome-guest://partition_domain/persist?partition_name
613 if (site.SchemeIs(chrome::kGuestScheme)) {
614 // Since guest URLs are only used for packaged apps, there must be an app
615 // id in the URL.
616 CHECK(site.has_host());
617 *partition_domain = site.host();
618 // Since persistence is optional, the path must either be empty or the
619 // literal string.
620 *in_memory = (site.path() != "/persist");
621 // The partition name is user supplied value, which we have encoded when the
622 // URL was created, so it needs to be decoded.
623 *partition_name = net::UnescapeURLComponent(site.query(),
624 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10625 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
626 // If |can_be_default| is false, the caller is stating that the |site|
627 // should be parsed as if it had isolated storage. In particular it is
628 // important to NOT check ExtensionService for the is_storage_isolated()
629 // attribute because this code path is run during Extension uninstall
630 // to do cleanup after the Extension has already been unloaded from the
631 // ExtensionService.
632 bool is_isolated = !can_be_default;
633 if (can_be_default) {
634 const Extension* extension = NULL;
635 Profile* profile = Profile::FromBrowserContext(browser_context);
636 ExtensionService* extension_service =
637 extensions::ExtensionSystem::Get(profile)->extension_service();
638 if (extension_service) {
639 extension = extension_service->extensions()->
640 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43641 if (extension &&
642 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10643 is_isolated = true;
644 }
645 }
646 }
[email protected]1bc28312012-11-08 08:31:53647
[email protected]14acc642012-11-17 12:20:10648 if (is_isolated) {
649 CHECK(site.has_host());
650 // For extensions with isolated storage, the the host of the |site| is
651 // the |partition_domain|. The |in_memory| and |partition_name| are only
652 // used in guest schemes so they are cleared here.
653 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53654 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10655 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53656 }
[email protected]d1198fd2012-08-13 22:50:19657 }
658
[email protected]14acc642012-11-17 12:20:10659 // Assert that if |can_be_default| is false, the code above must have found a
660 // non-default partition. If this fails, the caller has a serious logic
661 // error about which StoragePartition they expect to be in and it is not
662 // safe to continue.
663 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44664}
665
[email protected]38b098f2012-03-14 21:11:57666content::WebContentsViewDelegate*
667 ChromeContentBrowserClient::GetWebContentsViewDelegate(
668 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27669 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32670}
671
[email protected]f364d1392011-04-08 21:03:10672void ChromeContentBrowserClient::RenderViewHostCreated(
673 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46674
[email protected]9f76c1e2012-03-05 15:15:58675 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46676 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02677 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46678
679 new ChromeRenderViewHostObserver(render_view_host,
680 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49681 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26682}
683
[email protected]24665682013-02-25 20:59:38684// Check if the extension activity log is enabled for the profile.
685static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
686 extensions::ActivityLog* activity_log =
687 extensions::ActivityLog::GetInstance(profile);
688 return activity_log->IsLogEnabled();
689}
690
[email protected]44703cc72013-01-24 04:56:06691void ChromeContentBrowserClient::GuestWebContentsCreated(
692 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
693 Profile* profile = Profile::FromBrowserContext(
694 embedder_web_contents->GetBrowserContext());
695 ExtensionService* service =
696 extensions::ExtensionSystem::Get(profile)->extension_service();
697 if (!service)
698 return;
699 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
700 const Extension* extension = service->extensions()->
701 GetExtensionOrAppByURL(ExtensionURLInfo(url));
702 if (!extension)
703 return;
704 std::vector<ExtensionMsg_Loaded_Params> extensions;
705 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
706 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
707}
708
[email protected]f3b1a082011-11-18 00:34:30709void ChromeContentBrowserClient::RenderProcessHostCreated(
710 content::RenderProcessHost* host) {
711 int id = host->GetID();
712 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41713 net::URLRequestContextGetter* context =
714 profile->GetRequestContextForRenderProcess(id);
715
[email protected]f3b1a082011-11-18 00:34:30716 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41717 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55718#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30719 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55720#endif
[email protected]658677f2012-06-09 06:04:02721#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08722 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03723#endif
[email protected]f3b1a082011-11-18 00:34:30724 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02725 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30726 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56727#if defined(OS_MACOSX)
728 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
729#endif
[email protected]43535512013-02-20 20:41:41730 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
731 id, profile, context));
[email protected]2736c032012-05-11 18:06:07732 host->GetChannel()->AddFilter(
733 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38734
[email protected]2ccf45c2011-08-19 23:35:50735 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
736 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07737
[email protected]24665682013-02-25 20:59:38738 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
739 IsExtensionActivityLogEnabledForProfile(profile)));
740
[email protected]39a5b532011-10-22 01:47:07741 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56742
743 RendererContentSettingRules rules;
744 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
745 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14746}
747
[email protected]3d7474ff2011-07-27 17:47:37748GURL ChromeContentBrowserClient::GetEffectiveURL(
749 content::BrowserContext* browser_context, const GURL& url) {
750 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52751 if (!profile)
752 return url;
753
[email protected]7c60f5042013-02-14 03:39:32754 // If the input |url| should be assigned to the Instant renderer, make its
755 // effective URL distinct from other URLs on the search provider's domain.
[email protected]165fe422013-03-27 06:34:03756 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
[email protected]7c60f5042013-02-14 03:39:32757 return GetEffectiveURLForInstant(url, profile);
[email protected]c5dec6292013-01-25 04:54:52758
[email protected]970c63e2013-03-07 00:25:30759 // If the input |url| should be assigned to the Signin renderer, make its
760 // effective URL distinct from other URLs on the signin service's domain.
761 // Note that the signin renderer will be allowed to sign the user in to
762 // Chrome.
763 if (SigninManager::IsWebBasedSigninFlowURL(url))
764 return GetEffectiveURLForSignin(url);
765
[email protected]c5dec6292013-01-25 04:54:52766 // If the input |url| is part of an installed app, the effective URL is an
767 // extension URL with the ID of that extension as the host. This has the
768 // effect of grouping apps together in a common SiteInstance.
769 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13770 extensions::ExtensionSystem::Get(profile)->extension_service();
771 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08772 return url;
773
[email protected]06bdd2b2012-11-30 18:47:13774 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44775 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08776 if (!extension)
777 return url;
778
[email protected]15877ca2011-11-18 22:40:52779 // Bookmark apps do not use the hosted app process model, and should be
780 // treated as normal URLs.
781 if (extension->from_bookmark())
782 return url;
783
[email protected]36fb2c7c2011-04-04 15:49:08784 // If the URL is part of an extension's web extent, convert it to an
785 // extension URL.
786 return extension->GetResourceURL(url.path());
787}
788
[email protected]056ad2a2011-07-12 02:13:55789bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37790 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52791 // Non-extension, non-Instant URLs should generally use
792 // process-per-site-instance. Because we expect to use the effective URL,
793 // URLs for hosted apps (apart from bookmark apps) should have an extension
794 // scheme by now.
795
796 Profile* profile = Profile::FromBrowserContext(browser_context);
797 if (!profile)
798 return false;
799
[email protected]165fe422013-03-27 06:34:03800 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52801 return true;
802
[email protected]970c63e2013-03-07 00:25:30803 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
804 return true;
805
[email protected]885c0e92012-11-13 20:27:42806 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55807 return false;
808
[email protected]c5dec6292013-01-25 04:54:52809 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13810 extensions::ExtensionSystem::Get(profile)->extension_service();
811 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55812 return false;
813
[email protected]06bdd2b2012-11-30 18:47:13814 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44815 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55816 if (!extension)
817 return false;
818
819 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53820 // permission, or that does not allow JavaScript access to the background
821 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55822 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40823 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06824 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29825 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53826 return false;
827 }
828 }
[email protected]056ad2a2011-07-12 02:13:55829
[email protected]7b54ca02012-03-02 18:06:53830 // Hosted apps that have script access to their background page must use
831 // process per site, since all instances can make synchronous calls to the
832 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55833 return true;
834}
835
[email protected]672c8c12013-03-07 12:30:06836// These are treated as WebUI schemes but do not get WebUI bindings.
837std::vector<std::string>
838ChromeContentBrowserClient::GetAdditionalWebUISchemes() {
839 std::vector<std::string> additional_schemes;
840 additional_schemes.push_back(chrome::kChromeSearchScheme);
841 return additional_schemes;
842}
843
[email protected]6bd30072013-02-08 18:17:11844net::URLRequestContextGetter*
845ChromeContentBrowserClient::CreateRequestContext(
846 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06847 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11848 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06849 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11850}
851
852net::URLRequestContextGetter*
853ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
854 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40855 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11856 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06857 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11858 Profile* profile = Profile::FromBrowserContext(browser_context);
859 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06860 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11861}
862
[email protected]46fb9442011-12-09 17:57:47863bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
864 return ProfileIOData::IsHandledURL(url);
865}
866
[email protected]2a5221b2011-09-27 23:07:31867bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30868 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31869 const GURL& site_url) {
870 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30871 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52872 // This may be NULL during tests. In that case, just assume any site can
873 // share any host.
874 if (!profile)
875 return true;
876
[email protected]d43f99fe2013-04-03 00:20:14877 // Instant URLs should only be in the instant process and instant process
878 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52879 InstantService* instant_service =
880 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14881 if (instant_service) {
882 bool is_instant_process = instant_service->IsInstantProcess(
883 process_host->GetID());
884 bool should_be_in_instant_process =
885 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
886 if (is_instant_process || should_be_in_instant_process)
887 return is_instant_process && should_be_in_instant_process;
888 }
[email protected]c5dec6292013-01-25 04:54:52889
[email protected]970c63e2013-03-07 00:25:30890 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
891 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
892 return SigninManager::IsWebBasedSigninFlowURL(site_url);
893
[email protected]06bdd2b2012-11-30 18:47:13894 ExtensionService* service =
895 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46896 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31897
[email protected]ffa97602011-11-17 17:55:52898 // Don't allow the Task Manager to share a process with anything else.
899 // Otherwise it can affect the renderers it is observing.
900 // Note: we could create another RenderProcessHostPrivilege bucket for
901 // this to allow multiple chrome://tasks instances to share, but that's
902 // a very unlikely case without serious consequences.
903 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
904 return false;
905
[email protected]8d3132f62011-10-12 07:13:42906 // These may be NULL during tests. In that case, just assume any site can
907 // share any host.
[email protected]6f371442011-11-09 06:45:46908 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31909 return true;
910
[email protected]eec0b33c2011-12-05 22:09:45911 // Otherwise, just make sure the process privilege matches the privilege
912 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57913 RenderProcessHostPrivilege privilege_required =
914 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45915 return GetProcessPrivilege(process_host, process_map, service) ==
916 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31917}
918
[email protected]76411f412012-02-22 18:56:06919// This function is trying to limit the amount of processes used by extensions
920// with background pages. It uses a globally set percentage of processes to
921// run such extensions and if the limit is exceeded, it returns true, to
922// indicate to the content module to group extensions together.
923bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
924 content::BrowserContext* browser_context, const GURL& url) {
925 // It has to be a valid URL for us to check for an extension.
926 if (!url.is_valid())
927 return false;
928
929 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19930 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13931 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06932 if (!service)
933 return false;
934
935 // We have to have a valid extension with background page to proceed.
936 const Extension* extension =
937 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
938 if (!extension)
939 return false;
[email protected]9367eabc2013-03-01 01:29:29940 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06941 return false;
942
943 std::set<int> process_ids;
944 size_t max_process_count =
945 content::RenderProcessHost::GetMaxRendererProcessCount();
946
947 // Go through all profiles to ensure we have total count of extension
948 // processes containing background pages, otherwise one profile can
949 // starve the other.
950 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
951 GetLoadedProfiles();
952 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03953 ExtensionProcessManager* epm =
954 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32955 for (ExtensionProcessManager::const_iterator iter =
956 epm->background_hosts().begin();
957 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13958 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32959 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06960 }
961 }
962
963 if (process_ids.size() >
964 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
965 return true;
966 }
967
968 return false;
969}
970
[email protected]6f371442011-11-09 06:45:46971void ChromeContentBrowserClient::SiteInstanceGotProcess(
972 SiteInstance* site_instance) {
973 CHECK(site_instance->HasProcess());
974
975 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02976 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52977 if (!profile)
978 return;
979
980 // Remember the ID of the Instant process to signal the renderer process
981 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:03982 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:32983 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:52984 InstantService* instant_service =
985 InstantServiceFactory::GetForProfile(profile);
986 if (instant_service)
987 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
988 }
989
[email protected]970c63e2013-03-07 00:25:30990 // We only expect there to be one signin process as we use process-per-site
991 // for signin URLs. The signin process will be cleared from SigninManager
992 // when the renderer is destroyed.
993 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
994 SigninManager* signin_manager =
995 SigninManagerFactory::GetForProfile(profile);
996 if (signin_manager)
997 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
998 }
999
[email protected]06bdd2b2012-11-30 18:47:131000 ExtensionService* service =
1001 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461002 if (!service)
1003 return;
1004
1005 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441006 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591007 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461008 if (!extension)
1009 return;
1010
[email protected]6bc04fd82011-12-04 02:29:351011 service->process_map()->Insert(extension->id(),
1012 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331013 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461014 BrowserThread::PostTask(
1015 BrowserThread::IO, FROM_HERE,
1016 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591017 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461018 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351019 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331020 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461021}
1022
1023void ChromeContentBrowserClient::SiteInstanceDeleting(
1024 SiteInstance* site_instance) {
1025 if (!site_instance->HasProcess())
1026 return;
1027
1028 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021029 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131030 ExtensionService* service =
1031 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461032 if (!service)
1033 return;
1034
1035 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441036 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591037 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461038 if (!extension)
1039 return;
1040
[email protected]6bc04fd82011-12-04 02:29:351041 service->process_map()->Remove(extension->id(),
1042 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331043 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461044 BrowserThread::PostTask(
1045 BrowserThread::IO, FROM_HERE,
1046 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591047 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461048 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351049 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331050 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461051}
1052
[email protected]f05763972012-06-06 18:17:261053bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141054 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081055 const GURL& current_url,
1056 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261057 if (current_url.is_empty()) {
1058 // Always choose a new process when navigating to extension URLs. The
1059 // process grouping logic will combine all of a given extension's pages
1060 // into the same process.
[email protected]885c0e92012-11-13 20:27:421061 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261062 return true;
[email protected]e3daf3c2011-10-05 21:17:081063
[email protected]f05763972012-06-06 18:17:261064 return false;
1065 }
1066
1067 // Also, we must switch if one is an extension and the other is not the exact
1068 // same extension.
[email protected]885c0e92012-11-13 20:27:421069 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1070 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261071 if (current_url.GetOrigin() != new_url.GetOrigin())
1072 return true;
1073 }
1074
[email protected]e9841fbd2013-02-22 23:12:141075 // The checks below only matter if we can retrieve which extensions are
1076 // installed.
1077 Profile* profile =
1078 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1079 ExtensionService* service =
1080 extensions::ExtensionSystem::Get(profile)->extension_service();
1081 if (!service)
1082 return false;
1083
1084 // We must swap if the URL is for an extension and we are not using an
1085 // extension process.
1086 const Extension* new_extension =
1087 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1088 // Ignore all hosted apps except the Chrome Web Store, since they do not
1089 // require their own BrowsingInstance (e.g., postMessage is ok).
1090 if (new_extension &&
1091 new_extension->is_hosted_app() &&
1092 new_extension->id() != extension_misc::kWebStoreAppId)
1093 new_extension = NULL;
1094 if (new_extension &&
1095 site_instance->HasProcess() &&
1096 !service->process_map()->Contains(new_extension->id(),
1097 site_instance->GetProcess()->GetID()))
1098 return true;
1099
[email protected]f05763972012-06-06 18:17:261100 return false;
[email protected]e3daf3c2011-10-05 21:17:081101}
1102
[email protected]395045c2012-05-22 15:04:381103bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1104 content::ResourceContext* resource_context, const GURL& current_url,
1105 const GURL& new_url) {
1106 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1107 return extensions::CrossesExtensionProcessBoundary(
1108 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171109 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381110}
1111
[email protected]763ec4ca2011-04-29 15:48:121112std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1113 const std::string& alias_name) {
1114 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1115}
1116
[email protected]b80f68432011-05-02 17:22:301117void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1118 CommandLine* command_line, int child_process_id) {
1119#if defined(USE_LINUX_BREAKPAD)
1120 if (IsCrashReporterEnabled()) {
1121 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1122 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1123 }
1124#elif defined(OS_MACOSX)
1125 if (IsCrashReporterEnabled()) {
1126 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1127 child_process_logging::GetClientId());
1128 }
1129#endif // OS_MACOSX
1130
[email protected]f1933792011-06-14 00:49:341131 if (logging::DialogsAreSuppressed())
1132 command_line->AppendSwitch(switches::kNoErrorDialogs);
1133
[email protected]b80f68432011-05-02 17:22:301134 std::string process_type =
1135 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171136 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321137
1138 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1139 command_line->AppendSwitch(switches::kChromeFrame);
1140
[email protected]718eab62011-10-05 21:16:521141 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451142 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301143 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1144 if (!user_data_dir.empty())
1145 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1146#if defined(OS_CHROMEOS)
1147 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441148 browser_command_line.GetSwitchValueASCII(
1149 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301150 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441151 command_line->AppendSwitchASCII(
1152 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301153#endif
1154
[email protected]f3b1a082011-11-18 00:34:301155 content::RenderProcessHost* process =
1156 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371157 if (process) {
1158 Profile* profile = Profile::FromBrowserContext(
1159 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131160 ExtensionService* extension_service =
1161 extensions::ExtensionSystem::Get(profile)->extension_service();
1162 if (extension_service) {
1163 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001164 if (process_map && process_map->Contains(process->GetID()))
1165 command_line->AppendSwitch(switches::kExtensionProcess);
1166 }
[email protected]b80f68432011-05-02 17:22:301167
[email protected]a8d851f82011-12-21 00:32:371168 PrefService* prefs = profile->GetPrefs();
1169 // Currently this pref is only registered if applied via a policy.
1170 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1171 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1172 // Turn this policy into a command line switch.
1173 command_line->AppendSwitch(switches::kDisable3DAPIs);
1174 }
[email protected]718eab62011-10-05 21:16:521175
[email protected]a8d851f82011-12-21 00:32:371176 // Disable client-side phishing detection in the renderer if it is
1177 // disabled in the Profile preferences or the browser process.
1178 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1179 !g_browser_process->safe_browsing_detection_service()) {
1180 command_line->AppendSwitch(
1181 switches::kDisableClientSidePhishingDetection);
1182 }
[email protected]0045b0f42012-07-26 11:52:081183
1184 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211185 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521186
1187 InstantService* instant_service =
1188 InstantServiceFactory::GetForProfile(profile);
1189 if (instant_service &&
1190 instant_service->IsInstantProcess(process->GetID()))
1191 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301192
1193 SigninManager* signin_manager =
1194 SigninManagerFactory::GetForProfile(profile);
1195 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1196 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]47c7ec82012-01-18 03:29:211197 }
[email protected]4287a3d2011-06-13 23:56:511198
[email protected]87552982012-11-02 17:21:401199 if (content::IsThreadedCompositingEnabled())
1200 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1201
[email protected]16dc42452013-04-09 04:37:191202#if defined(ENABLE_MESSAGE_CENTER)
1203 if (message_center::IsRichNotificationEnabled())
1204 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
1205#endif
1206
[email protected]47c7ec82012-01-18 03:29:211207 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511208 static const char* const kSwitchNames[] = {
[email protected]8f96cef2013-04-01 16:51:131209 switches::kAllowRequestOSFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511210 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481211 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511212 switches::kAllowScriptingGallery,
1213 switches::kAppsCheckoutURL,
1214 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311215 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511216 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501217 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531218 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111219 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511220 switches::kDumpHistogramsOnExit,
[email protected]e9cddd52013-03-23 17:37:531221 switches::kEnableAdview,
1222 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211223 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511224 switches::kEnableExperimentalExtensionApis,
[email protected]dcfefa52013-02-15 07:46:561225 switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511226 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511227 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511228 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451229 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481230 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051231 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511232 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291233 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511234 switches::kMemoryProfiling,
1235 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371236 switches::kNoJsRandomness,
[email protected]732b1604e2012-10-26 19:59:581237 switches::kPerformCrashAnalysis,
[email protected]f45c5f32012-04-18 19:26:371238 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511239 switches::kPpapiFlashArgs,
1240 switches::kPpapiFlashInProcess,
1241 switches::kPpapiFlashPath,
1242 switches::kPpapiFlashVersion,
1243 switches::kProfilingAtStart,
1244 switches::kProfilingFile,
1245 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371246 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511247 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291248 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381249 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511250 };
1251
1252 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1253 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171254 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381255 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351256 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381257 switches::kEnableExperimentalExtensionApis,
1258 switches::kWhitelistedExtensionID,
1259 };
1260
1261 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1262 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511263 } else if (process_type == switches::kPluginProcess) {
1264 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441265#if defined(OS_CHROMEOS)
1266 chromeos::switches::kLoginProfile,
1267#endif
[email protected]4287a3d2011-06-13 23:56:511268 switches::kMemoryProfiling,
1269 switches::kSilentDumpOnDCHECK,
1270 switches::kUserDataDir,
1271 };
1272
1273 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1274 arraysize(kSwitchNames));
1275 } else if (process_type == switches::kZygoteProcess) {
1276 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511277 switches::kUserDataDir, // Make logs go to the right file.
1278 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501279 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511280 switches::kPpapiFlashInProcess,
1281 switches::kPpapiFlashPath,
1282 switches::kPpapiFlashVersion,
1283 };
1284
1285 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1286 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111287 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001288 base::FilePath user_data_dir =
1289 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1290 if (!user_data_dir.empty())
1291 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111292 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1293 // because GPU is expected to be unreliable.
1294 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1295 !command_line->HasSwitch(switches::kDisableBreakpad))
1296 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301297 }
[email protected]6f08af82011-09-15 01:19:031298
1299 // The command line switch kEnableBenchmarking needs to be specified along
1300 // with the kEnableStatsTable switch to ensure that the stats table global
1301 // is initialized correctly.
1302 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1303 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301304}
1305
1306std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431307 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351308 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301309 return g_browser_process->GetApplicationLocale();
1310}
1311
[email protected]597a867b2011-11-18 18:31:201312std::string ChromeContentBrowserClient::GetAcceptLangs(
1313 content::BrowserContext* context) {
1314 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371315 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081316}
1317
[email protected]9ec0f452012-05-31 15:58:531318gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221319 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531320 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081321}
1322
[email protected]a2176792011-05-08 19:30:491323bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091324 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191325 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201326 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201328 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051329 return io_data->GetCookieSettings()->
1330 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491331}
1332
[email protected]ed24fad2011-05-10 22:44:011333bool ChromeContentBrowserClient::AllowGetCookie(
1334 const GURL& url,
1335 const GURL& first_party,
1336 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201337 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011338 int render_process_id,
1339 int render_view_id) {
1340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201341 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051342 bool allow = io_data->GetCookieSettings()->
1343 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011344
[email protected]8093a542011-05-13 07:29:321345 BrowserThread::PostTask(
1346 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031347 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431348 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011349 return allow;
1350}
1351
1352bool ChromeContentBrowserClient::AllowSetCookie(
1353 const GURL& url,
1354 const GURL& first_party,
1355 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201356 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011357 int render_process_id,
1358 int render_view_id,
1359 net::CookieOptions* options) {
1360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201361 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051362 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1363 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1364
[email protected]8093a542011-05-13 07:29:321365 BrowserThread::PostTask(
1366 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031367 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431368 render_view_id, url, first_party, cookie_line, *options,
1369 !allow));
[email protected]ed24fad2011-05-10 22:44:011370 return allow;
1371}
1372
[email protected]d5a19162011-06-30 18:51:541373bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201374 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201376 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431377 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1378 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261379
[email protected]bf510ed2012-06-05 08:31:431380 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1381 // Could we even support per-origin settings?
1382 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541383}
1384
[email protected]5c5a88e2011-11-12 00:45:351385bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351386 const GURL& url,
1387 const string16& name,
1388 const string16& display_name,
1389 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201390 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481391 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351392 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201393 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351394 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1395 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1396
[email protected]62151052012-02-01 18:40:481397 // Record access to database for potential display in UI.
1398 std::vector<std::pair<int, int> >::const_iterator i;
1399 for (i = render_views.begin(); i != render_views.end(); ++i) {
1400 BrowserThread::PostTask(
1401 BrowserThread::UI, FROM_HERE,
1402 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1403 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351404 }
1405
1406 return allow;
1407}
1408
1409bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351410 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201411 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481412 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201414 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351415 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1416 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1417
[email protected]62151052012-02-01 18:40:481418 // Record access to file system for potential display in UI.
1419 std::vector<std::pair<int, int> >::const_iterator i;
1420 for (i = render_views.begin(); i != render_views.end(); ++i) {
1421 BrowserThread::PostTask(
1422 BrowserThread::UI, FROM_HERE,
1423 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1424 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351425 }
1426
1427 return allow;
1428}
1429
[email protected]7c5ff9a2012-03-02 07:42:491430bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1431 const GURL& url,
1432 const string16& name,
1433 content::ResourceContext* context,
1434 const std::vector<std::pair<int, int> >& render_views) {
1435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1436 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1437 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1438 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1439
1440 // Record access to IndexedDB for potential display in UI.
1441 std::vector<std::pair<int, int> >::const_iterator i;
1442 for (i = render_views.begin(); i != render_views.end(); ++i) {
1443 BrowserThread::PostTask(
1444 BrowserThread::UI, FROM_HERE,
1445 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1446 i->first, i->second, url, name, !allow));
1447 }
1448
1449 return allow;
1450}
1451
[email protected]6133f922011-07-01 21:34:341452net::URLRequestContext*
1453ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201454 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421456 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201457 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341458 return io_data->extensions_request_context();
1459 }
1460
1461 return NULL;
1462}
1463
[email protected]317f96c92011-05-31 06:53:411464QuotaPermissionContext*
1465ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1466 return new ChromeQuotaPermissionContext();
1467}
1468
[email protected]848dd042011-06-04 18:24:031469void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171470 int render_process_id,
1471 int render_view_id,
1472 int cert_error,
1473 const net::SSLInfo& ssl_info,
1474 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021475 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031476 bool overridable,
[email protected]d9be47702012-05-16 03:41:221477 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171478 const base::Callback<void(bool)>& callback,
1479 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021480 if (resource_type != ResourceType::MAIN_FRAME) {
1481 // A sub-resource has a certificate error. The user doesn't really
1482 // have a context for making the right decision, so block the
1483 // request hard, without an info bar to allow showing the insecure
1484 // content.
1485 *cancel_request = true;
1486 return;
1487 }
1488
[email protected]f9034cf2011-07-21 12:43:411489 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131490 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171491 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411492 if (!tab) {
1493 NOTREACHED();
1494 return;
1495 }
1496 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501497 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301498 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011499 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1500 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411501 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171502 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411503 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171504 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411505 return;
1506 }
1507 }
1508
[email protected]1e87df32012-09-12 04:53:191509#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231510 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1511 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1512 if (captive_portal_tab_helper)
1513 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191514#endif
1515
[email protected]f9034cf2011-07-21 12:43:411516 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221517 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1518 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031519}
1520
[email protected]c99c442e2011-08-24 11:37:301521void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451522 int render_process_id,
1523 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401524 const net::HttpNetworkSession* network_session,
1525 net::SSLCertRequestInfo* cert_request_info,
1526 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131527 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451528 render_process_id, render_view_id);
1529 if (!tab) {
1530 NOTREACHED();
1531 return;
1532 }
1533
[email protected]6786bf402011-12-03 15:19:451534 GURL requesting_url("https://" + cert_request_info->host_and_port);
1535 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1536 << cert_request_info->host_and_port;
1537
[email protected]627e0512011-12-21 22:55:301538 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451539 scoped_ptr<Value> filter(
1540 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1541 requesting_url,
1542 requesting_url,
1543 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1544 std::string(), NULL));
1545
1546 if (filter.get()) {
1547 // Try to automatically select a client certificate.
1548 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1549 DictionaryValue* filter_dict =
1550 static_cast<DictionaryValue*>(filter.get());
1551
1552 const std::vector<scoped_refptr<net::X509Certificate> >&
1553 all_client_certs = cert_request_info->client_certs;
1554 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1555 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1556 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401557 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451558 return;
1559 }
1560 }
1561 } else {
1562 NOTREACHED();
1563 }
1564 }
1565
[email protected]11feec322012-09-18 03:58:521566 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1567 if (!ssl_tab_helper) {
1568 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451569 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141570 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401571 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451572 return;
1573 }
[email protected]11feec322012-09-18 03:58:521574 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401575 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451576}
1577
[email protected]3b455502012-12-11 18:22:581578void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451579 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581580 net::CertificateMimeType cert_type,
1581 const void* cert_data,
1582 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451583 int render_process_id,
1584 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581585 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1586 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451587}
1588
[email protected]dc73a7b2012-03-25 15:27:181589content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561590 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181591}
1592
[email protected]941623e2011-06-07 23:06:041593void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1594 const GURL& source_origin,
1595 int callback_context,
1596 int render_process_id,
1597 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111598#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1600 WebContents* contents =
1601 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1602 if (!contents) {
[email protected]941623e2011-06-07 23:06:041603 NOTREACHED();
1604 return;
1605 }
1606
[email protected]d0d9c3ee2012-06-19 03:07:021607 // Skip showing the infobar if the request comes from an extension, and that
1608 // extension has the 'notify' permission. (If the extension does not have the
1609 // permission, the user will still be prompted.)
1610 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131611 ExtensionService* service =
1612 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]d0d9c3ee2012-06-19 03:07:021613 const Extension* extension = !service ? NULL :
1614 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1615 source_origin));
[email protected]eb4832a2012-12-08 01:57:521616 RenderViewHost* rvh =
1617 RenderViewHost::FromID(render_process_id, render_view_id);
1618 if (IsExtensionWithPermissionOrSuggestInConsole(
1619 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021620 if (rvh)
1621 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1622 return;
1623 }
1624
1625 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371626 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021627 notifications->RequestPermission(source_origin, render_process_id,
1628 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111629#else
1630 NOTIMPLEMENTED();
1631#endif
[email protected]941623e2011-06-07 23:06:041632}
1633
1634WebKit::WebNotificationPresenter::Permission
1635 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021636 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201637 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021638 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111639#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201641 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021642 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1643 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061644 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041645 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041646
1647 // Fall back to the regular notification preferences, which works on an
1648 // origin basis.
1649 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371650 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041651 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111652#else
1653 return WebKit::WebNotificationPresenter::PermissionAllowed;
1654#endif
[email protected]941623e2011-06-07 23:06:041655}
1656
1657void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171658 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041659 int render_process_id,
1660 int render_view_id,
1661 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111662#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041663 RenderViewHost* rvh = RenderViewHost::FromID(
1664 render_process_id, render_view_id);
1665 if (!rvh) {
1666 NOTREACHED();
1667 return;
1668 }
1669
[email protected]9f76c1e2012-03-05 15:15:581670 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301671 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041672 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371673 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041674 service->ShowDesktopNotification(
1675 params, render_process_id, render_view_id,
1676 worker ? DesktopNotificationService::WorkerNotification :
1677 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111678#else
1679 NOTIMPLEMENTED();
1680#endif
[email protected]941623e2011-06-07 23:06:041681}
1682
1683void ChromeContentBrowserClient::CancelDesktopNotification(
1684 int render_process_id,
1685 int render_view_id,
1686 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111687#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041688 RenderViewHost* rvh = RenderViewHost::FromID(
1689 render_process_id, render_view_id);
1690 if (!rvh) {
1691 NOTREACHED();
1692 return;
1693 }
1694
[email protected]9f76c1e2012-03-05 15:15:581695 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301696 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041697 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371698 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041699 service->CancelDesktopNotification(
1700 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111701#else
1702 NOTIMPLEMENTED();
1703#endif
[email protected]941623e2011-06-07 23:06:041704}
1705
[email protected]9f3fba52011-06-08 20:37:191706bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351707 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021708 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191709 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201710 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011711 int render_process_id,
1712 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191713 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011714
1715 *no_javascript_access = false;
1716
[email protected]9f3fba52011-06-08 20:37:191717 // If the opener is trying to create a background window but doesn't have
1718 // the appropriate permission, fail the attempt.
1719 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201720 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531721 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1722
[email protected]03b6d552012-03-29 04:03:011723 if (!map->SecurityOriginHasAPIPermission(
1724 source_origin,
1725 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061726 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011727 return false;
1728 }
1729
[email protected]7b54ca02012-03-02 18:06:531730 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1731 // return a recently installed Extension even if this CanCreateWindow call
1732 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011733 // because the permission check above would have caused an early return
1734 // already. We must use the full URL to find hosted apps, though, and not
1735 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531736 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351737 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291738 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011739 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191740 }
[email protected]056efdc2013-04-06 00:14:531741
1742 // No new browser window (popup or tab) in app mode.
1743 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1744 chrome::IsRunningInForcedAppMode()) {
1745 return false;
1746 }
1747
[email protected]9f3fba52011-06-08 20:37:191748 return true;
1749}
1750
1751std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201752 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191753 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1754 // Check if it's an extension-created worker, in which case we want to use
1755 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201756 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191757 const Extension* extension =
1758 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1759 return extension ? extension->name() : std::string();
1760}
1761
[email protected]99907362012-01-11 05:41:401762void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1763 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171764}
1765
[email protected]c52b2892012-03-07 11:01:021766content::SpeechRecognitionManagerDelegate*
1767 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321768#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021769 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321770#else
1771 return NULL;
1772#endif
[email protected]66cfec62012-02-24 17:57:511773}
1774
[email protected]ae6e9912011-07-27 01:18:281775net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1776 return g_browser_process->net_log();
1777}
1778
[email protected]32538d92011-08-25 00:09:231779AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1780 return new ChromeAccessTokenStore();
1781}
1782
[email protected]dbae6b02011-06-29 23:51:411783bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011784 return true;
[email protected]dbae6b02011-06-29 23:51:411785}
1786
[email protected]64d69de42012-02-06 00:19:541787void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321788 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061789 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581790 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061791 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061792
[email protected]f3986f82012-01-03 20:00:061793 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541794 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061795 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541796 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061797 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541798 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061799 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541800 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061801 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541802 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061803 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541804 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031805 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1806 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061807
[email protected]64d69de42012-02-06 00:19:541808 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401809 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541810 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401811 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541812 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401813 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541814 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401815 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061816
[email protected]ddf72142012-05-22 04:52:401817 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061818
[email protected]64d69de42012-02-06 00:19:541819 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401820 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541821 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061822 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541823 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061824 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1825 const DictionaryValue* inspector_settings =
1826 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1827 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181828 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1829 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061830 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181831 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541832 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181833 std::make_pair(iter.key(), value));
1834 }
[email protected]f3986f82012-01-03 20:00:061835 }
1836 }
[email protected]64d69de42012-02-06 00:19:541837 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061838
[email protected]ddf72142012-05-22 04:52:401839 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541840 web_prefs->javascript_enabled = false;
1841 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1842 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401843 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541844 web_prefs->plugins_enabled = false;
1845 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1846 web_prefs->java_enabled = false;
1847 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401848 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061849
[email protected]64d69de42012-02-06 00:19:541850 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1851 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061852
[email protected]64d69de42012-02-06 00:19:541853 web_prefs->memory_info_enabled =
1854 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1855 web_prefs->allow_displaying_insecure_content =
1856 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1857 web_prefs->allow_running_insecure_content =
1858 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321859#if defined(OS_ANDROID)
1860 web_prefs->font_scale_factor =
1861 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1862 web_prefs->force_enable_zoom =
1863 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451864#if defined(GOOGLE_TV)
1865 web_prefs->user_gesture_required_for_media_playback = false;
1866#endif
[email protected]d3b935f2012-10-19 23:14:321867#endif
[email protected]9d06d88d2012-02-23 22:37:081868 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061869
[email protected]64d69de42012-02-06 00:19:541870 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151871 UserStyleSheetWatcher* user_style_sheet_watcher =
1872 UserStyleSheetWatcherFactory::GetForProfile(profile);
1873 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541874 web_prefs->user_style_sheet_enabled = true;
1875 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151876 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541877 } else {
1878 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061879 }
1880
[email protected]cfadadd2013-04-03 04:43:021881 web_prefs->asynchronous_spell_checking_enabled = true;
1882 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:571883
[email protected]64d69de42012-02-06 00:19:541884 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061885 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541886 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061887 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541888 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061889 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1890
1891 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541892 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061893 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541894 web_prefs->default_encoding);
1895 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401896 prefs->ClearPref(prefs::kDefaultCharset);
1897 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061898 }
[email protected]64d69de42012-02-06 00:19:541899 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061900
[email protected]88ecf66d2012-12-11 22:53:471901 if (content::IsForceCompositingModeEnabled())
1902 web_prefs->force_compositing_mode = true;
1903
[email protected]299d7f12012-05-23 05:31:151904 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:231905 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131906 ExtensionService* service =
1907 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061908 if (service) {
[email protected]1bc28312012-11-08 08:31:531909 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1910 const Extension* extension = service->extensions()->GetByID(url.host());
1911 // Ensure that we are only granting extension preferences to URLs with
1912 // the correct scheme. Without this check, chrome-guest:// schemes used by
1913 // webview tags as well as hosts that happen to match the id of an
1914 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421915 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531916 extension_webkit_preferences::SetPreferences(
1917 extension, view_type, web_prefs);
1918 }
[email protected]f3986f82012-01-03 20:00:061919 }
1920
[email protected]cb2edf22013-04-01 20:25:231921 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541922 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:231923 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061924 // Disable all kinds of acceleration for background pages.
1925 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541926 web_prefs->force_compositing_mode = false;
1927 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061928 }
[email protected]2e21fe292012-03-02 22:52:321929
1930#if defined(FILE_MANAGER_EXTENSION)
1931 // Override the default of suppressing HW compositing for WebUI pages for the
1932 // file manager, which is implemented using WebUI but wants HW acceleration
1933 // for video decode & render.
1934 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1935 web_prefs->accelerated_compositing_enabled = true;
1936 web_prefs->accelerated_2d_canvas_enabled = true;
1937 }
1938#endif
[email protected]181a95ee2011-07-12 19:26:361939}
1940
1941void ChromeContentBrowserClient::UpdateInspectorSetting(
1942 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061943 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581944 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061945 DictionaryPrefUpdate update(
1946 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1947 prefs::kWebKitInspectorSettings);
1948 DictionaryValue* inspector_settings = update.Get();
1949 inspector_settings->SetWithoutPathExpansion(key,
1950 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361951}
1952
[email protected]b8148ac2011-07-13 22:03:251953void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1954 BrowserURLHandler* handler) {
1955 // Add the default URL handlers.
1956 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1957 BrowserURLHandler::null_handler());
1958 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1959 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1960
[email protected]b3adbd02011-11-30 22:23:271961 // about: handler. Must come before chrome: handler, since it will
1962 // rewrite about: urls to chrome: URLs and then expect chrome: to
1963 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251964 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1965 BrowserURLHandler::null_handler());
1966 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241967 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251968}
1969
1970void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371971 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581972 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471973 BrowsingDataRemover* remover =
1974 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551975 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1976 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251977 // BrowsingDataRemover takes care of deleting itself when done.
1978}
1979
1980void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371981 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581982 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471983 BrowsingDataRemover* remover =
1984 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231985 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551986 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251987 // BrowsingDataRemover takes care of deleting itself when done.
1988}
1989
[email protected]650b2d52013-02-10 03:41:451990base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:321991 return download_util::GetDefaultDownloadDirectory();
1992}
1993
[email protected]c9b6eb62011-10-18 20:49:391994std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1995 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1996}
1997
[email protected]b7631cc2012-09-15 05:08:381998void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1999 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542000#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382001 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2002 scoped_ptr<ppapi::host::HostFactory>(
2003 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542004#endif
[email protected]b7631cc2012-09-15 05:08:382005}
2006
[email protected]0c7193742012-11-07 19:05:032007content::BrowserPpapiHost*
2008 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2009 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132010 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032011 while (!iter.Done()) {
2012 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2013 if (host->process() &&
2014 host->process()->GetData().id == plugin_process_id) {
2015 // Found the plugin.
2016 return host->browser_ppapi_host();
2017 }
2018 ++iter;
2019 }
2020 return NULL;
2021}
2022
[email protected]7b38b192013-03-23 18:39:312023bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2024 content::BrowserContext* browser_context, const GURL& site_url) {
2025 if (CommandLine::ForCurrentProcess()->HasSwitch(
2026 switches::kEnableBrowserPluginForAllViewTypes))
2027 return true;
2028
2029 Profile* profile = Profile::FromBrowserContext(browser_context);
2030 ExtensionService* service =
2031 extensions::ExtensionSystem::Get(profile)->extension_service();
2032 if (!service)
2033 return false;
2034
2035 const Extension* extension = service->extensions()->
2036 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2037 if (!extension)
2038 return false;
2039
2040 return extension->HasAPIPermission(APIPermission::kWebView);
2041}
2042
[email protected]38cd8f7f2012-06-15 22:06:072043bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582044 content::BrowserContext* browser_context,
2045 const GURL& url,
2046 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:292047 if (!url.is_valid())
2048 return false;
2049
2050 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:422051 if (url.SchemeIs(extensions::kExtensionScheme) &&
2052 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:292053 return true;
[email protected]885c0e92012-11-13 20:27:422054 }
[email protected]a658d452012-03-02 12:45:292055
[email protected]9a5940d2012-04-27 19:16:232056 Profile* profile = Profile::FromBrowserContext(browser_context);
2057 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:192058 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:132059 extensions::ExtensionSystem::Get(profile)->extension_service();
2060 if (extension_service) {
2061 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:232062 GetExtensionOrAppByURL(ExtensionURLInfo(url));
2063 }
2064
[email protected]f237c0f2012-03-10 07:49:102065 // Need to check this now and not on construction because otherwise it won't
2066 // work with browser_tests.
2067 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2068 std::string allowed_list =
2069 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:232070 if (allowed_list == "*") {
2071 // The wildcard allows socket API only for packaged and platform apps.
2072 return extension &&
[email protected]1d5e58b2013-01-31 08:41:402073 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
2074 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:232075 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:392076 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:102077 while (t.GetNext()) {
2078 if (t.token() == host)
2079 return true;
2080 }
2081 }
2082
[email protected]a658d452012-03-02 12:45:292083 if (!extension)
2084 return false;
2085
[email protected]157cc902012-11-02 06:31:582086 extensions::SocketPermission::CheckParam extension_params(
2087 params.type, params.host, params.port);
2088 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
2089 &extension_params))
[email protected]a658d452012-03-02 12:45:292090 return true;
2091
2092 return false;
[email protected]e461da2f2012-02-16 19:06:402093}
2094
[email protected]650b2d52013-02-10 03:41:452095base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2096 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142097 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2098 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2099}
2100
[email protected]a28e3302013-02-03 03:50:432101ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2102 WebContents* web_contents) {
2103 return new ChromeSelectFilePolicy(web_contents);
2104}
2105
[email protected]e60c0232011-11-11 19:56:352106#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182107void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2108 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382109 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082110 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392111#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452112 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392113 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2114 DCHECK(!data_path.empty());
2115
2116 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452117 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392118 base::PlatformFile f =
2119 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2120 DCHECK(f != base::kInvalidPlatformFileValue);
2121 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2122 FileDescriptor(f, true)));
2123
[email protected]650b2d52013-02-10 03:41:452124 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392125 data_path.AppendASCII("chrome_100_percent.pak");
2126 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2127 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372128 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392129 FileDescriptor(f, true)));
2130
2131 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452132 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392133 GetLocaleFilePath(locale, false);
2134 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2135 DCHECK(f != base::kInvalidPlatformFileValue);
2136 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2137 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382138
[email protected]650b2d52013-02-10 03:41:452139 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372140 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2141 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2142 DCHECK(f != base::kInvalidPlatformFileValue);
2143 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2144 FileDescriptor(f, true)));
2145
[email protected]40da3e0c2012-10-24 22:03:382146#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432147 if (IsCrashReporterEnabled()) {
2148 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2149 if (f == base::kInvalidPlatformFileValue) {
2150 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2151 "be disabled for this process.";
2152 } else {
2153 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2154 FileDescriptor(f, true)));
2155 }
[email protected]40da3e0c2012-10-24 22:03:382156 }
2157#endif // defined(USE_LINUX_BREAKPAD)
2158
2159#else
2160 int crash_signal_fd = GetCrashSignalFD(command_line);
2161 if (crash_signal_fd >= 0) {
2162 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2163 FileDescriptor(crash_signal_fd,
2164 false)));
2165 }
[email protected]29699c22012-10-03 23:57:392166#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302167}
[email protected]e60c0232011-11-11 19:56:352168#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302169
[email protected]4a65826d2011-08-25 16:04:012170#if defined(OS_WIN)
2171const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2172 return chrome::kBrowserResourcesDll;
2173}
[email protected]34f48682013-03-20 00:30:182174
2175void ChromeContentBrowserClient::PreSpawnRenderer(
2176 sandbox::TargetPolicy* policy,
2177 bool* success) {
2178 // This code is duplicated in nacl_exe_win_64.cc.
2179 // Allow the server side of a pipe restricted to the "chrome.nacl."
2180 // namespace so that it cannot impersonate other system or other chrome
2181 // service pipes.
2182 sandbox::ResultCode result = policy->AddRule(
2183 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2184 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2185 L"\\\\.\\pipe\\chrome.nacl.*");
2186 if (result != sandbox::SBOX_ALL_OK) {
2187 *success = false;
2188 return;
2189 }
2190
2191 // Renderers need to send named pipe handles and shared memory
2192 // segment handles to NaCl loader processes.
2193 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2194 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2195 L"File");
2196 if (result != sandbox::SBOX_ALL_OK) {
2197 *success = false;
2198 return;
2199 }
2200}
[email protected]4a65826d2011-08-25 16:04:012201#endif
2202
[email protected]37a72af2011-06-13 05:42:012203#if defined(USE_NSS)
2204crypto::CryptoModuleBlockingPasswordDelegate*
2205 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2206 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292207 return chrome::NewCryptoModuleBlockingDialogDelegate(
2208 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012209}
2210#endif
2211
[email protected]d977f9c2011-03-14 16:10:262212} // namespace chrome