blob: 6be5957d95684324edf9130d367b797d9a76b982 [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]631bb742011-11-02 11:29:39192
[email protected]c5dbef02011-05-13 05:06:09193namespace {
194
[email protected]eabbfb12013-04-05 23:28:35195// Cached version of the locale so we can return the locale on the I/O
196// thread.
197base::LazyInstance<std::string> g_io_thread_application_locale;
198
[email protected]e461da2f2012-02-16 19:06:40199const char* kPredefinedAllowedSocketOrigins[] = {
200 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18201 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45202 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
203 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
204 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
205 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35206 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54207 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
208 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
209 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
210 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
211 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
212 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38213 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58214 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
215 "iabmpiboiopbgfabjmgeedhcmjenhbla" // see crbug.com/165080
[email protected]e461da2f2012-02-16 19:06:40216};
217
[email protected]f8f93eb2012-09-25 03:06:24218// Returns a copy of the given url with its host set to given host and path set
219// to given path. Other parts of the url will be the same.
220GURL ReplaceURLHostAndPath(const GURL& url,
221 const std::string& host,
222 const std::string& path) {
223 url_canon::Replacements<char> replacements;
224 replacements.SetHost(host.c_str(),
225 url_parse::Component(0, host.length()));
226 replacements.SetPath(path.c_str(),
227 url_parse::Component(0, path.length()));
228 return url.ReplaceComponents(replacements);
229}
230
231// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
232GURL AddUberHost(const GURL& url) {
233 const std::string uber_host = chrome::kChromeUIUberHost;
234 const std::string new_path = url.host() + url.path();
235
236 return ReplaceURLHostAndPath(url, uber_host, new_path);
237}
238
[email protected]045bf7c2012-09-28 20:27:36239// If url->host() is "chrome" and url->path() has characters other than the
240// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
241// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24242bool RemoveUberHost(GURL* url) {
243 if (url->host() != chrome::kChromeUIUberHost)
244 return false;
245
[email protected]045bf7c2012-09-28 20:27:36246 if (url->path().empty() || url->path() == "/")
247 return false;
248
[email protected]f8f93eb2012-09-25 03:06:24249 const std::string old_path = url->path();
250
251 const std::string::size_type separator = old_path.find('/', 1);
252 std::string new_host;
253 std::string new_path;
254 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36255 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24256 } else {
257 new_host = old_path.substr(1, separator - 1);
258 new_path = old_path.substr(separator);
259 }
260
261 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
262
263 return true;
264}
265
[email protected]b8148ac2011-07-13 22:03:25266// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42267bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24268 // Do not handle special URLs such as "about:foo"
269 if (!url->host().empty()) {
270 const GURL chrome_url = AddUberHost(*url);
271
272 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
273 // be called.
274 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
275 browser_context, chrome_url))
276 return true;
277 }
278
[email protected]863f70a2012-01-27 02:05:50279 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
280 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25281 return false;
282
[email protected]fe69558d2012-03-12 11:34:49283#if defined(OS_CHROMEOS)
284 // Special case : in ChromeOS in Guest mode bookmarks and history are
285 // disabled for security reasons. New tab page explains the reasons, so
286 // we redirect user to new tab page.
287 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
288 if (url->SchemeIs(chrome::kChromeUIScheme) &&
289 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
290 url->DomainIs(chrome::kChromeUIHistoryHost))) {
291 // Rewrite with new tab URL
292 *url = GURL(chrome::kChromeUINewTabURL);
293 }
294 }
295#endif
296
[email protected]b8148ac2011-07-13 22:03:25297 // Special case the new tab page. In older versions of Chrome, the new tab
298 // page was hosted at chrome-internal:<blah>. This might be in people's saved
299 // sessions or bookmarks, so we say any URL with that scheme triggers the new
300 // tab page.
301 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
302 // Rewrite it with the proper new tab URL.
303 *url = GURL(chrome::kChromeUINewTabURL);
304 }
305
306 return true;
307}
308
[email protected]f8f93eb2012-09-25 03:06:24309// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
310// "chrome://foo/".
311bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
312 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
313 return false;
314
315 return RemoveUberHost(url);
316}
317
[email protected]8d3132f62011-10-12 07:13:42318// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
319// below. Extension, and isolated apps require different privileges to be
320// granted to their RenderProcessHosts. This classification allows us to make
321// sure URLs are served by hosts with the right set of privileges.
322enum RenderProcessHostPrivilege {
323 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45324 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42325 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45326 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42327};
328
329RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
330 const GURL& url,
331 ExtensionService* service) {
332 // Default to a normal renderer cause it is lower privileged. This should only
333 // occur if the URL on a site instance is either malformed, or uninitialized.
334 // If it is malformed, then there is no need for better privileges anyways.
335 // If it is uninitialized, but eventually settles on being an a scheme other
336 // than normal webrenderer, the navigation logic will correct us out of band
337 // anyways.
338 if (!url.is_valid())
339 return PRIV_NORMAL;
340
[email protected]885c0e92012-11-13 20:27:42341 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44342 const Extension* extension =
343 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43344 if (extension &&
345 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42346 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45347 if (extension && extension->is_hosted_app())
348 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42349
350 return PRIV_EXTENSION;
351 }
352
353 return PRIV_NORMAL;
354}
355
356RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30357 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46358 extensions::ProcessMap* process_map,
359 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46360 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30361 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46362 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21363 return PRIV_NORMAL;
364
[email protected]6f371442011-11-09 06:45:46365 for (std::set<std::string>::iterator iter = extension_ids.begin();
366 iter != extension_ids.end(); ++iter) {
367 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43368 if (extension &&
369 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42370 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45371 if (extension && extension->is_hosted_app())
372 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42373 }
374
[email protected]676f6ab2011-10-19 20:23:21375 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42376}
377
[email protected]6786bf402011-12-03 15:19:45378bool CertMatchesFilter(const net::X509Certificate& cert,
379 const base::DictionaryValue& filter) {
380 // TODO(markusheintz): This is the minimal required filter implementation.
381 // Implement a better matcher.
382
383 // An empty filter matches any client certificate since no requirements are
384 // specified at all.
385 if (filter.empty())
386 return true;
387
388 std::string common_name;
389 if (filter.GetString("ISSUER.CN", &common_name) &&
390 (cert.issuer().common_name == common_name)) {
391 return true;
392 }
393 return false;
394}
395
[email protected]f3986f82012-01-03 20:00:06396// Fills |map| with the per-script font prefs under path |map_name|.
397void FillFontFamilyMap(const PrefService* prefs,
398 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53399 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06400 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
401 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
402 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
403 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23404 if (!font_family.empty())
405 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06406 }
407}
408
[email protected]a1733df2012-06-22 11:24:18409#if defined(OS_POSIX) && !defined(OS_MACOSX)
410int GetCrashSignalFD(const CommandLine& command_line) {
411 if (command_line.HasSwitch(switches::kExtensionProcess)) {
412 ExtensionCrashHandlerHostLinux* crash_handler =
413 ExtensionCrashHandlerHostLinux::GetInstance();
414 return crash_handler->GetDeathSignalSocket();
415 }
416
417 std::string process_type =
418 command_line.GetSwitchValueASCII(switches::kProcessType);
419
420 if (process_type == switches::kRendererProcess)
421 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
422
423 if (process_type == switches::kPluginProcess)
424 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
425
426 if (process_type == switches::kPpapiPluginProcess)
427 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
428
429 if (process_type == switches::kGpuProcess)
430 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
431
432 return -1;
433}
434#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
435
[email protected]7c60f5042013-02-14 03:39:32436// Transforms the input |url| into its "effective URL". The returned URL
[email protected]c5dec6292013-01-25 04:54:52437// facilitates grouping process-per-site. The |url| is transformed, for
438// example, from
439//
440// https://www.google.com/search?espv=1&q=tractors
441//
[email protected]7c60f5042013-02-14 03:39:32442// to the effective URL
[email protected]c5dec6292013-01-25 04:54:52443//
444// chrome-search://www.google.com/search?espv=1&q=tractors
445//
446// Notice the scheme change.
[email protected]7c60f5042013-02-14 03:39:32447//
448// If the input is already an effective URL then that same URL is returned.
449GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
[email protected]165fe422013-03-27 06:34:03450 CHECK(chrome::ShouldAssignURLToInstantRenderer(url, profile))
[email protected]7c60f5042013-02-14 03:39:32451 << "Error granting Instant access.";
[email protected]c5dec6292013-01-25 04:54:52452
453 if (url.SchemeIs(chrome::kChromeSearchScheme))
454 return url;
455
456 GURL effective_url(url);
457
458 // Replace the scheme with "chrome-search:".
459 url_canon::Replacements<char> replacements;
460 std::string search_scheme(chrome::kChromeSearchScheme);
461 replacements.SetScheme(search_scheme.data(),
462 url_parse::Component(0, search_scheme.length()));
463 effective_url = effective_url.ReplaceComponents(replacements);
464 return effective_url;
465}
466
[email protected]d5bcd06f2013-04-21 08:07:24467#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30468GURL GetEffectiveURLForSignin(const GURL& url) {
469 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
470
471 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03472 // Copy the path because the argument to SetPathStr must outlive
473 // the Replacements object.
474 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30475 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03476 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30477 effective_url = effective_url.ReplaceComponents(replacements);
478 return effective_url;
479}
[email protected]d5bcd06f2013-04-21 08:07:24480#endif
[email protected]970c63e2013-03-07 00:25:30481
[email protected]eabbfb12013-04-05 23:28:35482void SetApplicationLocaleOnIOThread(const std::string& locale) {
483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
484 g_io_thread_application_locale.Get() = locale;
485}
486
[email protected]9dbfff12011-07-01 19:37:07487} // namespace
[email protected]c5dbef02011-05-13 05:06:09488
[email protected]d977f9c2011-03-14 16:10:26489namespace chrome {
490
[email protected]e461da2f2012-02-16 19:06:40491ChromeContentBrowserClient::ChromeContentBrowserClient() {
492 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
493 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40494}
495
496ChromeContentBrowserClient::~ChromeContentBrowserClient() {
497}
498
[email protected]bca18382012-06-25 19:15:23499// static
[email protected]c753f142013-02-10 13:14:04500void ChromeContentBrowserClient::RegisterUserPrefs(
501 PrefRegistrySyncable* registry) {
502 registry->RegisterBooleanPref(prefs::kDisable3DAPIs,
503 false,
504 PrefRegistrySyncable::UNSYNCABLE_PREF);
505 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
506 true,
507 PrefRegistrySyncable::UNSYNCABLE_PREF);
508 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo,
509 false,
510 PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23511}
512
[email protected]eabbfb12013-04-05 23:28:35513// static
514void ChromeContentBrowserClient::SetApplicationLocale(
515 const std::string& locale) {
516 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
517
518 // This object is guaranteed to outlive all threads so we don't have to
519 // worry about the lack of refcounting and can just post as Unretained.
520 //
521 // The common case is that this function is called early in Chrome startup
522 // before any threads are created (it will also be called later if the user
523 // changes the pref). In this case, there will be no threads created and
524 // posting will fail. When there are no threads, we can just set the string
525 // without worrying about threadsafety.
526 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
527 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
528 g_io_thread_application_locale.Get() = locale;
529 }
530}
531
[email protected]50462bf02011-11-21 19:13:31532content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
533 const content::MainFunctionParams& parameters) {
534 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30535 // Construct the Main browser parts based on the OS type.
536#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31537 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04538#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31539 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30540#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22541 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26542#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31543 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14544#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09545 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30546#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31547 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04548#else
[email protected]b48c9182011-10-26 18:03:30549 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31550 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30551#endif
552
[email protected]c7480942011-11-08 19:18:27553 // Construct additional browser parts. Stages are called in the order in
554 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22555#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41556 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04557#endif
[email protected]c7480942011-11-08 19:18:27558
559#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41560 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27561#endif
562
[email protected]dc04be7c2012-03-15 23:57:49563#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41564 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49565#endif
566
[email protected]e050ef142012-03-21 01:04:24567#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41568 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24569#endif
570
[email protected]95132f52013-04-12 02:19:04571 chrome::AddMetricsExtraParts(main_parts);
572
[email protected]50462bf02011-11-21 19:13:31573 return main_parts;
[email protected]f967b722011-09-07 00:58:04574}
575
[email protected]e94bbcb2012-09-07 05:33:57576std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19577 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57578 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53579 std::string partition_id;
580
581 // The partition ID for webview guest processes is the string value of its
582 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
583 if (site.SchemeIs(chrome::kGuestScheme))
584 partition_id = site.spec();
585
[email protected]056efdc2013-04-06 00:14:53586 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53587 return partition_id;
588}
589
590bool ChromeContentBrowserClient::IsValidStoragePartitionId(
591 content::BrowserContext* browser_context,
592 const std::string& partition_id) {
593 // The default ID is empty and is always valid.
594 if (partition_id.empty())
595 return true;
596
597 return GURL(partition_id).is_valid();
598}
599
600void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
601 content::BrowserContext* browser_context,
602 const GURL& site,
[email protected]14acc642012-11-17 12:20:10603 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53604 std::string* partition_domain,
605 std::string* partition_name,
606 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10607 // Default to the browser-wide storage partition and override based on |site|
608 // below.
609 partition_domain->clear();
610 partition_name->clear();
611 *in_memory = false;
612
[email protected]1bc28312012-11-08 08:31:53613 // For the webview tag, we create special guest processes, which host the
614 // tag content separately from the main application that embeds the tag.
615 // A webview tag can specify both the partition name and whether the storage
616 // for that partition should be persisted. Each tag gets a SiteInstance with
617 // a specially formatted URL, based on the application it is hosted by and
618 // the partition requested by it. The format for that URL is:
619 // chrome-guest://partition_domain/persist?partition_name
620 if (site.SchemeIs(chrome::kGuestScheme)) {
621 // Since guest URLs are only used for packaged apps, there must be an app
622 // id in the URL.
623 CHECK(site.has_host());
624 *partition_domain = site.host();
625 // Since persistence is optional, the path must either be empty or the
626 // literal string.
627 *in_memory = (site.path() != "/persist");
628 // The partition name is user supplied value, which we have encoded when the
629 // URL was created, so it needs to be decoded.
630 *partition_name = net::UnescapeURLComponent(site.query(),
631 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10632 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
633 // If |can_be_default| is false, the caller is stating that the |site|
634 // should be parsed as if it had isolated storage. In particular it is
635 // important to NOT check ExtensionService for the is_storage_isolated()
636 // attribute because this code path is run during Extension uninstall
637 // to do cleanup after the Extension has already been unloaded from the
638 // ExtensionService.
639 bool is_isolated = !can_be_default;
640 if (can_be_default) {
641 const Extension* extension = NULL;
642 Profile* profile = Profile::FromBrowserContext(browser_context);
643 ExtensionService* extension_service =
644 extensions::ExtensionSystem::Get(profile)->extension_service();
645 if (extension_service) {
646 extension = extension_service->extensions()->
647 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43648 if (extension &&
649 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10650 is_isolated = true;
651 }
652 }
653 }
[email protected]1bc28312012-11-08 08:31:53654
[email protected]14acc642012-11-17 12:20:10655 if (is_isolated) {
656 CHECK(site.has_host());
657 // For extensions with isolated storage, the the host of the |site| is
658 // the |partition_domain|. The |in_memory| and |partition_name| are only
659 // used in guest schemes so they are cleared here.
660 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53661 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10662 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53663 }
[email protected]d1198fd2012-08-13 22:50:19664 }
665
[email protected]14acc642012-11-17 12:20:10666 // Assert that if |can_be_default| is false, the code above must have found a
667 // non-default partition. If this fails, the caller has a serious logic
668 // error about which StoragePartition they expect to be in and it is not
669 // safe to continue.
670 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44671}
672
[email protected]38b098f2012-03-14 21:11:57673content::WebContentsViewDelegate*
674 ChromeContentBrowserClient::GetWebContentsViewDelegate(
675 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27676 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32677}
678
[email protected]24665682013-02-25 20:59:38679// Check if the extension activity log is enabled for the profile.
680static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
681 extensions::ActivityLog* activity_log =
682 extensions::ActivityLog::GetInstance(profile);
683 return activity_log->IsLogEnabled();
684}
685
[email protected]44703cc72013-01-24 04:56:06686void ChromeContentBrowserClient::GuestWebContentsCreated(
687 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
688 Profile* profile = Profile::FromBrowserContext(
689 embedder_web_contents->GetBrowserContext());
690 ExtensionService* service =
691 extensions::ExtensionSystem::Get(profile)->extension_service();
692 if (!service)
693 return;
694 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
695 const Extension* extension = service->extensions()->
696 GetExtensionOrAppByURL(ExtensionURLInfo(url));
697 if (!extension)
698 return;
699 std::vector<ExtensionMsg_Loaded_Params> extensions;
700 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
701 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
702}
703
[email protected]f3b1a082011-11-18 00:34:30704void ChromeContentBrowserClient::RenderProcessHostCreated(
705 content::RenderProcessHost* host) {
706 int id = host->GetID();
707 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41708 net::URLRequestContextGetter* context =
709 profile->GetRequestContextForRenderProcess(id);
710
[email protected]f3b1a082011-11-18 00:34:30711 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41712 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55713#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30714 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55715#endif
[email protected]658677f2012-06-09 06:04:02716#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08717 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03718#endif
[email protected]f3b1a082011-11-18 00:34:30719 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02720 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30721 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56722#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21723 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56724#endif
[email protected]43535512013-02-20 20:41:41725 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
726 id, profile, context));
[email protected]2736c032012-05-11 18:06:07727 host->GetChannel()->AddFilter(
728 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27729#if defined(OS_MACOSX)
730 // TODO(tkent): Enable it for other platforms.
731 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
732#endif
[email protected]3e69bc82011-05-26 23:22:38733
[email protected]2ccf45c2011-08-19 23:35:50734 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
735 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07736
[email protected]24665682013-02-25 20:59:38737 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
738 IsExtensionActivityLogEnabledForProfile(profile)));
739
[email protected]39a5b532011-10-22 01:47:07740 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56741
742 RendererContentSettingRules rules;
743 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
744 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14745}
746
[email protected]3d7474ff2011-07-27 17:47:37747GURL ChromeContentBrowserClient::GetEffectiveURL(
748 content::BrowserContext* browser_context, const GURL& url) {
749 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52750 if (!profile)
751 return url;
752
[email protected]7c60f5042013-02-14 03:39:32753 // If the input |url| should be assigned to the Instant renderer, make its
754 // effective URL distinct from other URLs on the search provider's domain.
[email protected]165fe422013-03-27 06:34:03755 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
[email protected]7c60f5042013-02-14 03:39:32756 return GetEffectiveURLForInstant(url, profile);
[email protected]c5dec6292013-01-25 04:54:52757
[email protected]d5bcd06f2013-04-21 08:07:24758#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30759 // If the input |url| should be assigned to the Signin renderer, make its
760 // effective URL distinct from other URLs on the signin service's domain.
761 // Note that the signin renderer will be allowed to sign the user in to
762 // Chrome.
763 if (SigninManager::IsWebBasedSigninFlowURL(url))
764 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24765#endif
[email protected]970c63e2013-03-07 00:25:30766
[email protected]c5dec6292013-01-25 04:54:52767 // If the input |url| is part of an installed app, the effective URL is an
768 // extension URL with the ID of that extension as the host. This has the
769 // effect of grouping apps together in a common SiteInstance.
770 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13771 extensions::ExtensionSystem::Get(profile)->extension_service();
772 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08773 return url;
774
[email protected]06bdd2b2012-11-30 18:47:13775 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44776 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08777 if (!extension)
778 return url;
779
[email protected]15877ca2011-11-18 22:40:52780 // Bookmark apps do not use the hosted app process model, and should be
781 // treated as normal URLs.
782 if (extension->from_bookmark())
783 return url;
784
[email protected]36fb2c7c2011-04-04 15:49:08785 // If the URL is part of an extension's web extent, convert it to an
786 // extension URL.
787 return extension->GetResourceURL(url.path());
788}
789
[email protected]056ad2a2011-07-12 02:13:55790bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37791 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52792 // Non-extension, non-Instant URLs should generally use
793 // process-per-site-instance. Because we expect to use the effective URL,
794 // URLs for hosted apps (apart from bookmark apps) should have an extension
795 // scheme by now.
796
797 Profile* profile = Profile::FromBrowserContext(browser_context);
798 if (!profile)
799 return false;
800
[email protected]165fe422013-03-27 06:34:03801 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52802 return true;
803
[email protected]d5bcd06f2013-04-21 08:07:24804#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30805 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
806 return true;
[email protected]d5bcd06f2013-04-21 08:07:24807#endif
[email protected]970c63e2013-03-07 00:25:30808
[email protected]885c0e92012-11-13 20:27:42809 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55810 return false;
811
[email protected]c5dec6292013-01-25 04:54:52812 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13813 extensions::ExtensionSystem::Get(profile)->extension_service();
814 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55815 return false;
816
[email protected]06bdd2b2012-11-30 18:47:13817 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44818 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55819 if (!extension)
820 return false;
821
822 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53823 // permission, or that does not allow JavaScript access to the background
824 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55825 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40826 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06827 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29828 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53829 return false;
830 }
831 }
[email protected]056ad2a2011-07-12 02:13:55832
[email protected]7b54ca02012-03-02 18:06:53833 // Hosted apps that have script access to their background page must use
834 // process per site, since all instances can make synchronous calls to the
835 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55836 return true;
837}
838
[email protected]672c8c12013-03-07 12:30:06839// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41840void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
841 std::vector<std::string>* additional_schemes) {
842 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06843}
844
[email protected]6bd30072013-02-08 18:17:11845net::URLRequestContextGetter*
846ChromeContentBrowserClient::CreateRequestContext(
847 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06848 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11849 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06850 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11851}
852
853net::URLRequestContextGetter*
854ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
855 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40856 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11857 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06858 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11859 Profile* profile = Profile::FromBrowserContext(browser_context);
860 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06861 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11862}
863
[email protected]46fb9442011-12-09 17:57:47864bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
865 return ProfileIOData::IsHandledURL(url);
866}
867
[email protected]2a5221b2011-09-27 23:07:31868bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30869 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31870 const GURL& site_url) {
871 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30872 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52873 // This may be NULL during tests. In that case, just assume any site can
874 // share any host.
875 if (!profile)
876 return true;
877
[email protected]d43f99fe2013-04-03 00:20:14878 // Instant URLs should only be in the instant process and instant process
879 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52880 InstantService* instant_service =
881 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14882 if (instant_service) {
883 bool is_instant_process = instant_service->IsInstantProcess(
884 process_host->GetID());
885 bool should_be_in_instant_process =
886 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
887 if (is_instant_process || should_be_in_instant_process)
888 return is_instant_process && should_be_in_instant_process;
889 }
[email protected]c5dec6292013-01-25 04:54:52890
[email protected]d5bcd06f2013-04-21 08:07:24891#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30892 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
893 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
894 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:24895#endif
[email protected]970c63e2013-03-07 00:25:30896
[email protected]06bdd2b2012-11-30 18:47:13897 ExtensionService* service =
898 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46899 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31900
[email protected]ffa97602011-11-17 17:55:52901 // Don't allow the Task Manager to share a process with anything else.
902 // Otherwise it can affect the renderers it is observing.
903 // Note: we could create another RenderProcessHostPrivilege bucket for
904 // this to allow multiple chrome://tasks instances to share, but that's
905 // a very unlikely case without serious consequences.
906 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
907 return false;
908
[email protected]8d3132f62011-10-12 07:13:42909 // These may be NULL during tests. In that case, just assume any site can
910 // share any host.
[email protected]6f371442011-11-09 06:45:46911 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31912 return true;
913
[email protected]eec0b33c2011-12-05 22:09:45914 // Otherwise, just make sure the process privilege matches the privilege
915 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57916 RenderProcessHostPrivilege privilege_required =
917 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45918 return GetProcessPrivilege(process_host, process_map, service) ==
919 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31920}
921
[email protected]76411f412012-02-22 18:56:06922// This function is trying to limit the amount of processes used by extensions
923// with background pages. It uses a globally set percentage of processes to
924// run such extensions and if the limit is exceeded, it returns true, to
925// indicate to the content module to group extensions together.
926bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
927 content::BrowserContext* browser_context, const GURL& url) {
928 // It has to be a valid URL for us to check for an extension.
929 if (!url.is_valid())
930 return false;
931
932 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19933 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13934 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06935 if (!service)
936 return false;
937
938 // We have to have a valid extension with background page to proceed.
939 const Extension* extension =
940 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
941 if (!extension)
942 return false;
[email protected]9367eabc2013-03-01 01:29:29943 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06944 return false;
945
946 std::set<int> process_ids;
947 size_t max_process_count =
948 content::RenderProcessHost::GetMaxRendererProcessCount();
949
950 // Go through all profiles to ensure we have total count of extension
951 // processes containing background pages, otherwise one profile can
952 // starve the other.
953 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
954 GetLoadedProfiles();
955 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03956 ExtensionProcessManager* epm =
957 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32958 for (ExtensionProcessManager::const_iterator iter =
959 epm->background_hosts().begin();
960 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13961 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32962 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06963 }
964 }
965
966 if (process_ids.size() >
967 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
968 return true;
969 }
970
971 return false;
972}
973
[email protected]6f371442011-11-09 06:45:46974void ChromeContentBrowserClient::SiteInstanceGotProcess(
975 SiteInstance* site_instance) {
976 CHECK(site_instance->HasProcess());
977
978 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02979 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52980 if (!profile)
981 return;
982
983 // Remember the ID of the Instant process to signal the renderer process
984 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:03985 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:32986 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:52987 InstantService* instant_service =
988 InstantServiceFactory::GetForProfile(profile);
989 if (instant_service)
990 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
991 }
992
[email protected]d5bcd06f2013-04-21 08:07:24993#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30994 // We only expect there to be one signin process as we use process-per-site
995 // for signin URLs. The signin process will be cleared from SigninManager
996 // when the renderer is destroyed.
997 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
998 SigninManager* signin_manager =
999 SigninManagerFactory::GetForProfile(profile);
1000 if (signin_manager)
1001 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
1002 }
[email protected]d5bcd06f2013-04-21 08:07:241003#endif
[email protected]970c63e2013-03-07 00:25:301004
[email protected]06bdd2b2012-11-30 18:47:131005 ExtensionService* service =
1006 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461007 if (!service)
1008 return;
1009
1010 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441011 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591012 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461013 if (!extension)
1014 return;
1015
[email protected]6bc04fd82011-12-04 02:29:351016 service->process_map()->Insert(extension->id(),
1017 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331018 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461019 BrowserThread::PostTask(
1020 BrowserThread::IO, FROM_HERE,
1021 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591022 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461023 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351024 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331025 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461026}
1027
1028void ChromeContentBrowserClient::SiteInstanceDeleting(
1029 SiteInstance* site_instance) {
1030 if (!site_instance->HasProcess())
1031 return;
1032
1033 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021034 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131035 ExtensionService* service =
1036 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461037 if (!service)
1038 return;
1039
1040 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441041 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591042 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461043 if (!extension)
1044 return;
1045
[email protected]6bc04fd82011-12-04 02:29:351046 service->process_map()->Remove(extension->id(),
1047 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331048 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461049 BrowserThread::PostTask(
1050 BrowserThread::IO, FROM_HERE,
1051 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591052 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461053 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351054 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331055 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461056}
1057
[email protected]f05763972012-06-06 18:17:261058bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141059 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081060 const GURL& current_url,
1061 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261062 if (current_url.is_empty()) {
1063 // Always choose a new process when navigating to extension URLs. The
1064 // process grouping logic will combine all of a given extension's pages
1065 // into the same process.
[email protected]885c0e92012-11-13 20:27:421066 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261067 return true;
[email protected]e3daf3c2011-10-05 21:17:081068
[email protected]f05763972012-06-06 18:17:261069 return false;
1070 }
1071
1072 // Also, we must switch if one is an extension and the other is not the exact
1073 // same extension.
[email protected]885c0e92012-11-13 20:27:421074 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1075 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261076 if (current_url.GetOrigin() != new_url.GetOrigin())
1077 return true;
1078 }
1079
[email protected]e9841fbd2013-02-22 23:12:141080 // The checks below only matter if we can retrieve which extensions are
1081 // installed.
1082 Profile* profile =
1083 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1084 ExtensionService* service =
1085 extensions::ExtensionSystem::Get(profile)->extension_service();
1086 if (!service)
1087 return false;
1088
1089 // We must swap if the URL is for an extension and we are not using an
1090 // extension process.
1091 const Extension* new_extension =
1092 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1093 // Ignore all hosted apps except the Chrome Web Store, since they do not
1094 // require their own BrowsingInstance (e.g., postMessage is ok).
1095 if (new_extension &&
1096 new_extension->is_hosted_app() &&
1097 new_extension->id() != extension_misc::kWebStoreAppId)
1098 new_extension = NULL;
1099 if (new_extension &&
1100 site_instance->HasProcess() &&
1101 !service->process_map()->Contains(new_extension->id(),
1102 site_instance->GetProcess()->GetID()))
1103 return true;
1104
[email protected]f05763972012-06-06 18:17:261105 return false;
[email protected]e3daf3c2011-10-05 21:17:081106}
1107
[email protected]395045c2012-05-22 15:04:381108bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1109 content::ResourceContext* resource_context, const GURL& current_url,
1110 const GURL& new_url) {
1111 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1112 return extensions::CrossesExtensionProcessBoundary(
1113 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171114 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381115}
1116
[email protected]763ec4ca2011-04-29 15:48:121117std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1118 const std::string& alias_name) {
1119 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1120}
1121
[email protected]b80f68432011-05-02 17:22:301122void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1123 CommandLine* command_line, int child_process_id) {
1124#if defined(USE_LINUX_BREAKPAD)
1125 if (IsCrashReporterEnabled()) {
1126 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1127 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1128 }
1129#elif defined(OS_MACOSX)
1130 if (IsCrashReporterEnabled()) {
1131 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1132 child_process_logging::GetClientId());
1133 }
1134#endif // OS_MACOSX
1135
[email protected]f1933792011-06-14 00:49:341136 if (logging::DialogsAreSuppressed())
1137 command_line->AppendSwitch(switches::kNoErrorDialogs);
1138
[email protected]b80f68432011-05-02 17:22:301139 std::string process_type =
1140 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171141 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321142
1143 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1144 command_line->AppendSwitch(switches::kChromeFrame);
1145
[email protected]718eab62011-10-05 21:16:521146 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451147 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301148 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1149 if (!user_data_dir.empty())
1150 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1151#if defined(OS_CHROMEOS)
1152 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441153 browser_command_line.GetSwitchValueASCII(
1154 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301155 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441156 command_line->AppendSwitchASCII(
1157 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301158#endif
1159
[email protected]f3b1a082011-11-18 00:34:301160 content::RenderProcessHost* process =
1161 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371162 if (process) {
1163 Profile* profile = Profile::FromBrowserContext(
1164 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131165 ExtensionService* extension_service =
1166 extensions::ExtensionSystem::Get(profile)->extension_service();
1167 if (extension_service) {
1168 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001169 if (process_map && process_map->Contains(process->GetID()))
1170 command_line->AppendSwitch(switches::kExtensionProcess);
1171 }
[email protected]b80f68432011-05-02 17:22:301172
[email protected]a8d851f82011-12-21 00:32:371173 PrefService* prefs = profile->GetPrefs();
1174 // Currently this pref is only registered if applied via a policy.
1175 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1176 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1177 // Turn this policy into a command line switch.
1178 command_line->AppendSwitch(switches::kDisable3DAPIs);
1179 }
[email protected]718eab62011-10-05 21:16:521180
[email protected]a8d851f82011-12-21 00:32:371181 // Disable client-side phishing detection in the renderer if it is
1182 // disabled in the Profile preferences or the browser process.
1183 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1184 !g_browser_process->safe_browsing_detection_service()) {
1185 command_line->AppendSwitch(
1186 switches::kDisableClientSidePhishingDetection);
1187 }
[email protected]0045b0f42012-07-26 11:52:081188
1189 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211190 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521191
1192 InstantService* instant_service =
1193 InstantServiceFactory::GetForProfile(profile);
1194 if (instant_service &&
1195 instant_service->IsInstantProcess(process->GetID()))
1196 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301197
[email protected]d5bcd06f2013-04-21 08:07:241198#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301199 SigninManager* signin_manager =
1200 SigninManagerFactory::GetForProfile(profile);
1201 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1202 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241203#endif
[email protected]47c7ec82012-01-18 03:29:211204 }
[email protected]4287a3d2011-06-13 23:56:511205
[email protected]87552982012-11-02 17:21:401206 if (content::IsThreadedCompositingEnabled())
1207 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1208
[email protected]16dc42452013-04-09 04:37:191209#if defined(ENABLE_MESSAGE_CENTER)
1210 if (message_center::IsRichNotificationEnabled())
1211 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
1212#endif
1213
[email protected]47c7ec82012-01-18 03:29:211214 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511215 static const char* const kSwitchNames[] = {
[email protected]e217c5632013-04-12 19:11:481216 autofill::switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511217 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481218 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511219 switches::kAllowScriptingGallery,
1220 switches::kAppsCheckoutURL,
1221 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311222 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511223 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501224 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531225 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111226 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511227 switches::kDumpHistogramsOnExit,
[email protected]e9cddd52013-03-23 17:37:531228 switches::kEnableAdview,
1229 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211230 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511231 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511232 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511233 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511234 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451235 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481236 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051237 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511238 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291239 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511240 switches::kMemoryProfiling,
1241 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371242 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371243 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511244 switches::kPpapiFlashArgs,
1245 switches::kPpapiFlashInProcess,
1246 switches::kPpapiFlashPath,
1247 switches::kPpapiFlashVersion,
1248 switches::kProfilingAtStart,
1249 switches::kProfilingFile,
1250 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371251 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511252 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291253 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381254 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511255 };
1256
1257 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1258 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171259 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381260 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351261 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381262 switches::kEnableExperimentalExtensionApis,
1263 switches::kWhitelistedExtensionID,
1264 };
1265
1266 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1267 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511268 } else if (process_type == switches::kPluginProcess) {
1269 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441270#if defined(OS_CHROMEOS)
1271 chromeos::switches::kLoginProfile,
1272#endif
[email protected]4287a3d2011-06-13 23:56:511273 switches::kMemoryProfiling,
1274 switches::kSilentDumpOnDCHECK,
1275 switches::kUserDataDir,
1276 };
1277
1278 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1279 arraysize(kSwitchNames));
1280 } else if (process_type == switches::kZygoteProcess) {
1281 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511282 switches::kUserDataDir, // Make logs go to the right file.
1283 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501284 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511285 switches::kPpapiFlashInProcess,
1286 switches::kPpapiFlashPath,
1287 switches::kPpapiFlashVersion,
1288 };
1289
1290 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1291 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111292 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001293 base::FilePath user_data_dir =
1294 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1295 if (!user_data_dir.empty())
1296 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111297 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1298 // because GPU is expected to be unreliable.
1299 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1300 !command_line->HasSwitch(switches::kDisableBreakpad))
1301 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301302 }
[email protected]6f08af82011-09-15 01:19:031303
1304 // The command line switch kEnableBenchmarking needs to be specified along
1305 // with the kEnableStatsTable switch to ensure that the stats table global
1306 // is initialized correctly.
1307 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1308 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301309}
1310
1311std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431312 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351313 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301314 return g_browser_process->GetApplicationLocale();
1315}
1316
[email protected]597a867b2011-11-18 18:31:201317std::string ChromeContentBrowserClient::GetAcceptLangs(
1318 content::BrowserContext* context) {
1319 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371320 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081321}
1322
[email protected]9ec0f452012-05-31 15:58:531323gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221324 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531325 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081326}
1327
[email protected]a2176792011-05-08 19:30:491328bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091329 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191330 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201331 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201333 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051334 return io_data->GetCookieSettings()->
1335 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491336}
1337
[email protected]ed24fad2011-05-10 22:44:011338bool ChromeContentBrowserClient::AllowGetCookie(
1339 const GURL& url,
1340 const GURL& first_party,
1341 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201342 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011343 int render_process_id,
1344 int render_view_id) {
1345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201346 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051347 bool allow = io_data->GetCookieSettings()->
1348 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011349
[email protected]8093a542011-05-13 07:29:321350 BrowserThread::PostTask(
1351 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031352 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431353 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011354 return allow;
1355}
1356
1357bool ChromeContentBrowserClient::AllowSetCookie(
1358 const GURL& url,
1359 const GURL& first_party,
1360 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201361 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011362 int render_process_id,
1363 int render_view_id,
1364 net::CookieOptions* options) {
1365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201366 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051367 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1368 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1369
[email protected]8093a542011-05-13 07:29:321370 BrowserThread::PostTask(
1371 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031372 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431373 render_view_id, url, first_party, cookie_line, *options,
1374 !allow));
[email protected]ed24fad2011-05-10 22:44:011375 return allow;
1376}
1377
[email protected]d5a19162011-06-30 18:51:541378bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201379 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201381 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431382 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1383 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261384
[email protected]bf510ed2012-06-05 08:31:431385 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1386 // Could we even support per-origin settings?
1387 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541388}
1389
[email protected]5c5a88e2011-11-12 00:45:351390bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351391 const GURL& url,
1392 const string16& name,
1393 const string16& display_name,
1394 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201395 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481396 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201398 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351399 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1400 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1401
[email protected]62151052012-02-01 18:40:481402 // Record access to database for potential display in UI.
1403 std::vector<std::pair<int, int> >::const_iterator i;
1404 for (i = render_views.begin(); i != render_views.end(); ++i) {
1405 BrowserThread::PostTask(
1406 BrowserThread::UI, FROM_HERE,
1407 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1408 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351409 }
1410
1411 return allow;
1412}
1413
1414bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351415 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201416 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481417 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201419 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351420 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1421 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1422
[email protected]62151052012-02-01 18:40:481423 // Record access to file system for potential display in UI.
1424 std::vector<std::pair<int, int> >::const_iterator i;
1425 for (i = render_views.begin(); i != render_views.end(); ++i) {
1426 BrowserThread::PostTask(
1427 BrowserThread::UI, FROM_HERE,
1428 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1429 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351430 }
1431
1432 return allow;
1433}
1434
[email protected]7c5ff9a2012-03-02 07:42:491435bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1436 const GURL& url,
1437 const string16& name,
1438 content::ResourceContext* context,
1439 const std::vector<std::pair<int, int> >& render_views) {
1440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1441 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1442 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1443 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1444
1445 // Record access to IndexedDB for potential display in UI.
1446 std::vector<std::pair<int, int> >::const_iterator i;
1447 for (i = render_views.begin(); i != render_views.end(); ++i) {
1448 BrowserThread::PostTask(
1449 BrowserThread::UI, FROM_HERE,
1450 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1451 i->first, i->second, url, name, !allow));
1452 }
1453
1454 return allow;
1455}
1456
[email protected]6133f922011-07-01 21:34:341457net::URLRequestContext*
1458ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201459 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421461 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201462 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341463 return io_data->extensions_request_context();
1464 }
1465
1466 return NULL;
1467}
1468
[email protected]317f96c92011-05-31 06:53:411469QuotaPermissionContext*
1470ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1471 return new ChromeQuotaPermissionContext();
1472}
1473
[email protected]848dd042011-06-04 18:24:031474void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171475 int render_process_id,
1476 int render_view_id,
1477 int cert_error,
1478 const net::SSLInfo& ssl_info,
1479 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021480 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031481 bool overridable,
[email protected]d9be47702012-05-16 03:41:221482 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171483 const base::Callback<void(bool)>& callback,
1484 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021485 if (resource_type != ResourceType::MAIN_FRAME) {
1486 // A sub-resource has a certificate error. The user doesn't really
1487 // have a context for making the right decision, so block the
1488 // request hard, without an info bar to allow showing the insecure
1489 // content.
1490 *cancel_request = true;
1491 return;
1492 }
1493
[email protected]f9034cf2011-07-21 12:43:411494 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131495 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171496 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411497 if (!tab) {
1498 NOTREACHED();
1499 return;
1500 }
1501 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501502 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301503 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011504 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1505 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411506 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171507 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411508 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171509 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411510 return;
1511 }
1512 }
1513
[email protected]1e87df32012-09-12 04:53:191514#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231515 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1516 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1517 if (captive_portal_tab_helper)
1518 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191519#endif
1520
[email protected]f9034cf2011-07-21 12:43:411521 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221522 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1523 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031524}
1525
[email protected]c99c442e2011-08-24 11:37:301526void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451527 int render_process_id,
1528 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401529 const net::HttpNetworkSession* network_session,
1530 net::SSLCertRequestInfo* cert_request_info,
1531 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131532 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451533 render_process_id, render_view_id);
1534 if (!tab) {
1535 NOTREACHED();
1536 return;
1537 }
1538
[email protected]6786bf402011-12-03 15:19:451539 GURL requesting_url("https://" + cert_request_info->host_and_port);
1540 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1541 << cert_request_info->host_and_port;
1542
[email protected]627e0512011-12-21 22:55:301543 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451544 scoped_ptr<Value> filter(
1545 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1546 requesting_url,
1547 requesting_url,
1548 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1549 std::string(), NULL));
1550
1551 if (filter.get()) {
1552 // Try to automatically select a client certificate.
1553 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1554 DictionaryValue* filter_dict =
1555 static_cast<DictionaryValue*>(filter.get());
1556
1557 const std::vector<scoped_refptr<net::X509Certificate> >&
1558 all_client_certs = cert_request_info->client_certs;
1559 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1560 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1561 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401562 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451563 return;
1564 }
1565 }
1566 } else {
1567 NOTREACHED();
1568 }
1569 }
1570
[email protected]11feec322012-09-18 03:58:521571 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1572 if (!ssl_tab_helper) {
1573 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451574 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141575 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401576 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451577 return;
1578 }
[email protected]11feec322012-09-18 03:58:521579 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401580 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451581}
1582
[email protected]3b455502012-12-11 18:22:581583void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451584 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581585 net::CertificateMimeType cert_type,
1586 const void* cert_data,
1587 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451588 int render_process_id,
1589 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581590 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1591 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451592}
1593
[email protected]dc73a7b2012-03-25 15:27:181594content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561595 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181596}
1597
[email protected]941623e2011-06-07 23:06:041598void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1599 const GURL& source_origin,
1600 int callback_context,
1601 int render_process_id,
1602 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111603#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1605 WebContents* contents =
1606 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1607 if (!contents) {
[email protected]941623e2011-06-07 23:06:041608 NOTREACHED();
1609 return;
1610 }
1611
[email protected]d0d9c3ee2012-06-19 03:07:021612 // Skip showing the infobar if the request comes from an extension, and that
1613 // extension has the 'notify' permission. (If the extension does not have the
1614 // permission, the user will still be prompted.)
1615 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011616 ExtensionInfoMap* extension_info_map =
1617 extensions::ExtensionSystem::Get(profile)->info_map();
1618 DesktopNotificationService* notification_service =
1619 DesktopNotificationServiceFactory::GetForProfile(profile);
1620 const Extension* extension = NULL;
1621 if (extension_info_map) {
1622 ExtensionSet extensions;
1623 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1624 source_origin, render_process_id,
1625 extensions::APIPermission::kNotification, &extensions);
1626 for (ExtensionSet::const_iterator iter = extensions.begin();
1627 iter != extensions.end(); ++iter) {
1628 if (notification_service->IsExtensionEnabled((*iter)->id())) {
1629 extension = *iter;
1630 break;
1631 }
1632 }
1633 }
[email protected]eb4832a2012-12-08 01:57:521634 RenderViewHost* rvh =
1635 RenderViewHost::FromID(render_process_id, render_view_id);
1636 if (IsExtensionWithPermissionOrSuggestInConsole(
1637 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021638 if (rvh)
1639 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1640 return;
1641 }
1642
[email protected]c7cd5942013-04-30 03:31:011643 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021644 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111645#else
1646 NOTIMPLEMENTED();
1647#endif
[email protected]941623e2011-06-07 23:06:041648}
1649
1650WebKit::WebNotificationPresenter::Permission
1651 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021652 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201653 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021654 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111655#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201657 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041658
[email protected]c7cd5942013-04-30 03:31:011659 DesktopNotificationService* notification_service =
1660 io_data->GetNotificationService();
1661 if (notification_service) {
1662 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1663 ExtensionSet extensions;
1664 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1665 source_origin, render_process_id,
1666 extensions::APIPermission::kNotification, &extensions);
1667 for (ExtensionSet::const_iterator iter = extensions.begin();
1668 iter != extensions.end(); ++iter) {
1669 if (notification_service->IsExtensionEnabled((*iter)->id()))
1670 return WebKit::WebNotificationPresenter::PermissionAllowed;
1671 }
1672
1673 return notification_service->HasPermission(source_origin);
1674 }
1675
1676 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111677#else
1678 return WebKit::WebNotificationPresenter::PermissionAllowed;
1679#endif
[email protected]941623e2011-06-07 23:06:041680}
1681
1682void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171683 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041684 int render_process_id,
1685 int render_view_id,
1686 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111687#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041688 RenderViewHost* rvh = RenderViewHost::FromID(
1689 render_process_id, render_view_id);
1690 if (!rvh) {
1691 NOTREACHED();
1692 return;
1693 }
1694
[email protected]9f76c1e2012-03-05 15:15:581695 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301696 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041697 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371698 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041699 service->ShowDesktopNotification(
1700 params, render_process_id, render_view_id,
1701 worker ? DesktopNotificationService::WorkerNotification :
1702 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111703#else
1704 NOTIMPLEMENTED();
1705#endif
[email protected]941623e2011-06-07 23:06:041706}
1707
1708void ChromeContentBrowserClient::CancelDesktopNotification(
1709 int render_process_id,
1710 int render_view_id,
1711 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111712#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041713 RenderViewHost* rvh = RenderViewHost::FromID(
1714 render_process_id, render_view_id);
1715 if (!rvh) {
1716 NOTREACHED();
1717 return;
1718 }
1719
[email protected]9f76c1e2012-03-05 15:15:581720 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301721 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041722 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371723 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041724 service->CancelDesktopNotification(
1725 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111726#else
1727 NOTIMPLEMENTED();
1728#endif
[email protected]941623e2011-06-07 23:06:041729}
1730
[email protected]9f3fba52011-06-08 20:37:191731bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351732 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021733 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191734 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201735 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011736 int render_process_id,
1737 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191738 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011739
1740 *no_javascript_access = false;
1741
[email protected]9f3fba52011-06-08 20:37:191742 // If the opener is trying to create a background window but doesn't have
1743 // the appropriate permission, fail the attempt.
1744 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201745 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531746 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1747
[email protected]03b6d552012-03-29 04:03:011748 if (!map->SecurityOriginHasAPIPermission(
1749 source_origin,
1750 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061751 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011752 return false;
1753 }
1754
[email protected]7b54ca02012-03-02 18:06:531755 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1756 // return a recently installed Extension even if this CanCreateWindow call
1757 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011758 // because the permission check above would have caused an early return
1759 // already. We must use the full URL to find hosted apps, though, and not
1760 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531761 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351762 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291763 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011764 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191765 }
[email protected]056efdc2013-04-06 00:14:531766
1767 // No new browser window (popup or tab) in app mode.
1768 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1769 chrome::IsRunningInForcedAppMode()) {
1770 return false;
1771 }
1772
[email protected]9f3fba52011-06-08 20:37:191773 return true;
1774}
1775
1776std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201777 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1779 // Check if it's an extension-created worker, in which case we want to use
1780 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201781 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191782 const Extension* extension =
1783 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1784 return extension ? extension->name() : std::string();
1785}
1786
[email protected]99907362012-01-11 05:41:401787void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1788 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171789}
1790
[email protected]c52b2892012-03-07 11:01:021791content::SpeechRecognitionManagerDelegate*
1792 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321793#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021794 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321795#else
1796 return NULL;
1797#endif
[email protected]66cfec62012-02-24 17:57:511798}
1799
[email protected]ae6e9912011-07-27 01:18:281800net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1801 return g_browser_process->net_log();
1802}
1803
[email protected]32538d92011-08-25 00:09:231804AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1805 return new ChromeAccessTokenStore();
1806}
1807
[email protected]dbae6b02011-06-29 23:51:411808bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011809 return true;
[email protected]dbae6b02011-06-29 23:51:411810}
1811
[email protected]64d69de42012-02-06 00:19:541812void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321813 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061814 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581815 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061816 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061817
[email protected]f3986f82012-01-03 20:00:061818 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541819 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061820 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541821 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061822 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541823 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061824 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541825 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061826 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541827 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061828 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541829 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031830 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1831 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061832
[email protected]64d69de42012-02-06 00:19:541833 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401834 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541835 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401836 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541837 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401838 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541839 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401840 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061841
[email protected]ddf72142012-05-22 04:52:401842 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061843
[email protected]64d69de42012-02-06 00:19:541844 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401845 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541846 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061847 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541848 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061849 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1850 const DictionaryValue* inspector_settings =
1851 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1852 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181853 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1854 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061855 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181856 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541857 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181858 std::make_pair(iter.key(), value));
1859 }
[email protected]f3986f82012-01-03 20:00:061860 }
1861 }
[email protected]64d69de42012-02-06 00:19:541862 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061863
[email protected]ddf72142012-05-22 04:52:401864 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541865 web_prefs->javascript_enabled = false;
1866 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1867 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401868 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541869 web_prefs->plugins_enabled = false;
1870 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1871 web_prefs->java_enabled = false;
1872 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401873 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061874
[email protected]64d69de42012-02-06 00:19:541875 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1876 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061877
[email protected]64d69de42012-02-06 00:19:541878 web_prefs->memory_info_enabled =
1879 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1880 web_prefs->allow_displaying_insecure_content =
1881 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1882 web_prefs->allow_running_insecure_content =
1883 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321884#if defined(OS_ANDROID)
1885 web_prefs->font_scale_factor =
1886 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1887 web_prefs->force_enable_zoom =
1888 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451889#if defined(GOOGLE_TV)
1890 web_prefs->user_gesture_required_for_media_playback = false;
1891#endif
[email protected]d3b935f2012-10-19 23:14:321892#endif
[email protected]9d06d88d2012-02-23 22:37:081893 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061894
[email protected]64d69de42012-02-06 00:19:541895 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151896 UserStyleSheetWatcher* user_style_sheet_watcher =
1897 UserStyleSheetWatcherFactory::GetForProfile(profile);
1898 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541899 web_prefs->user_style_sheet_enabled = true;
1900 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151901 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541902 } else {
1903 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061904 }
1905
[email protected]cfadadd2013-04-03 04:43:021906 web_prefs->asynchronous_spell_checking_enabled = true;
1907 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:571908
[email protected]64d69de42012-02-06 00:19:541909 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061910 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541911 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061912 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541913 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061914 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1915
1916 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541917 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061918 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541919 web_prefs->default_encoding);
1920 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401921 prefs->ClearPref(prefs::kDefaultCharset);
1922 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061923 }
[email protected]64d69de42012-02-06 00:19:541924 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061925
[email protected]88ecf66d2012-12-11 22:53:471926 if (content::IsForceCompositingModeEnabled())
1927 web_prefs->force_compositing_mode = true;
1928
[email protected]299d7f12012-05-23 05:31:151929 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:231930 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131931 ExtensionService* service =
1932 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061933 if (service) {
[email protected]1bc28312012-11-08 08:31:531934 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1935 const Extension* extension = service->extensions()->GetByID(url.host());
1936 // Ensure that we are only granting extension preferences to URLs with
1937 // the correct scheme. Without this check, chrome-guest:// schemes used by
1938 // webview tags as well as hosts that happen to match the id of an
1939 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421940 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531941 extension_webkit_preferences::SetPreferences(
1942 extension, view_type, web_prefs);
1943 }
[email protected]f3986f82012-01-03 20:00:061944 }
1945
[email protected]cb2edf22013-04-01 20:25:231946 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541947 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:231948 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061949 // Disable all kinds of acceleration for background pages.
1950 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541951 web_prefs->force_compositing_mode = false;
1952 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061953 }
[email protected]2e21fe292012-03-02 22:52:321954
1955#if defined(FILE_MANAGER_EXTENSION)
1956 // Override the default of suppressing HW compositing for WebUI pages for the
1957 // file manager, which is implemented using WebUI but wants HW acceleration
1958 // for video decode & render.
1959 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1960 web_prefs->accelerated_compositing_enabled = true;
1961 web_prefs->accelerated_2d_canvas_enabled = true;
1962 }
1963#endif
[email protected]181a95ee2011-07-12 19:26:361964}
1965
1966void ChromeContentBrowserClient::UpdateInspectorSetting(
1967 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061968 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581969 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061970 DictionaryPrefUpdate update(
1971 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1972 prefs::kWebKitInspectorSettings);
1973 DictionaryValue* inspector_settings = update.Get();
1974 inspector_settings->SetWithoutPathExpansion(key,
1975 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361976}
1977
[email protected]b8148ac2011-07-13 22:03:251978void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1979 BrowserURLHandler* handler) {
1980 // Add the default URL handlers.
1981 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1982 BrowserURLHandler::null_handler());
1983 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1984 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1985
[email protected]b3adbd02011-11-30 22:23:271986 // about: handler. Must come before chrome: handler, since it will
1987 // rewrite about: urls to chrome: URLs and then expect chrome: to
1988 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251989 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1990 BrowserURLHandler::null_handler());
1991 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241992 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251993}
1994
1995void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371996 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581997 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471998 BrowsingDataRemover* remover =
1999 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552000 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2001 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252002 // BrowsingDataRemover takes care of deleting itself when done.
2003}
2004
2005void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372006 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582007 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472008 BrowsingDataRemover* remover =
2009 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232010 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552011 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252012 // BrowsingDataRemover takes care of deleting itself when done.
2013}
2014
[email protected]650b2d52013-02-10 03:41:452015base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322016 return download_util::GetDefaultDownloadDirectory();
2017}
2018
[email protected]c9b6eb62011-10-18 20:49:392019std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2020 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2021}
2022
[email protected]b7631cc2012-09-15 05:08:382023void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2024 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542025#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382026 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2027 scoped_ptr<ppapi::host::HostFactory>(
2028 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542029#endif
[email protected]b7631cc2012-09-15 05:08:382030}
2031
[email protected]0c7193742012-11-07 19:05:032032content::BrowserPpapiHost*
2033 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2034 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132035 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032036 while (!iter.Done()) {
2037 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2038 if (host->process() &&
2039 host->process()->GetData().id == plugin_process_id) {
2040 // Found the plugin.
2041 return host->browser_ppapi_host();
2042 }
2043 ++iter;
2044 }
2045 return NULL;
2046}
2047
[email protected]7b38b192013-03-23 18:39:312048bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2049 content::BrowserContext* browser_context, const GURL& site_url) {
2050 if (CommandLine::ForCurrentProcess()->HasSwitch(
2051 switches::kEnableBrowserPluginForAllViewTypes))
2052 return true;
2053
2054 Profile* profile = Profile::FromBrowserContext(browser_context);
2055 ExtensionService* service =
2056 extensions::ExtensionSystem::Get(profile)->extension_service();
2057 if (!service)
2058 return false;
2059
2060 const Extension* extension = service->extensions()->
2061 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2062 if (!extension)
2063 return false;
2064
[email protected]c2d2f102013-04-29 16:42:582065 return extension->HasAPIPermission(APIPermission::kWebView) ||
2066 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312067}
2068
[email protected]38cd8f7f2012-06-15 22:06:072069bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582070 content::BrowserContext* browser_context,
2071 const GURL& url,
2072 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:292073 if (!url.is_valid())
2074 return false;
2075
2076 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:422077 if (url.SchemeIs(extensions::kExtensionScheme) &&
2078 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:292079 return true;
[email protected]885c0e92012-11-13 20:27:422080 }
[email protected]a658d452012-03-02 12:45:292081
[email protected]9a5940d2012-04-27 19:16:232082 Profile* profile = Profile::FromBrowserContext(browser_context);
2083 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:192084 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:132085 extensions::ExtensionSystem::Get(profile)->extension_service();
2086 if (extension_service) {
2087 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:232088 GetExtensionOrAppByURL(ExtensionURLInfo(url));
2089 }
2090
[email protected]f237c0f2012-03-10 07:49:102091 // Need to check this now and not on construction because otherwise it won't
2092 // work with browser_tests.
2093 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2094 std::string allowed_list =
2095 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:232096 if (allowed_list == "*") {
2097 // The wildcard allows socket API only for packaged and platform apps.
2098 return extension &&
[email protected]1d5e58b2013-01-31 08:41:402099 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
2100 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:232101 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:392102 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:102103 while (t.GetNext()) {
2104 if (t.token() == host)
2105 return true;
2106 }
2107 }
2108
[email protected]a658d452012-03-02 12:45:292109 if (!extension)
2110 return false;
2111
[email protected]157cc902012-11-02 06:31:582112 extensions::SocketPermission::CheckParam extension_params(
2113 params.type, params.host, params.port);
2114 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
2115 &extension_params))
[email protected]a658d452012-03-02 12:45:292116 return true;
2117
2118 return false;
[email protected]e461da2f2012-02-16 19:06:402119}
2120
[email protected]650b2d52013-02-10 03:41:452121base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2122 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142123 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2124 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2125}
2126
[email protected]a28e3302013-02-03 03:50:432127ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2128 WebContents* web_contents) {
2129 return new ChromeSelectFilePolicy(web_contents);
2130}
2131
[email protected]7d9424702013-04-14 13:14:162132void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2133 std::vector<std::string>* additional_allowed_schemes) {
2134 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2135 additional_allowed_schemes);
2136 additional_allowed_schemes->push_back(kChromeUIScheme);
2137 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2138}
2139
[email protected]02250952013-04-24 23:52:532140void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2141 const base::FilePath& storage_partition_path,
2142 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2143#if !defined(OS_ANDROID)
2144 additional_providers->push_back(new MediaFileSystemMountPointProvider(
2145 storage_partition_path));
2146#endif
2147}
2148
[email protected]e60c0232011-11-11 19:56:352149#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182150void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2151 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382152 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082153 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392154#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452155 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392156 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2157 DCHECK(!data_path.empty());
2158
2159 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452160 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392161 base::PlatformFile f =
2162 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2163 DCHECK(f != base::kInvalidPlatformFileValue);
2164 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2165 FileDescriptor(f, true)));
2166
[email protected]650b2d52013-02-10 03:41:452167 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392168 data_path.AppendASCII("chrome_100_percent.pak");
2169 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2170 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372171 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392172 FileDescriptor(f, true)));
2173
2174 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452175 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392176 GetLocaleFilePath(locale, false);
2177 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2178 DCHECK(f != base::kInvalidPlatformFileValue);
2179 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2180 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382181
[email protected]650b2d52013-02-10 03:41:452182 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372183 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2184 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2185 DCHECK(f != base::kInvalidPlatformFileValue);
2186 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2187 FileDescriptor(f, true)));
2188
[email protected]40da3e0c2012-10-24 22:03:382189#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432190 if (IsCrashReporterEnabled()) {
2191 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2192 if (f == base::kInvalidPlatformFileValue) {
2193 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2194 "be disabled for this process.";
2195 } else {
2196 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2197 FileDescriptor(f, true)));
2198 }
[email protected]40da3e0c2012-10-24 22:03:382199 }
2200#endif // defined(USE_LINUX_BREAKPAD)
2201
2202#else
2203 int crash_signal_fd = GetCrashSignalFD(command_line);
2204 if (crash_signal_fd >= 0) {
2205 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2206 FileDescriptor(crash_signal_fd,
2207 false)));
2208 }
[email protected]29699c22012-10-03 23:57:392209#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302210}
[email protected]e60c0232011-11-11 19:56:352211#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302212
[email protected]4a65826d2011-08-25 16:04:012213#if defined(OS_WIN)
2214const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2215 return chrome::kBrowserResourcesDll;
2216}
[email protected]34f48682013-03-20 00:30:182217
2218void ChromeContentBrowserClient::PreSpawnRenderer(
2219 sandbox::TargetPolicy* policy,
2220 bool* success) {
2221 // This code is duplicated in nacl_exe_win_64.cc.
2222 // Allow the server side of a pipe restricted to the "chrome.nacl."
2223 // namespace so that it cannot impersonate other system or other chrome
2224 // service pipes.
2225 sandbox::ResultCode result = policy->AddRule(
2226 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2227 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2228 L"\\\\.\\pipe\\chrome.nacl.*");
2229 if (result != sandbox::SBOX_ALL_OK) {
2230 *success = false;
2231 return;
2232 }
2233
2234 // Renderers need to send named pipe handles and shared memory
2235 // segment handles to NaCl loader processes.
2236 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2237 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2238 L"File");
2239 if (result != sandbox::SBOX_ALL_OK) {
2240 *success = false;
2241 return;
2242 }
2243}
[email protected]4a65826d2011-08-25 16:04:012244#endif
2245
[email protected]37a72af2011-06-13 05:42:012246#if defined(USE_NSS)
2247crypto::CryptoModuleBlockingPasswordDelegate*
2248 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2249 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292250 return chrome::NewCryptoModuleBlockingDialogDelegate(
2251 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012252}
2253#endif
2254
[email protected]d977f9c2011-03-14 16:10:262255} // namespace chrome