blob: c51859e0ced7e6fcf7517e0c66d60202763e3211 [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]eabbfb12013-04-05 23:28:3513#include "base/lazy_instance.h"
[email protected]29699c22012-10-03 23:57:3914#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5715#include "base/prefs/pref_service.h"
[email protected]f4ebe772013-02-02 00:21:3916#include "base/strings/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0617#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3018#include "chrome/app/breakpad_mac.h"
[email protected]056efdc2013-04-06 00:14:5319#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]b8148ac2011-07-13 22:03:2520#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3021#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4722#include "chrome/browser/browsing_data/browsing_data_helper.h"
23#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1224#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4125#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4126#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5627#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0528#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4529#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3230#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0831#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3232#include "chrome/browser/download/download_util.h"
[email protected]24665682013-02-25 20:59:3833#include "chrome/browser/extensions/activity_log.h"
[email protected]2b33dcd02012-03-18 01:34:1634#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0635#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0436#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3337#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2638#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0839#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2540#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0641#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5242#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2343#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1244#include "chrome/browser/google/google_util.h"
[email protected]11158e2d2013-02-01 02:31:5645#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0446#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]0c7193742012-11-07 19:05:0347#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2848#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0449#include "chrome/browser/notifications/desktop_notification_service.h"
50#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4251#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5652#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0653#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4154#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5055#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0756#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4157#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1458#include "chrome/browser/printing/printing_message_filter.h"
59#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3260#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0661#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1462#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3863#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4364#include "chrome/browser/search/instant_service.h"
65#include "chrome/browser/search/instant_service_factory.h"
66#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1467#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0268#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4669#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5870#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0371#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5272#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4573#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5474#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4375#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]b5d73422012-06-02 23:46:4476#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5077#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]970c63e2013-03-07 00:25:3078#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
[email protected]f3986f82012-01-03 20:00:0679#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1580#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2781#include "chrome/browser/validation_message_message_filter.h"
[email protected]b80f68432011-05-02 17:22:3082#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0183#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1484#include "chrome/common/chrome_paths.h"
[email protected]f3b357692013-03-22 05:16:1385#include "chrome/common/chrome_process_type.h"
[email protected]b80f68432011-05-02 17:22:3086#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2987#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0488#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3889#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4490#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4391#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]157cc902012-11-02 06:31:5892#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3493#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1294#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3895#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0996#include "chrome/common/url_constants.h"
[email protected]75fee372013-03-06 00:42:4497#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:4398#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3099#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38100#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:31101#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03102#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59103#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36104#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30105#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33106#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05107#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33108#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19109#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10110#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43111#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18112#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23113#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42114#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39115#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23116#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53117#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58118#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34119#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06120#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57121#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38122#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39123#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08124#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36125#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04126#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26127
[email protected]b48c9182011-10-26 18:03:30128#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38129#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18130#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38131#elif defined(OS_MACOSX)
132#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56133#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30134#elif defined(OS_CHROMEOS)
135#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49136#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]931d1042013-04-05 17:50:44137#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26138#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30139#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09140#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38141#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09142#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39143#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30144#elif defined(OS_POSIX)
145#include "chrome/browser/chrome_browser_main_posix.h"
146#endif
147
[email protected]6653c192012-04-10 22:52:44148#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30149#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12150#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43151#endif
[email protected]b80f68432011-05-02 17:22:30152
[email protected]1e87df32012-09-12 04:53:19153#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
154#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
155#endif
156
[email protected]16dc42452013-04-09 04:37:19157#if defined(ENABLE_MESSAGE_CENTER)
158#include "ui/message_center/message_center_util.h"
159#endif
160
[email protected]29699c22012-10-03 23:57:39161#if defined(OS_ANDROID)
162#include "ui/base/ui_base_paths.h"
163#endif
164
[email protected]37a72af2011-06-13 05:42:01165#if defined(USE_NSS)
166#include "chrome/browser/ui/crypto_module_password_dialog.h"
167#endif
168
[email protected]d5bcd06f2013-04-21 08:07:24169#if !defined(OS_CHROMEOS)
170#include "chrome/browser/signin/signin_manager.h"
171#include "chrome/browser/signin/signin_manager_factory.h"
172#endif
173
[email protected]02250952013-04-24 23:52:53174#if !defined(OS_ANDROID)
175#include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h"
176#endif
177
[email protected]c7abd422012-09-25 00:20:08178using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47179using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03180using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39181using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31182using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59183using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08184using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00185using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11186using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33187using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13188using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06189using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34190using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40191using extensions::Manifest;
[email protected]6717bf272012-05-11 23:31:25192using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39193
[email protected]c5dbef02011-05-13 05:06:09194namespace {
195
[email protected]eabbfb12013-04-05 23:28:35196// Cached version of the locale so we can return the locale on the I/O
197// thread.
198base::LazyInstance<std::string> g_io_thread_application_locale;
199
[email protected]e461da2f2012-02-16 19:06:40200const char* kPredefinedAllowedSocketOrigins[] = {
201 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18202 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45203 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
204 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
205 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
206 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35207 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54208 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
209 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
210 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
211 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
212 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
213 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38214 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58215 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
216 "iabmpiboiopbgfabjmgeedhcmjenhbla" // see crbug.com/165080
[email protected]e461da2f2012-02-16 19:06:40217};
218
[email protected]f8f93eb2012-09-25 03:06:24219// Returns a copy of the given url with its host set to given host and path set
220// to given path. Other parts of the url will be the same.
221GURL ReplaceURLHostAndPath(const GURL& url,
222 const std::string& host,
223 const std::string& path) {
224 url_canon::Replacements<char> replacements;
225 replacements.SetHost(host.c_str(),
226 url_parse::Component(0, host.length()));
227 replacements.SetPath(path.c_str(),
228 url_parse::Component(0, path.length()));
229 return url.ReplaceComponents(replacements);
230}
231
232// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
233GURL AddUberHost(const GURL& url) {
234 const std::string uber_host = chrome::kChromeUIUberHost;
235 const std::string new_path = url.host() + url.path();
236
237 return ReplaceURLHostAndPath(url, uber_host, new_path);
238}
239
[email protected]045bf7c2012-09-28 20:27:36240// If url->host() is "chrome" and url->path() has characters other than the
241// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
242// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24243bool RemoveUberHost(GURL* url) {
244 if (url->host() != chrome::kChromeUIUberHost)
245 return false;
246
[email protected]045bf7c2012-09-28 20:27:36247 if (url->path().empty() || url->path() == "/")
248 return false;
249
[email protected]f8f93eb2012-09-25 03:06:24250 const std::string old_path = url->path();
251
252 const std::string::size_type separator = old_path.find('/', 1);
253 std::string new_host;
254 std::string new_path;
255 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36256 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24257 } else {
258 new_host = old_path.substr(1, separator - 1);
259 new_path = old_path.substr(separator);
260 }
261
262 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
263
264 return true;
265}
266
[email protected]b8148ac2011-07-13 22:03:25267// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42268bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24269 // Do not handle special URLs such as "about:foo"
270 if (!url->host().empty()) {
271 const GURL chrome_url = AddUberHost(*url);
272
273 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
274 // be called.
275 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
276 browser_context, chrome_url))
277 return true;
278 }
279
[email protected]863f70a2012-01-27 02:05:50280 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
281 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25282 return false;
283
[email protected]fe69558d2012-03-12 11:34:49284#if defined(OS_CHROMEOS)
285 // Special case : in ChromeOS in Guest mode bookmarks and history are
286 // disabled for security reasons. New tab page explains the reasons, so
287 // we redirect user to new tab page.
288 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
289 if (url->SchemeIs(chrome::kChromeUIScheme) &&
290 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
291 url->DomainIs(chrome::kChromeUIHistoryHost))) {
292 // Rewrite with new tab URL
293 *url = GURL(chrome::kChromeUINewTabURL);
294 }
295 }
296#endif
297
[email protected]b8148ac2011-07-13 22:03:25298 // Special case the new tab page. In older versions of Chrome, the new tab
299 // page was hosted at chrome-internal:<blah>. This might be in people's saved
300 // sessions or bookmarks, so we say any URL with that scheme triggers the new
301 // tab page.
302 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
303 // Rewrite it with the proper new tab URL.
304 *url = GURL(chrome::kChromeUINewTabURL);
305 }
306
307 return true;
308}
309
[email protected]f8f93eb2012-09-25 03:06:24310// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
311// "chrome://foo/".
312bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
313 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
314 return false;
315
316 return RemoveUberHost(url);
317}
318
[email protected]8d3132f62011-10-12 07:13:42319// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
320// below. Extension, and isolated apps require different privileges to be
321// granted to their RenderProcessHosts. This classification allows us to make
322// sure URLs are served by hosts with the right set of privileges.
323enum RenderProcessHostPrivilege {
324 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45325 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42326 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45327 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42328};
329
330RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
331 const GURL& url,
332 ExtensionService* service) {
333 // Default to a normal renderer cause it is lower privileged. This should only
334 // occur if the URL on a site instance is either malformed, or uninitialized.
335 // If it is malformed, then there is no need for better privileges anyways.
336 // If it is uninitialized, but eventually settles on being an a scheme other
337 // than normal webrenderer, the navigation logic will correct us out of band
338 // anyways.
339 if (!url.is_valid())
340 return PRIV_NORMAL;
341
[email protected]885c0e92012-11-13 20:27:42342 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44343 const Extension* extension =
344 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43345 if (extension &&
346 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42347 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45348 if (extension && extension->is_hosted_app())
349 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42350
351 return PRIV_EXTENSION;
352 }
353
354 return PRIV_NORMAL;
355}
356
357RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30358 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46359 extensions::ProcessMap* process_map,
360 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46361 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30362 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46363 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21364 return PRIV_NORMAL;
365
[email protected]6f371442011-11-09 06:45:46366 for (std::set<std::string>::iterator iter = extension_ids.begin();
367 iter != extension_ids.end(); ++iter) {
368 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43369 if (extension &&
370 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42371 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45372 if (extension && extension->is_hosted_app())
373 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42374 }
375
[email protected]676f6ab2011-10-19 20:23:21376 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42377}
378
[email protected]6786bf402011-12-03 15:19:45379bool CertMatchesFilter(const net::X509Certificate& cert,
380 const base::DictionaryValue& filter) {
381 // TODO(markusheintz): This is the minimal required filter implementation.
382 // Implement a better matcher.
383
384 // An empty filter matches any client certificate since no requirements are
385 // specified at all.
386 if (filter.empty())
387 return true;
388
389 std::string common_name;
390 if (filter.GetString("ISSUER.CN", &common_name) &&
391 (cert.issuer().common_name == common_name)) {
392 return true;
393 }
394 return false;
395}
396
[email protected]f3986f82012-01-03 20:00:06397// Fills |map| with the per-script font prefs under path |map_name|.
398void FillFontFamilyMap(const PrefService* prefs,
399 const char* map_name,
400 WebPreferences::ScriptFontFamilyMap* map) {
401 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
402 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
403 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
404 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23405 if (!font_family.empty())
406 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06407 }
408}
409
[email protected]a1733df2012-06-22 11:24:18410#if defined(OS_POSIX) && !defined(OS_MACOSX)
411int GetCrashSignalFD(const CommandLine& command_line) {
412 if (command_line.HasSwitch(switches::kExtensionProcess)) {
413 ExtensionCrashHandlerHostLinux* crash_handler =
414 ExtensionCrashHandlerHostLinux::GetInstance();
415 return crash_handler->GetDeathSignalSocket();
416 }
417
418 std::string process_type =
419 command_line.GetSwitchValueASCII(switches::kProcessType);
420
421 if (process_type == switches::kRendererProcess)
422 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
423
424 if (process_type == switches::kPluginProcess)
425 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
426
427 if (process_type == switches::kPpapiPluginProcess)
428 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
429
430 if (process_type == switches::kGpuProcess)
431 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
432
433 return -1;
434}
435#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
436
[email protected]7c60f5042013-02-14 03:39:32437// Transforms the input |url| into its "effective URL". The returned URL
[email protected]c5dec6292013-01-25 04:54:52438// facilitates grouping process-per-site. The |url| is transformed, for
439// example, from
440//
441// https://www.google.com/search?espv=1&q=tractors
442//
[email protected]7c60f5042013-02-14 03:39:32443// to the effective URL
[email protected]c5dec6292013-01-25 04:54:52444//
445// chrome-search://www.google.com/search?espv=1&q=tractors
446//
447// Notice the scheme change.
[email protected]7c60f5042013-02-14 03:39:32448//
449// If the input is already an effective URL then that same URL is returned.
450GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
[email protected]165fe422013-03-27 06:34:03451 CHECK(chrome::ShouldAssignURLToInstantRenderer(url, profile))
[email protected]7c60f5042013-02-14 03:39:32452 << "Error granting Instant access.";
[email protected]c5dec6292013-01-25 04:54:52453
454 if (url.SchemeIs(chrome::kChromeSearchScheme))
455 return url;
456
457 GURL effective_url(url);
458
459 // Replace the scheme with "chrome-search:".
460 url_canon::Replacements<char> replacements;
461 std::string search_scheme(chrome::kChromeSearchScheme);
462 replacements.SetScheme(search_scheme.data(),
463 url_parse::Component(0, search_scheme.length()));
464 effective_url = effective_url.ReplaceComponents(replacements);
465 return effective_url;
466}
467
[email protected]d5bcd06f2013-04-21 08:07:24468#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30469GURL GetEffectiveURLForSignin(const GURL& url) {
470 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
471
472 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03473 // Copy the path because the argument to SetPathStr must outlive
474 // the Replacements object.
475 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30476 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03477 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30478 effective_url = effective_url.ReplaceComponents(replacements);
479 return effective_url;
480}
[email protected]d5bcd06f2013-04-21 08:07:24481#endif
[email protected]970c63e2013-03-07 00:25:30482
[email protected]eabbfb12013-04-05 23:28:35483void SetApplicationLocaleOnIOThread(const std::string& locale) {
484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
485 g_io_thread_application_locale.Get() = locale;
486}
487
[email protected]9dbfff12011-07-01 19:37:07488} // namespace
[email protected]c5dbef02011-05-13 05:06:09489
[email protected]d977f9c2011-03-14 16:10:26490namespace chrome {
491
[email protected]e461da2f2012-02-16 19:06:40492ChromeContentBrowserClient::ChromeContentBrowserClient() {
493 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
494 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40495}
496
497ChromeContentBrowserClient::~ChromeContentBrowserClient() {
498}
499
[email protected]bca18382012-06-25 19:15:23500// static
[email protected]c753f142013-02-10 13:14:04501void ChromeContentBrowserClient::RegisterUserPrefs(
502 PrefRegistrySyncable* registry) {
503 registry->RegisterBooleanPref(prefs::kDisable3DAPIs,
504 false,
505 PrefRegistrySyncable::UNSYNCABLE_PREF);
506 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
507 true,
508 PrefRegistrySyncable::UNSYNCABLE_PREF);
509 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo,
510 false,
511 PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23512}
513
[email protected]eabbfb12013-04-05 23:28:35514// static
515void ChromeContentBrowserClient::SetApplicationLocale(
516 const std::string& locale) {
517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
518
519 // This object is guaranteed to outlive all threads so we don't have to
520 // worry about the lack of refcounting and can just post as Unretained.
521 //
522 // The common case is that this function is called early in Chrome startup
523 // before any threads are created (it will also be called later if the user
524 // changes the pref). In this case, there will be no threads created and
525 // posting will fail. When there are no threads, we can just set the string
526 // without worrying about threadsafety.
527 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
528 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
529 g_io_thread_application_locale.Get() = locale;
530 }
531}
532
[email protected]50462bf02011-11-21 19:13:31533content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
534 const content::MainFunctionParams& parameters) {
535 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30536 // Construct the Main browser parts based on the OS type.
537#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31538 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04539#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31540 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30541#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22542 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26543#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31544 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14545#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09546 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30547#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31548 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04549#else
[email protected]b48c9182011-10-26 18:03:30550 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31551 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30552#endif
553
[email protected]c7480942011-11-08 19:18:27554 // Construct additional browser parts. Stages are called in the order in
555 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22556#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41557 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04558#endif
[email protected]c7480942011-11-08 19:18:27559
560#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41561 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27562#endif
563
[email protected]dc04be7c2012-03-15 23:57:49564#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41565 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49566#endif
567
[email protected]e050ef142012-03-21 01:04:24568#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41569 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24570#endif
571
[email protected]95132f52013-04-12 02:19:04572 chrome::AddMetricsExtraParts(main_parts);
573
[email protected]50462bf02011-11-21 19:13:31574 return main_parts;
[email protected]f967b722011-09-07 00:58:04575}
576
[email protected]e94bbcb2012-09-07 05:33:57577std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19578 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57579 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53580 std::string partition_id;
581
582 // The partition ID for webview guest processes is the string value of its
583 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
584 if (site.SchemeIs(chrome::kGuestScheme))
585 partition_id = site.spec();
586
[email protected]056efdc2013-04-06 00:14:53587 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53588 return partition_id;
589}
590
591bool ChromeContentBrowserClient::IsValidStoragePartitionId(
592 content::BrowserContext* browser_context,
593 const std::string& partition_id) {
594 // The default ID is empty and is always valid.
595 if (partition_id.empty())
596 return true;
597
598 return GURL(partition_id).is_valid();
599}
600
601void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
602 content::BrowserContext* browser_context,
603 const GURL& site,
[email protected]14acc642012-11-17 12:20:10604 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53605 std::string* partition_domain,
606 std::string* partition_name,
607 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10608 // Default to the browser-wide storage partition and override based on |site|
609 // below.
610 partition_domain->clear();
611 partition_name->clear();
612 *in_memory = false;
613
[email protected]1bc28312012-11-08 08:31:53614 // For the webview tag, we create special guest processes, which host the
615 // tag content separately from the main application that embeds the tag.
616 // A webview tag can specify both the partition name and whether the storage
617 // for that partition should be persisted. Each tag gets a SiteInstance with
618 // a specially formatted URL, based on the application it is hosted by and
619 // the partition requested by it. The format for that URL is:
620 // chrome-guest://partition_domain/persist?partition_name
621 if (site.SchemeIs(chrome::kGuestScheme)) {
622 // Since guest URLs are only used for packaged apps, there must be an app
623 // id in the URL.
624 CHECK(site.has_host());
625 *partition_domain = site.host();
626 // Since persistence is optional, the path must either be empty or the
627 // literal string.
628 *in_memory = (site.path() != "/persist");
629 // The partition name is user supplied value, which we have encoded when the
630 // URL was created, so it needs to be decoded.
631 *partition_name = net::UnescapeURLComponent(site.query(),
632 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10633 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
634 // If |can_be_default| is false, the caller is stating that the |site|
635 // should be parsed as if it had isolated storage. In particular it is
636 // important to NOT check ExtensionService for the is_storage_isolated()
637 // attribute because this code path is run during Extension uninstall
638 // to do cleanup after the Extension has already been unloaded from the
639 // ExtensionService.
640 bool is_isolated = !can_be_default;
641 if (can_be_default) {
642 const Extension* extension = NULL;
643 Profile* profile = Profile::FromBrowserContext(browser_context);
644 ExtensionService* extension_service =
645 extensions::ExtensionSystem::Get(profile)->extension_service();
646 if (extension_service) {
647 extension = extension_service->extensions()->
648 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43649 if (extension &&
650 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10651 is_isolated = true;
652 }
653 }
654 }
[email protected]1bc28312012-11-08 08:31:53655
[email protected]14acc642012-11-17 12:20:10656 if (is_isolated) {
657 CHECK(site.has_host());
658 // For extensions with isolated storage, the the host of the |site| is
659 // the |partition_domain|. The |in_memory| and |partition_name| are only
660 // used in guest schemes so they are cleared here.
661 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53662 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10663 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53664 }
[email protected]d1198fd2012-08-13 22:50:19665 }
666
[email protected]14acc642012-11-17 12:20:10667 // Assert that if |can_be_default| is false, the code above must have found a
668 // non-default partition. If this fails, the caller has a serious logic
669 // error about which StoragePartition they expect to be in and it is not
670 // safe to continue.
671 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44672}
673
[email protected]38b098f2012-03-14 21:11:57674content::WebContentsViewDelegate*
675 ChromeContentBrowserClient::GetWebContentsViewDelegate(
676 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27677 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32678}
679
[email protected]24665682013-02-25 20:59:38680// Check if the extension activity log is enabled for the profile.
681static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
682 extensions::ActivityLog* activity_log =
683 extensions::ActivityLog::GetInstance(profile);
684 return activity_log->IsLogEnabled();
685}
686
[email protected]44703cc72013-01-24 04:56:06687void ChromeContentBrowserClient::GuestWebContentsCreated(
688 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
689 Profile* profile = Profile::FromBrowserContext(
690 embedder_web_contents->GetBrowserContext());
691 ExtensionService* service =
692 extensions::ExtensionSystem::Get(profile)->extension_service();
693 if (!service)
694 return;
695 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
696 const Extension* extension = service->extensions()->
697 GetExtensionOrAppByURL(ExtensionURLInfo(url));
698 if (!extension)
699 return;
700 std::vector<ExtensionMsg_Loaded_Params> extensions;
701 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
702 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
703}
704
[email protected]f3b1a082011-11-18 00:34:30705void ChromeContentBrowserClient::RenderProcessHostCreated(
706 content::RenderProcessHost* host) {
707 int id = host->GetID();
708 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41709 net::URLRequestContextGetter* context =
710 profile->GetRequestContextForRenderProcess(id);
711
[email protected]f3b1a082011-11-18 00:34:30712 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41713 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55714#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30715 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55716#endif
[email protected]658677f2012-06-09 06:04:02717#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08718 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03719#endif
[email protected]f3b1a082011-11-18 00:34:30720 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02721 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30722 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56723#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21724 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56725#endif
[email protected]43535512013-02-20 20:41:41726 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
727 id, profile, context));
[email protected]2736c032012-05-11 18:06:07728 host->GetChannel()->AddFilter(
729 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27730#if defined(OS_MACOSX)
731 // TODO(tkent): Enable it for other platforms.
732 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
733#endif
[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]d5bcd06f2013-04-21 08:07:24759#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30760 // If the input |url| should be assigned to the Signin renderer, make its
761 // effective URL distinct from other URLs on the signin service's domain.
762 // Note that the signin renderer will be allowed to sign the user in to
763 // Chrome.
764 if (SigninManager::IsWebBasedSigninFlowURL(url))
765 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24766#endif
[email protected]970c63e2013-03-07 00:25:30767
[email protected]c5dec6292013-01-25 04:54:52768 // If the input |url| is part of an installed app, the effective URL is an
769 // extension URL with the ID of that extension as the host. This has the
770 // effect of grouping apps together in a common SiteInstance.
771 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13772 extensions::ExtensionSystem::Get(profile)->extension_service();
773 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08774 return url;
775
[email protected]06bdd2b2012-11-30 18:47:13776 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44777 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08778 if (!extension)
779 return url;
780
[email protected]15877ca2011-11-18 22:40:52781 // Bookmark apps do not use the hosted app process model, and should be
782 // treated as normal URLs.
783 if (extension->from_bookmark())
784 return url;
785
[email protected]36fb2c7c2011-04-04 15:49:08786 // If the URL is part of an extension's web extent, convert it to an
787 // extension URL.
788 return extension->GetResourceURL(url.path());
789}
790
[email protected]056ad2a2011-07-12 02:13:55791bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37792 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52793 // Non-extension, non-Instant URLs should generally use
794 // process-per-site-instance. Because we expect to use the effective URL,
795 // URLs for hosted apps (apart from bookmark apps) should have an extension
796 // scheme by now.
797
798 Profile* profile = Profile::FromBrowserContext(browser_context);
799 if (!profile)
800 return false;
801
[email protected]165fe422013-03-27 06:34:03802 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52803 return true;
804
[email protected]d5bcd06f2013-04-21 08:07:24805#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30806 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
807 return true;
[email protected]d5bcd06f2013-04-21 08:07:24808#endif
[email protected]970c63e2013-03-07 00:25:30809
[email protected]885c0e92012-11-13 20:27:42810 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55811 return false;
812
[email protected]c5dec6292013-01-25 04:54:52813 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13814 extensions::ExtensionSystem::Get(profile)->extension_service();
815 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55816 return false;
817
[email protected]06bdd2b2012-11-30 18:47:13818 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44819 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55820 if (!extension)
821 return false;
822
823 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53824 // permission, or that does not allow JavaScript access to the background
825 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55826 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40827 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06828 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29829 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53830 return false;
831 }
832 }
[email protected]056ad2a2011-07-12 02:13:55833
[email protected]7b54ca02012-03-02 18:06:53834 // Hosted apps that have script access to their background page must use
835 // process per site, since all instances can make synchronous calls to the
836 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55837 return true;
838}
839
[email protected]672c8c12013-03-07 12:30:06840// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41841void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
842 std::vector<std::string>* additional_schemes) {
843 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06844}
845
[email protected]6bd30072013-02-08 18:17:11846net::URLRequestContextGetter*
847ChromeContentBrowserClient::CreateRequestContext(
848 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06849 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11850 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06851 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11852}
853
854net::URLRequestContextGetter*
855ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
856 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40857 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11858 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06859 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11860 Profile* profile = Profile::FromBrowserContext(browser_context);
861 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06862 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11863}
864
[email protected]46fb9442011-12-09 17:57:47865bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
866 return ProfileIOData::IsHandledURL(url);
867}
868
[email protected]2a5221b2011-09-27 23:07:31869bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30870 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31871 const GURL& site_url) {
872 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30873 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52874 // This may be NULL during tests. In that case, just assume any site can
875 // share any host.
876 if (!profile)
877 return true;
878
[email protected]d43f99fe2013-04-03 00:20:14879 // Instant URLs should only be in the instant process and instant process
880 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52881 InstantService* instant_service =
882 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14883 if (instant_service) {
884 bool is_instant_process = instant_service->IsInstantProcess(
885 process_host->GetID());
886 bool should_be_in_instant_process =
887 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
888 if (is_instant_process || should_be_in_instant_process)
889 return is_instant_process && should_be_in_instant_process;
890 }
[email protected]c5dec6292013-01-25 04:54:52891
[email protected]d5bcd06f2013-04-21 08:07:24892#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30893 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
894 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
895 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:24896#endif
[email protected]970c63e2013-03-07 00:25:30897
[email protected]06bdd2b2012-11-30 18:47:13898 ExtensionService* service =
899 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46900 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31901
[email protected]ffa97602011-11-17 17:55:52902 // Don't allow the Task Manager to share a process with anything else.
903 // Otherwise it can affect the renderers it is observing.
904 // Note: we could create another RenderProcessHostPrivilege bucket for
905 // this to allow multiple chrome://tasks instances to share, but that's
906 // a very unlikely case without serious consequences.
907 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
908 return false;
909
[email protected]8d3132f62011-10-12 07:13:42910 // These may be NULL during tests. In that case, just assume any site can
911 // share any host.
[email protected]6f371442011-11-09 06:45:46912 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31913 return true;
914
[email protected]eec0b33c2011-12-05 22:09:45915 // Otherwise, just make sure the process privilege matches the privilege
916 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57917 RenderProcessHostPrivilege privilege_required =
918 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45919 return GetProcessPrivilege(process_host, process_map, service) ==
920 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31921}
922
[email protected]76411f412012-02-22 18:56:06923// This function is trying to limit the amount of processes used by extensions
924// with background pages. It uses a globally set percentage of processes to
925// run such extensions and if the limit is exceeded, it returns true, to
926// indicate to the content module to group extensions together.
927bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
928 content::BrowserContext* browser_context, const GURL& url) {
929 // It has to be a valid URL for us to check for an extension.
930 if (!url.is_valid())
931 return false;
932
933 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19934 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13935 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06936 if (!service)
937 return false;
938
939 // We have to have a valid extension with background page to proceed.
940 const Extension* extension =
941 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
942 if (!extension)
943 return false;
[email protected]9367eabc2013-03-01 01:29:29944 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06945 return false;
946
947 std::set<int> process_ids;
948 size_t max_process_count =
949 content::RenderProcessHost::GetMaxRendererProcessCount();
950
951 // Go through all profiles to ensure we have total count of extension
952 // processes containing background pages, otherwise one profile can
953 // starve the other.
954 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
955 GetLoadedProfiles();
956 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03957 ExtensionProcessManager* epm =
958 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32959 for (ExtensionProcessManager::const_iterator iter =
960 epm->background_hosts().begin();
961 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13962 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32963 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06964 }
965 }
966
967 if (process_ids.size() >
968 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
969 return true;
970 }
971
972 return false;
973}
974
[email protected]6f371442011-11-09 06:45:46975void ChromeContentBrowserClient::SiteInstanceGotProcess(
976 SiteInstance* site_instance) {
977 CHECK(site_instance->HasProcess());
978
979 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02980 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52981 if (!profile)
982 return;
983
984 // Remember the ID of the Instant process to signal the renderer process
985 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:03986 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:32987 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:52988 InstantService* instant_service =
989 InstantServiceFactory::GetForProfile(profile);
990 if (instant_service)
991 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
992 }
993
[email protected]d5bcd06f2013-04-21 08:07:24994#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30995 // We only expect there to be one signin process as we use process-per-site
996 // for signin URLs. The signin process will be cleared from SigninManager
997 // when the renderer is destroyed.
998 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
999 SigninManager* signin_manager =
1000 SigninManagerFactory::GetForProfile(profile);
1001 if (signin_manager)
1002 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
1003 }
[email protected]d5bcd06f2013-04-21 08:07:241004#endif
[email protected]970c63e2013-03-07 00:25:301005
[email protected]06bdd2b2012-11-30 18:47:131006 ExtensionService* service =
1007 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461008 if (!service)
1009 return;
1010
1011 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441012 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591013 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461014 if (!extension)
1015 return;
1016
[email protected]6bc04fd82011-12-04 02:29:351017 service->process_map()->Insert(extension->id(),
1018 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331019 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461020 BrowserThread::PostTask(
1021 BrowserThread::IO, FROM_HERE,
1022 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591023 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461024 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351025 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331026 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461027}
1028
1029void ChromeContentBrowserClient::SiteInstanceDeleting(
1030 SiteInstance* site_instance) {
1031 if (!site_instance->HasProcess())
1032 return;
1033
1034 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021035 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131036 ExtensionService* service =
1037 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461038 if (!service)
1039 return;
1040
1041 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441042 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591043 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461044 if (!extension)
1045 return;
1046
[email protected]6bc04fd82011-12-04 02:29:351047 service->process_map()->Remove(extension->id(),
1048 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331049 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461050 BrowserThread::PostTask(
1051 BrowserThread::IO, FROM_HERE,
1052 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591053 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461054 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351055 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331056 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461057}
1058
[email protected]f05763972012-06-06 18:17:261059bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141060 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081061 const GURL& current_url,
1062 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261063 if (current_url.is_empty()) {
1064 // Always choose a new process when navigating to extension URLs. The
1065 // process grouping logic will combine all of a given extension's pages
1066 // into the same process.
[email protected]885c0e92012-11-13 20:27:421067 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261068 return true;
[email protected]e3daf3c2011-10-05 21:17:081069
[email protected]f05763972012-06-06 18:17:261070 return false;
1071 }
1072
1073 // Also, we must switch if one is an extension and the other is not the exact
1074 // same extension.
[email protected]885c0e92012-11-13 20:27:421075 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1076 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261077 if (current_url.GetOrigin() != new_url.GetOrigin())
1078 return true;
1079 }
1080
[email protected]e9841fbd2013-02-22 23:12:141081 // The checks below only matter if we can retrieve which extensions are
1082 // installed.
1083 Profile* profile =
1084 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1085 ExtensionService* service =
1086 extensions::ExtensionSystem::Get(profile)->extension_service();
1087 if (!service)
1088 return false;
1089
1090 // We must swap if the URL is for an extension and we are not using an
1091 // extension process.
1092 const Extension* new_extension =
1093 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1094 // Ignore all hosted apps except the Chrome Web Store, since they do not
1095 // require their own BrowsingInstance (e.g., postMessage is ok).
1096 if (new_extension &&
1097 new_extension->is_hosted_app() &&
1098 new_extension->id() != extension_misc::kWebStoreAppId)
1099 new_extension = NULL;
1100 if (new_extension &&
1101 site_instance->HasProcess() &&
1102 !service->process_map()->Contains(new_extension->id(),
1103 site_instance->GetProcess()->GetID()))
1104 return true;
1105
[email protected]f05763972012-06-06 18:17:261106 return false;
[email protected]e3daf3c2011-10-05 21:17:081107}
1108
[email protected]395045c2012-05-22 15:04:381109bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1110 content::ResourceContext* resource_context, const GURL& current_url,
1111 const GURL& new_url) {
1112 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1113 return extensions::CrossesExtensionProcessBoundary(
1114 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171115 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381116}
1117
[email protected]763ec4ca2011-04-29 15:48:121118std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1119 const std::string& alias_name) {
1120 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1121}
1122
[email protected]b80f68432011-05-02 17:22:301123void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1124 CommandLine* command_line, int child_process_id) {
1125#if defined(USE_LINUX_BREAKPAD)
1126 if (IsCrashReporterEnabled()) {
1127 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1128 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1129 }
1130#elif defined(OS_MACOSX)
1131 if (IsCrashReporterEnabled()) {
1132 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1133 child_process_logging::GetClientId());
1134 }
1135#endif // OS_MACOSX
1136
[email protected]f1933792011-06-14 00:49:341137 if (logging::DialogsAreSuppressed())
1138 command_line->AppendSwitch(switches::kNoErrorDialogs);
1139
[email protected]b80f68432011-05-02 17:22:301140 std::string process_type =
1141 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171142 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321143
1144 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1145 command_line->AppendSwitch(switches::kChromeFrame);
1146
[email protected]718eab62011-10-05 21:16:521147 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451148 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301149 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1150 if (!user_data_dir.empty())
1151 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1152#if defined(OS_CHROMEOS)
1153 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441154 browser_command_line.GetSwitchValueASCII(
1155 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301156 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441157 command_line->AppendSwitchASCII(
1158 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301159#endif
1160
[email protected]f3b1a082011-11-18 00:34:301161 content::RenderProcessHost* process =
1162 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371163 if (process) {
1164 Profile* profile = Profile::FromBrowserContext(
1165 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131166 ExtensionService* extension_service =
1167 extensions::ExtensionSystem::Get(profile)->extension_service();
1168 if (extension_service) {
1169 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001170 if (process_map && process_map->Contains(process->GetID()))
1171 command_line->AppendSwitch(switches::kExtensionProcess);
1172 }
[email protected]b80f68432011-05-02 17:22:301173
[email protected]a8d851f82011-12-21 00:32:371174 PrefService* prefs = profile->GetPrefs();
1175 // Currently this pref is only registered if applied via a policy.
1176 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1177 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1178 // Turn this policy into a command line switch.
1179 command_line->AppendSwitch(switches::kDisable3DAPIs);
1180 }
[email protected]718eab62011-10-05 21:16:521181
[email protected]a8d851f82011-12-21 00:32:371182 // Disable client-side phishing detection in the renderer if it is
1183 // disabled in the Profile preferences or the browser process.
1184 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1185 !g_browser_process->safe_browsing_detection_service()) {
1186 command_line->AppendSwitch(
1187 switches::kDisableClientSidePhishingDetection);
1188 }
[email protected]0045b0f42012-07-26 11:52:081189
1190 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211191 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521192
1193 InstantService* instant_service =
1194 InstantServiceFactory::GetForProfile(profile);
1195 if (instant_service &&
1196 instant_service->IsInstantProcess(process->GetID()))
1197 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301198
[email protected]d5bcd06f2013-04-21 08:07:241199#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301200 SigninManager* signin_manager =
1201 SigninManagerFactory::GetForProfile(profile);
1202 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1203 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241204#endif
[email protected]47c7ec82012-01-18 03:29:211205 }
[email protected]4287a3d2011-06-13 23:56:511206
[email protected]87552982012-11-02 17:21:401207 if (content::IsThreadedCompositingEnabled())
1208 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1209
[email protected]16dc42452013-04-09 04:37:191210#if defined(ENABLE_MESSAGE_CENTER)
1211 if (message_center::IsRichNotificationEnabled())
1212 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
1213#endif
1214
[email protected]47c7ec82012-01-18 03:29:211215 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511216 static const char* const kSwitchNames[] = {
[email protected]e217c5632013-04-12 19:11:481217 autofill::switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511218 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481219 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511220 switches::kAllowScriptingGallery,
1221 switches::kAppsCheckoutURL,
1222 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311223 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511224 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501225 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531226 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111227 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511228 switches::kDumpHistogramsOnExit,
[email protected]e9cddd52013-03-23 17:37:531229 switches::kEnableAdview,
1230 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211231 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511232 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511233 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511234 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511235 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451236 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481237 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051238 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511239 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291240 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511241 switches::kMemoryProfiling,
1242 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371243 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371244 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511245 switches::kPpapiFlashArgs,
1246 switches::kPpapiFlashInProcess,
1247 switches::kPpapiFlashPath,
1248 switches::kPpapiFlashVersion,
1249 switches::kProfilingAtStart,
1250 switches::kProfilingFile,
1251 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371252 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511253 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291254 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381255 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511256 };
1257
1258 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1259 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171260 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381261 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351262 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381263 switches::kEnableExperimentalExtensionApis,
1264 switches::kWhitelistedExtensionID,
1265 };
1266
1267 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1268 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511269 } else if (process_type == switches::kPluginProcess) {
1270 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441271#if defined(OS_CHROMEOS)
1272 chromeos::switches::kLoginProfile,
1273#endif
[email protected]4287a3d2011-06-13 23:56:511274 switches::kMemoryProfiling,
1275 switches::kSilentDumpOnDCHECK,
1276 switches::kUserDataDir,
1277 };
1278
1279 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1280 arraysize(kSwitchNames));
1281 } else if (process_type == switches::kZygoteProcess) {
1282 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511283 switches::kUserDataDir, // Make logs go to the right file.
1284 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501285 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511286 switches::kPpapiFlashInProcess,
1287 switches::kPpapiFlashPath,
1288 switches::kPpapiFlashVersion,
1289 };
1290
1291 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1292 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111293 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001294 base::FilePath user_data_dir =
1295 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1296 if (!user_data_dir.empty())
1297 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111298 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1299 // because GPU is expected to be unreliable.
1300 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1301 !command_line->HasSwitch(switches::kDisableBreakpad))
1302 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301303 }
[email protected]6f08af82011-09-15 01:19:031304
1305 // The command line switch kEnableBenchmarking needs to be specified along
1306 // with the kEnableStatsTable switch to ensure that the stats table global
1307 // is initialized correctly.
1308 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1309 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301310}
1311
1312std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431313 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351314 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301315 return g_browser_process->GetApplicationLocale();
1316}
1317
[email protected]597a867b2011-11-18 18:31:201318std::string ChromeContentBrowserClient::GetAcceptLangs(
1319 content::BrowserContext* context) {
1320 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371321 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081322}
1323
[email protected]9ec0f452012-05-31 15:58:531324gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221325 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531326 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081327}
1328
[email protected]a2176792011-05-08 19:30:491329bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091330 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191331 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201332 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201334 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051335 return io_data->GetCookieSettings()->
1336 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491337}
1338
[email protected]ed24fad2011-05-10 22:44:011339bool ChromeContentBrowserClient::AllowGetCookie(
1340 const GURL& url,
1341 const GURL& first_party,
1342 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201343 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011344 int render_process_id,
1345 int render_view_id) {
1346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201347 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051348 bool allow = io_data->GetCookieSettings()->
1349 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011350
[email protected]8093a542011-05-13 07:29:321351 BrowserThread::PostTask(
1352 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031353 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431354 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011355 return allow;
1356}
1357
1358bool ChromeContentBrowserClient::AllowSetCookie(
1359 const GURL& url,
1360 const GURL& first_party,
1361 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201362 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011363 int render_process_id,
1364 int render_view_id,
1365 net::CookieOptions* options) {
1366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201367 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051368 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1369 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1370
[email protected]8093a542011-05-13 07:29:321371 BrowserThread::PostTask(
1372 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031373 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431374 render_view_id, url, first_party, cookie_line, *options,
1375 !allow));
[email protected]ed24fad2011-05-10 22:44:011376 return allow;
1377}
1378
[email protected]d5a19162011-06-30 18:51:541379bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201380 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201382 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431383 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1384 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261385
[email protected]bf510ed2012-06-05 08:31:431386 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1387 // Could we even support per-origin settings?
1388 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541389}
1390
[email protected]5c5a88e2011-11-12 00:45:351391bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351392 const GURL& url,
1393 const string16& name,
1394 const string16& display_name,
1395 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201396 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481397 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201399 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351400 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1401 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1402
[email protected]62151052012-02-01 18:40:481403 // Record access to database for potential display in UI.
1404 std::vector<std::pair<int, int> >::const_iterator i;
1405 for (i = render_views.begin(); i != render_views.end(); ++i) {
1406 BrowserThread::PostTask(
1407 BrowserThread::UI, FROM_HERE,
1408 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1409 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351410 }
1411
1412 return allow;
1413}
1414
1415bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351416 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201417 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481418 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201420 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351421 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1422 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1423
[email protected]62151052012-02-01 18:40:481424 // Record access to file system for potential display in UI.
1425 std::vector<std::pair<int, int> >::const_iterator i;
1426 for (i = render_views.begin(); i != render_views.end(); ++i) {
1427 BrowserThread::PostTask(
1428 BrowserThread::UI, FROM_HERE,
1429 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1430 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351431 }
1432
1433 return allow;
1434}
1435
[email protected]7c5ff9a2012-03-02 07:42:491436bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1437 const GURL& url,
1438 const string16& name,
1439 content::ResourceContext* context,
1440 const std::vector<std::pair<int, int> >& render_views) {
1441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1442 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1443 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1444 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1445
1446 // Record access to IndexedDB for potential display in UI.
1447 std::vector<std::pair<int, int> >::const_iterator i;
1448 for (i = render_views.begin(); i != render_views.end(); ++i) {
1449 BrowserThread::PostTask(
1450 BrowserThread::UI, FROM_HERE,
1451 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1452 i->first, i->second, url, name, !allow));
1453 }
1454
1455 return allow;
1456}
1457
[email protected]6133f922011-07-01 21:34:341458net::URLRequestContext*
1459ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201460 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421462 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201463 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341464 return io_data->extensions_request_context();
1465 }
1466
1467 return NULL;
1468}
1469
[email protected]317f96c92011-05-31 06:53:411470QuotaPermissionContext*
1471ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1472 return new ChromeQuotaPermissionContext();
1473}
1474
[email protected]848dd042011-06-04 18:24:031475void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171476 int render_process_id,
1477 int render_view_id,
1478 int cert_error,
1479 const net::SSLInfo& ssl_info,
1480 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021481 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031482 bool overridable,
[email protected]d9be47702012-05-16 03:41:221483 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171484 const base::Callback<void(bool)>& callback,
1485 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021486 if (resource_type != ResourceType::MAIN_FRAME) {
1487 // A sub-resource has a certificate error. The user doesn't really
1488 // have a context for making the right decision, so block the
1489 // request hard, without an info bar to allow showing the insecure
1490 // content.
1491 *cancel_request = true;
1492 return;
1493 }
1494
[email protected]f9034cf2011-07-21 12:43:411495 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131496 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171497 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411498 if (!tab) {
1499 NOTREACHED();
1500 return;
1501 }
1502 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501503 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301504 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011505 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1506 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411507 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171508 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411509 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171510 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411511 return;
1512 }
1513 }
1514
[email protected]1e87df32012-09-12 04:53:191515#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231516 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1517 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1518 if (captive_portal_tab_helper)
1519 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191520#endif
1521
[email protected]f9034cf2011-07-21 12:43:411522 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221523 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1524 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031525}
1526
[email protected]c99c442e2011-08-24 11:37:301527void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451528 int render_process_id,
1529 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401530 const net::HttpNetworkSession* network_session,
1531 net::SSLCertRequestInfo* cert_request_info,
1532 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131533 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451534 render_process_id, render_view_id);
1535 if (!tab) {
1536 NOTREACHED();
1537 return;
1538 }
1539
[email protected]6786bf402011-12-03 15:19:451540 GURL requesting_url("https://" + cert_request_info->host_and_port);
1541 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1542 << cert_request_info->host_and_port;
1543
[email protected]627e0512011-12-21 22:55:301544 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451545 scoped_ptr<Value> filter(
1546 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1547 requesting_url,
1548 requesting_url,
1549 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1550 std::string(), NULL));
1551
1552 if (filter.get()) {
1553 // Try to automatically select a client certificate.
1554 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1555 DictionaryValue* filter_dict =
1556 static_cast<DictionaryValue*>(filter.get());
1557
1558 const std::vector<scoped_refptr<net::X509Certificate> >&
1559 all_client_certs = cert_request_info->client_certs;
1560 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1561 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1562 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401563 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451564 return;
1565 }
1566 }
1567 } else {
1568 NOTREACHED();
1569 }
1570 }
1571
[email protected]11feec322012-09-18 03:58:521572 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1573 if (!ssl_tab_helper) {
1574 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451575 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141576 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401577 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451578 return;
1579 }
[email protected]11feec322012-09-18 03:58:521580 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401581 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451582}
1583
[email protected]3b455502012-12-11 18:22:581584void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451585 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581586 net::CertificateMimeType cert_type,
1587 const void* cert_data,
1588 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451589 int render_process_id,
1590 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581591 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1592 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451593}
1594
[email protected]dc73a7b2012-03-25 15:27:181595content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561596 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181597}
1598
[email protected]941623e2011-06-07 23:06:041599void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1600 const GURL& source_origin,
1601 int callback_context,
1602 int render_process_id,
1603 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111604#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1606 WebContents* contents =
1607 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1608 if (!contents) {
[email protected]941623e2011-06-07 23:06:041609 NOTREACHED();
1610 return;
1611 }
1612
[email protected]d0d9c3ee2012-06-19 03:07:021613 // Skip showing the infobar if the request comes from an extension, and that
1614 // extension has the 'notify' permission. (If the extension does not have the
1615 // permission, the user will still be prompted.)
1616 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011617 ExtensionInfoMap* extension_info_map =
1618 extensions::ExtensionSystem::Get(profile)->info_map();
1619 DesktopNotificationService* notification_service =
1620 DesktopNotificationServiceFactory::GetForProfile(profile);
1621 const Extension* extension = NULL;
1622 if (extension_info_map) {
1623 ExtensionSet extensions;
1624 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1625 source_origin, render_process_id,
1626 extensions::APIPermission::kNotification, &extensions);
1627 for (ExtensionSet::const_iterator iter = extensions.begin();
1628 iter != extensions.end(); ++iter) {
1629 if (notification_service->IsExtensionEnabled((*iter)->id())) {
1630 extension = *iter;
1631 break;
1632 }
1633 }
1634 }
[email protected]eb4832a2012-12-08 01:57:521635 RenderViewHost* rvh =
1636 RenderViewHost::FromID(render_process_id, render_view_id);
1637 if (IsExtensionWithPermissionOrSuggestInConsole(
1638 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021639 if (rvh)
1640 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1641 return;
1642 }
1643
[email protected]c7cd5942013-04-30 03:31:011644 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021645 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111646#else
1647 NOTIMPLEMENTED();
1648#endif
[email protected]941623e2011-06-07 23:06:041649}
1650
1651WebKit::WebNotificationPresenter::Permission
1652 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021653 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201654 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021655 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111656#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201658 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041659
[email protected]c7cd5942013-04-30 03:31:011660 DesktopNotificationService* notification_service =
1661 io_data->GetNotificationService();
1662 if (notification_service) {
1663 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1664 ExtensionSet extensions;
1665 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1666 source_origin, render_process_id,
1667 extensions::APIPermission::kNotification, &extensions);
1668 for (ExtensionSet::const_iterator iter = extensions.begin();
1669 iter != extensions.end(); ++iter) {
1670 if (notification_service->IsExtensionEnabled((*iter)->id()))
1671 return WebKit::WebNotificationPresenter::PermissionAllowed;
1672 }
1673
1674 return notification_service->HasPermission(source_origin);
1675 }
1676
1677 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111678#else
1679 return WebKit::WebNotificationPresenter::PermissionAllowed;
1680#endif
[email protected]941623e2011-06-07 23:06:041681}
1682
1683void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171684 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041685 int render_process_id,
1686 int render_view_id,
1687 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111688#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041689 RenderViewHost* rvh = RenderViewHost::FromID(
1690 render_process_id, render_view_id);
1691 if (!rvh) {
1692 NOTREACHED();
1693 return;
1694 }
1695
[email protected]9f76c1e2012-03-05 15:15:581696 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301697 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041698 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371699 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041700 service->ShowDesktopNotification(
1701 params, render_process_id, render_view_id,
1702 worker ? DesktopNotificationService::WorkerNotification :
1703 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111704#else
1705 NOTIMPLEMENTED();
1706#endif
[email protected]941623e2011-06-07 23:06:041707}
1708
1709void ChromeContentBrowserClient::CancelDesktopNotification(
1710 int render_process_id,
1711 int render_view_id,
1712 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111713#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041714 RenderViewHost* rvh = RenderViewHost::FromID(
1715 render_process_id, render_view_id);
1716 if (!rvh) {
1717 NOTREACHED();
1718 return;
1719 }
1720
[email protected]9f76c1e2012-03-05 15:15:581721 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301722 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041723 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371724 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041725 service->CancelDesktopNotification(
1726 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111727#else
1728 NOTIMPLEMENTED();
1729#endif
[email protected]941623e2011-06-07 23:06:041730}
1731
[email protected]9f3fba52011-06-08 20:37:191732bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351733 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021734 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191735 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201736 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011737 int render_process_id,
1738 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191739 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011740
1741 *no_javascript_access = false;
1742
[email protected]9f3fba52011-06-08 20:37:191743 // If the opener is trying to create a background window but doesn't have
1744 // the appropriate permission, fail the attempt.
1745 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201746 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531747 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1748
[email protected]03b6d552012-03-29 04:03:011749 if (!map->SecurityOriginHasAPIPermission(
1750 source_origin,
1751 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061752 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011753 return false;
1754 }
1755
[email protected]7b54ca02012-03-02 18:06:531756 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1757 // return a recently installed Extension even if this CanCreateWindow call
1758 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011759 // because the permission check above would have caused an early return
1760 // already. We must use the full URL to find hosted apps, though, and not
1761 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531762 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351763 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291764 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011765 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191766 }
[email protected]056efdc2013-04-06 00:14:531767
1768 // No new browser window (popup or tab) in app mode.
1769 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1770 chrome::IsRunningInForcedAppMode()) {
1771 return false;
1772 }
1773
[email protected]9f3fba52011-06-08 20:37:191774 return true;
1775}
1776
1777std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201778 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191779 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1780 // Check if it's an extension-created worker, in which case we want to use
1781 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201782 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191783 const Extension* extension =
1784 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1785 return extension ? extension->name() : std::string();
1786}
1787
[email protected]99907362012-01-11 05:41:401788void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1789 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171790}
1791
[email protected]c52b2892012-03-07 11:01:021792content::SpeechRecognitionManagerDelegate*
1793 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321794#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021795 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321796#else
1797 return NULL;
1798#endif
[email protected]66cfec62012-02-24 17:57:511799}
1800
[email protected]ae6e9912011-07-27 01:18:281801net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1802 return g_browser_process->net_log();
1803}
1804
[email protected]32538d92011-08-25 00:09:231805AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1806 return new ChromeAccessTokenStore();
1807}
1808
[email protected]dbae6b02011-06-29 23:51:411809bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011810 return true;
[email protected]dbae6b02011-06-29 23:51:411811}
1812
[email protected]64d69de42012-02-06 00:19:541813void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321814 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061815 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581816 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061817 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061818
[email protected]f3986f82012-01-03 20:00:061819 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541820 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061821 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541822 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061823 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541824 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061825 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541826 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061827 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541828 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061829 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541830 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031831 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1832 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061833
[email protected]64d69de42012-02-06 00:19:541834 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401835 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541836 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401837 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541838 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401839 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541840 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401841 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061842
[email protected]ddf72142012-05-22 04:52:401843 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061844
[email protected]64d69de42012-02-06 00:19:541845 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401846 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541847 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061848 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541849 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061850 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1851 const DictionaryValue* inspector_settings =
1852 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1853 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181854 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1855 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061856 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181857 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541858 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181859 std::make_pair(iter.key(), value));
1860 }
[email protected]f3986f82012-01-03 20:00:061861 }
1862 }
[email protected]64d69de42012-02-06 00:19:541863 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061864
[email protected]ddf72142012-05-22 04:52:401865 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541866 web_prefs->javascript_enabled = false;
1867 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1868 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401869 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541870 web_prefs->plugins_enabled = false;
1871 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1872 web_prefs->java_enabled = false;
1873 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401874 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061875
[email protected]64d69de42012-02-06 00:19:541876 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1877 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061878
[email protected]64d69de42012-02-06 00:19:541879 web_prefs->memory_info_enabled =
1880 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1881 web_prefs->allow_displaying_insecure_content =
1882 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1883 web_prefs->allow_running_insecure_content =
1884 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321885#if defined(OS_ANDROID)
1886 web_prefs->font_scale_factor =
1887 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1888 web_prefs->force_enable_zoom =
1889 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451890#if defined(GOOGLE_TV)
1891 web_prefs->user_gesture_required_for_media_playback = false;
1892#endif
[email protected]d3b935f2012-10-19 23:14:321893#endif
[email protected]9d06d88d2012-02-23 22:37:081894 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061895
[email protected]64d69de42012-02-06 00:19:541896 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151897 UserStyleSheetWatcher* user_style_sheet_watcher =
1898 UserStyleSheetWatcherFactory::GetForProfile(profile);
1899 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541900 web_prefs->user_style_sheet_enabled = true;
1901 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151902 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541903 } else {
1904 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061905 }
1906
[email protected]cfadadd2013-04-03 04:43:021907 web_prefs->asynchronous_spell_checking_enabled = true;
1908 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:571909
[email protected]64d69de42012-02-06 00:19:541910 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061911 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541912 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061913 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541914 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061915 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1916
1917 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541918 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061919 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541920 web_prefs->default_encoding);
1921 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401922 prefs->ClearPref(prefs::kDefaultCharset);
1923 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061924 }
[email protected]64d69de42012-02-06 00:19:541925 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061926
[email protected]88ecf66d2012-12-11 22:53:471927 if (content::IsForceCompositingModeEnabled())
1928 web_prefs->force_compositing_mode = true;
1929
[email protected]299d7f12012-05-23 05:31:151930 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:231931 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131932 ExtensionService* service =
1933 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061934 if (service) {
[email protected]1bc28312012-11-08 08:31:531935 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1936 const Extension* extension = service->extensions()->GetByID(url.host());
1937 // Ensure that we are only granting extension preferences to URLs with
1938 // the correct scheme. Without this check, chrome-guest:// schemes used by
1939 // webview tags as well as hosts that happen to match the id of an
1940 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421941 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531942 extension_webkit_preferences::SetPreferences(
1943 extension, view_type, web_prefs);
1944 }
[email protected]f3986f82012-01-03 20:00:061945 }
1946
[email protected]cb2edf22013-04-01 20:25:231947 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541948 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:231949 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061950 // Disable all kinds of acceleration for background pages.
1951 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541952 web_prefs->force_compositing_mode = false;
1953 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061954 }
[email protected]2e21fe292012-03-02 22:52:321955
1956#if defined(FILE_MANAGER_EXTENSION)
1957 // Override the default of suppressing HW compositing for WebUI pages for the
1958 // file manager, which is implemented using WebUI but wants HW acceleration
1959 // for video decode & render.
1960 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1961 web_prefs->accelerated_compositing_enabled = true;
1962 web_prefs->accelerated_2d_canvas_enabled = true;
1963 }
1964#endif
[email protected]181a95ee2011-07-12 19:26:361965}
1966
1967void ChromeContentBrowserClient::UpdateInspectorSetting(
1968 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061969 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581970 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061971 DictionaryPrefUpdate update(
1972 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1973 prefs::kWebKitInspectorSettings);
1974 DictionaryValue* inspector_settings = update.Get();
1975 inspector_settings->SetWithoutPathExpansion(key,
1976 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361977}
1978
[email protected]b8148ac2011-07-13 22:03:251979void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1980 BrowserURLHandler* handler) {
1981 // Add the default URL handlers.
1982 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1983 BrowserURLHandler::null_handler());
1984 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1985 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1986
[email protected]b3adbd02011-11-30 22:23:271987 // about: handler. Must come before chrome: handler, since it will
1988 // rewrite about: urls to chrome: URLs and then expect chrome: to
1989 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251990 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1991 BrowserURLHandler::null_handler());
1992 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241993 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251994}
1995
1996void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371997 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581998 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471999 BrowsingDataRemover* remover =
2000 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552001 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2002 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252003 // BrowsingDataRemover takes care of deleting itself when done.
2004}
2005
2006void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372007 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582008 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472009 BrowsingDataRemover* remover =
2010 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232011 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552012 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252013 // BrowsingDataRemover takes care of deleting itself when done.
2014}
2015
[email protected]650b2d52013-02-10 03:41:452016base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322017 return download_util::GetDefaultDownloadDirectory();
2018}
2019
[email protected]c9b6eb62011-10-18 20:49:392020std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2021 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2022}
2023
[email protected]b7631cc2012-09-15 05:08:382024void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2025 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542026#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382027 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2028 scoped_ptr<ppapi::host::HostFactory>(
2029 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542030#endif
[email protected]b7631cc2012-09-15 05:08:382031}
2032
[email protected]0c7193742012-11-07 19:05:032033content::BrowserPpapiHost*
2034 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2035 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132036 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032037 while (!iter.Done()) {
2038 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2039 if (host->process() &&
2040 host->process()->GetData().id == plugin_process_id) {
2041 // Found the plugin.
2042 return host->browser_ppapi_host();
2043 }
2044 ++iter;
2045 }
2046 return NULL;
2047}
2048
[email protected]7b38b192013-03-23 18:39:312049bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2050 content::BrowserContext* browser_context, const GURL& site_url) {
2051 if (CommandLine::ForCurrentProcess()->HasSwitch(
2052 switches::kEnableBrowserPluginForAllViewTypes))
2053 return true;
2054
2055 Profile* profile = Profile::FromBrowserContext(browser_context);
2056 ExtensionService* service =
2057 extensions::ExtensionSystem::Get(profile)->extension_service();
2058 if (!service)
2059 return false;
2060
2061 const Extension* extension = service->extensions()->
2062 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2063 if (!extension)
2064 return false;
2065
[email protected]c2d2f102013-04-29 16:42:582066 return extension->HasAPIPermission(APIPermission::kWebView) ||
2067 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312068}
2069
[email protected]38cd8f7f2012-06-15 22:06:072070bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582071 content::BrowserContext* browser_context,
2072 const GURL& url,
2073 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:292074 if (!url.is_valid())
2075 return false;
2076
2077 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:422078 if (url.SchemeIs(extensions::kExtensionScheme) &&
2079 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:292080 return true;
[email protected]885c0e92012-11-13 20:27:422081 }
[email protected]a658d452012-03-02 12:45:292082
[email protected]9a5940d2012-04-27 19:16:232083 Profile* profile = Profile::FromBrowserContext(browser_context);
2084 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:192085 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:132086 extensions::ExtensionSystem::Get(profile)->extension_service();
2087 if (extension_service) {
2088 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:232089 GetExtensionOrAppByURL(ExtensionURLInfo(url));
2090 }
2091
[email protected]f237c0f2012-03-10 07:49:102092 // Need to check this now and not on construction because otherwise it won't
2093 // work with browser_tests.
2094 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2095 std::string allowed_list =
2096 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:232097 if (allowed_list == "*") {
2098 // The wildcard allows socket API only for packaged and platform apps.
2099 return extension &&
[email protected]1d5e58b2013-01-31 08:41:402100 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
2101 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:232102 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:392103 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:102104 while (t.GetNext()) {
2105 if (t.token() == host)
2106 return true;
2107 }
2108 }
2109
[email protected]a658d452012-03-02 12:45:292110 if (!extension)
2111 return false;
2112
[email protected]157cc902012-11-02 06:31:582113 extensions::SocketPermission::CheckParam extension_params(
2114 params.type, params.host, params.port);
2115 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
2116 &extension_params))
[email protected]a658d452012-03-02 12:45:292117 return true;
2118
2119 return false;
[email protected]e461da2f2012-02-16 19:06:402120}
2121
[email protected]650b2d52013-02-10 03:41:452122base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2123 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142124 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2125 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2126}
2127
[email protected]a28e3302013-02-03 03:50:432128ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2129 WebContents* web_contents) {
2130 return new ChromeSelectFilePolicy(web_contents);
2131}
2132
[email protected]7d9424702013-04-14 13:14:162133void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2134 std::vector<std::string>* additional_allowed_schemes) {
2135 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2136 additional_allowed_schemes);
2137 additional_allowed_schemes->push_back(kChromeUIScheme);
2138 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2139}
2140
[email protected]02250952013-04-24 23:52:532141void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2142 const base::FilePath& storage_partition_path,
2143 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2144#if !defined(OS_ANDROID)
2145 additional_providers->push_back(new MediaFileSystemMountPointProvider(
2146 storage_partition_path));
2147#endif
2148}
2149
[email protected]e60c0232011-11-11 19:56:352150#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182151void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2152 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382153 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082154 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392155#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452156 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392157 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2158 DCHECK(!data_path.empty());
2159
2160 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452161 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392162 base::PlatformFile f =
2163 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2164 DCHECK(f != base::kInvalidPlatformFileValue);
2165 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2166 FileDescriptor(f, true)));
2167
[email protected]650b2d52013-02-10 03:41:452168 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392169 data_path.AppendASCII("chrome_100_percent.pak");
2170 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2171 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372172 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392173 FileDescriptor(f, true)));
2174
2175 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452176 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392177 GetLocaleFilePath(locale, false);
2178 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2179 DCHECK(f != base::kInvalidPlatformFileValue);
2180 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2181 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382182
[email protected]650b2d52013-02-10 03:41:452183 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372184 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2185 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2186 DCHECK(f != base::kInvalidPlatformFileValue);
2187 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2188 FileDescriptor(f, true)));
2189
[email protected]40da3e0c2012-10-24 22:03:382190#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432191 if (IsCrashReporterEnabled()) {
2192 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2193 if (f == base::kInvalidPlatformFileValue) {
2194 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2195 "be disabled for this process.";
2196 } else {
2197 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2198 FileDescriptor(f, true)));
2199 }
[email protected]40da3e0c2012-10-24 22:03:382200 }
2201#endif // defined(USE_LINUX_BREAKPAD)
2202
2203#else
2204 int crash_signal_fd = GetCrashSignalFD(command_line);
2205 if (crash_signal_fd >= 0) {
2206 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2207 FileDescriptor(crash_signal_fd,
2208 false)));
2209 }
[email protected]29699c22012-10-03 23:57:392210#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302211}
[email protected]e60c0232011-11-11 19:56:352212#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302213
[email protected]4a65826d2011-08-25 16:04:012214#if defined(OS_WIN)
2215const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2216 return chrome::kBrowserResourcesDll;
2217}
[email protected]34f48682013-03-20 00:30:182218
2219void ChromeContentBrowserClient::PreSpawnRenderer(
2220 sandbox::TargetPolicy* policy,
2221 bool* success) {
2222 // This code is duplicated in nacl_exe_win_64.cc.
2223 // Allow the server side of a pipe restricted to the "chrome.nacl."
2224 // namespace so that it cannot impersonate other system or other chrome
2225 // service pipes.
2226 sandbox::ResultCode result = policy->AddRule(
2227 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2228 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2229 L"\\\\.\\pipe\\chrome.nacl.*");
2230 if (result != sandbox::SBOX_ALL_OK) {
2231 *success = false;
2232 return;
2233 }
2234
2235 // Renderers need to send named pipe handles and shared memory
2236 // segment handles to NaCl loader processes.
2237 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2238 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2239 L"File");
2240 if (result != sandbox::SBOX_ALL_OK) {
2241 *success = false;
2242 return;
2243 }
2244}
[email protected]4a65826d2011-08-25 16:04:012245#endif
2246
[email protected]37a72af2011-06-13 05:42:012247#if defined(USE_NSS)
2248crypto::CryptoModuleBlockingPasswordDelegate*
2249 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2250 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292251 return chrome::NewCryptoModuleBlockingDialogDelegate(
2252 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012253}
2254#endif
2255
[email protected]d977f9c2011-03-14 16:10:262256} // namespace chrome