blob: 6723deadf5438582074560211c400aacd70ef329 [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]b71313232013-05-06 06:16:2916#include "base/string_number_conversions.h"
[email protected]135cb802013-06-09 16:44:2017#include "base/strings/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]17263b22013-05-16 03:29:2233#include "chrome/browser/extensions/activity_log/activity_log.h"
[email protected]2b33dcd02012-03-18 01:34:1634#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]1deace22013-05-22 06:14:4635#include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
[email protected]76411f412012-02-22 18:56:0636#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0437#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3338#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2639#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0840#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2541#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0642#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5243#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2344#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1245#include "chrome/browser/google/google_util.h"
[email protected]11158e2d2013-02-01 02:31:5646#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0447#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]0c7193742012-11-07 19:05:0348#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2849#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0450#include "chrome/browser/notifications/desktop_notification_service.h"
51#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]93f72062013-05-29 20:29:4052#include "chrome/browser/pepper_permission_util.h"
[email protected]0609b17f2011-05-31 20:13:4253#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5654#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0655#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4156#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5057#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0758#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4159#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1460#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0361#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1462#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3263#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0664#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1465#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3866#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4367#include "chrome/browser/search/instant_service.h"
68#include "chrome/browser/search/instant_service_factory.h"
69#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1470#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0271#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3372#include "chrome/browser/speech/tts_message_filter.h"
[email protected]8ec71262011-07-28 08:12:4673#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5874#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0375#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5276#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4577#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5478#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4379#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]b5d73422012-06-02 23:46:4480#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5081#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]970c63e2013-03-07 00:25:3082#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
[email protected]f3986f82012-01-03 20:00:0683#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1584#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2785#include "chrome/browser/validation_message_message_filter.h"
[email protected]db9f2142013-05-27 22:56:1686#include "chrome/browser/webview/webview_guest.h"
[email protected]b80f68432011-05-02 17:22:3087#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0188#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1489#include "chrome/common/chrome_paths.h"
[email protected]f3b357692013-03-22 05:16:1390#include "chrome/common/chrome_process_type.h"
[email protected]b80f68432011-05-02 17:22:3091#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2992#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0493#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3894#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4495#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4396#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:2997#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]157cc902012-11-02 06:31:5898#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3499#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:12100#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38101#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09102#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53103#include "chromeos/chromeos_constants.h"
[email protected]75fee372013-03-06 00:42:44104#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43105#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30106#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38107#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:31108#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03109#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59110#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36111#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30112#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33113#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05114#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33115#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19116#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10117#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43118#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18119#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23120#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42121#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39122#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23123#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53124#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58125#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34126#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06127#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57128#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38129#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39130#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08131#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24132#include "ui/message_center/message_center_util.h"
[email protected]fab55e72013-05-31 07:06:18133#include "webkit/common/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04134#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26135
[email protected]b48c9182011-10-26 18:03:30136#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38137#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18138#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38139#elif defined(OS_MACOSX)
140#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56141#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30142#elif defined(OS_CHROMEOS)
143#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]5c915252013-05-07 13:15:39144#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49145#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]5c915252013-05-07 13:15:39146#include "chrome/browser/chromeos/system/statistics_provider.h"
[email protected]931d1042013-04-05 17:50:44147#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26148#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30149#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09150#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38151#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09152#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39153#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30154#elif defined(OS_POSIX)
155#include "chrome/browser/chrome_browser_main_posix.h"
156#endif
157
[email protected]6653c192012-04-10 22:52:44158#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30159#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12160#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43161#endif
[email protected]b80f68432011-05-02 17:22:30162
[email protected]1e87df32012-09-12 04:53:19163#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
164#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
165#endif
166
[email protected]29699c22012-10-03 23:57:39167#if defined(OS_ANDROID)
168#include "ui/base/ui_base_paths.h"
169#endif
170
[email protected]37a72af2011-06-13 05:42:01171#if defined(USE_NSS)
172#include "chrome/browser/ui/crypto_module_password_dialog.h"
173#endif
174
[email protected]d5bcd06f2013-04-21 08:07:24175#if !defined(OS_CHROMEOS)
176#include "chrome/browser/signin/signin_manager.h"
177#include "chrome/browser/signin/signin_manager_factory.h"
178#endif
179
[email protected]02250952013-04-24 23:52:53180#if !defined(OS_ANDROID)
181#include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h"
182#endif
183
[email protected]6ef98b5a2013-05-31 23:58:31184#if defined(ENABLE_WEBRTC)
185#include "chrome/browser/media/webrtc_logging_handler_host.h"
186#endif
187
[email protected]c7abd422012-09-25 00:20:08188using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47189using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03190using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39191using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31192using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59193using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08194using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00195using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11196using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33197using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13198using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06199using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34200using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40201using extensions::Manifest;
[email protected]631bb742011-11-02 11:29:39202
[email protected]c5dbef02011-05-13 05:06:09203namespace {
204
[email protected]eabbfb12013-04-05 23:28:35205// Cached version of the locale so we can return the locale on the I/O
206// thread.
207base::LazyInstance<std::string> g_io_thread_application_locale;
208
[email protected]93f72062013-05-29 20:29:40209#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40210const char* kPredefinedAllowedSocketOrigins[] = {
211 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18212 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45213 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
214 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
215 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
216 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35217 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54218 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
219 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
220 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
221 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
222 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
223 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38224 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58225 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29226 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
227 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
228 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
229 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
230 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40231};
[email protected]93f72062013-05-29 20:29:40232#endif
[email protected]e461da2f2012-02-16 19:06:40233
[email protected]f8f93eb2012-09-25 03:06:24234// Returns a copy of the given url with its host set to given host and path set
235// to given path. Other parts of the url will be the same.
236GURL ReplaceURLHostAndPath(const GURL& url,
237 const std::string& host,
238 const std::string& path) {
239 url_canon::Replacements<char> replacements;
240 replacements.SetHost(host.c_str(),
241 url_parse::Component(0, host.length()));
242 replacements.SetPath(path.c_str(),
243 url_parse::Component(0, path.length()));
244 return url.ReplaceComponents(replacements);
245}
246
247// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
248GURL AddUberHost(const GURL& url) {
249 const std::string uber_host = chrome::kChromeUIUberHost;
250 const std::string new_path = url.host() + url.path();
251
252 return ReplaceURLHostAndPath(url, uber_host, new_path);
253}
254
[email protected]045bf7c2012-09-28 20:27:36255// If url->host() is "chrome" and url->path() has characters other than the
256// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
257// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24258bool RemoveUberHost(GURL* url) {
259 if (url->host() != chrome::kChromeUIUberHost)
260 return false;
261
[email protected]045bf7c2012-09-28 20:27:36262 if (url->path().empty() || url->path() == "/")
263 return false;
264
[email protected]f8f93eb2012-09-25 03:06:24265 const std::string old_path = url->path();
266
267 const std::string::size_type separator = old_path.find('/', 1);
268 std::string new_host;
269 std::string new_path;
270 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36271 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24272 } else {
273 new_host = old_path.substr(1, separator - 1);
274 new_path = old_path.substr(separator);
275 }
276
277 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
278
279 return true;
280}
281
[email protected]b8148ac2011-07-13 22:03:25282// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42283bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24284 // Do not handle special URLs such as "about:foo"
285 if (!url->host().empty()) {
286 const GURL chrome_url = AddUberHost(*url);
287
288 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
289 // be called.
290 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
291 browser_context, chrome_url))
292 return true;
293 }
294
[email protected]863f70a2012-01-27 02:05:50295 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
296 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25297 return false;
298
[email protected]fe69558d2012-03-12 11:34:49299#if defined(OS_CHROMEOS)
300 // Special case : in ChromeOS in Guest mode bookmarks and history are
301 // disabled for security reasons. New tab page explains the reasons, so
302 // we redirect user to new tab page.
303 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
304 if (url->SchemeIs(chrome::kChromeUIScheme) &&
305 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
306 url->DomainIs(chrome::kChromeUIHistoryHost))) {
307 // Rewrite with new tab URL
308 *url = GURL(chrome::kChromeUINewTabURL);
309 }
310 }
311#endif
312
[email protected]b8148ac2011-07-13 22:03:25313 // Special case the new tab page. In older versions of Chrome, the new tab
314 // page was hosted at chrome-internal:<blah>. This might be in people's saved
315 // sessions or bookmarks, so we say any URL with that scheme triggers the new
316 // tab page.
317 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
318 // Rewrite it with the proper new tab URL.
319 *url = GURL(chrome::kChromeUINewTabURL);
320 }
321
322 return true;
323}
324
[email protected]f8f93eb2012-09-25 03:06:24325// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
326// "chrome://foo/".
327bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
328 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
329 return false;
330
331 return RemoveUberHost(url);
332}
333
[email protected]8d3132f62011-10-12 07:13:42334// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
335// below. Extension, and isolated apps require different privileges to be
336// granted to their RenderProcessHosts. This classification allows us to make
337// sure URLs are served by hosts with the right set of privileges.
338enum RenderProcessHostPrivilege {
339 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45340 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42341 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45342 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42343};
344
345RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
346 const GURL& url,
347 ExtensionService* service) {
348 // Default to a normal renderer cause it is lower privileged. This should only
349 // occur if the URL on a site instance is either malformed, or uninitialized.
350 // If it is malformed, then there is no need for better privileges anyways.
351 // If it is uninitialized, but eventually settles on being an a scheme other
352 // than normal webrenderer, the navigation logic will correct us out of band
353 // anyways.
354 if (!url.is_valid())
355 return PRIV_NORMAL;
356
[email protected]885c0e92012-11-13 20:27:42357 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44358 const Extension* extension =
359 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43360 if (extension &&
361 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42362 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45363 if (extension && extension->is_hosted_app())
364 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42365
366 return PRIV_EXTENSION;
367 }
368
369 return PRIV_NORMAL;
370}
371
372RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30373 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46374 extensions::ProcessMap* process_map,
375 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46376 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30377 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46378 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21379 return PRIV_NORMAL;
380
[email protected]6f371442011-11-09 06:45:46381 for (std::set<std::string>::iterator iter = extension_ids.begin();
382 iter != extension_ids.end(); ++iter) {
383 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43384 if (extension &&
385 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42386 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45387 if (extension && extension->is_hosted_app())
388 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42389 }
390
[email protected]676f6ab2011-10-19 20:23:21391 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42392}
393
[email protected]6786bf402011-12-03 15:19:45394bool CertMatchesFilter(const net::X509Certificate& cert,
395 const base::DictionaryValue& filter) {
396 // TODO(markusheintz): This is the minimal required filter implementation.
397 // Implement a better matcher.
398
399 // An empty filter matches any client certificate since no requirements are
400 // specified at all.
401 if (filter.empty())
402 return true;
403
404 std::string common_name;
405 if (filter.GetString("ISSUER.CN", &common_name) &&
406 (cert.issuer().common_name == common_name)) {
407 return true;
408 }
409 return false;
410}
411
[email protected]f3986f82012-01-03 20:00:06412// Fills |map| with the per-script font prefs under path |map_name|.
413void FillFontFamilyMap(const PrefService* prefs,
414 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53415 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06416 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
417 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
418 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
419 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23420 if (!font_family.empty())
421 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06422 }
423}
424
[email protected]a1733df2012-06-22 11:24:18425#if defined(OS_POSIX) && !defined(OS_MACOSX)
426int GetCrashSignalFD(const CommandLine& command_line) {
427 if (command_line.HasSwitch(switches::kExtensionProcess)) {
428 ExtensionCrashHandlerHostLinux* crash_handler =
429 ExtensionCrashHandlerHostLinux::GetInstance();
430 return crash_handler->GetDeathSignalSocket();
431 }
432
433 std::string process_type =
434 command_line.GetSwitchValueASCII(switches::kProcessType);
435
436 if (process_type == switches::kRendererProcess)
437 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
438
439 if (process_type == switches::kPluginProcess)
440 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
441
442 if (process_type == switches::kPpapiPluginProcess)
443 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
444
445 if (process_type == switches::kGpuProcess)
446 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
447
448 return -1;
449}
450#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
451
[email protected]d5bcd06f2013-04-21 08:07:24452#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30453GURL GetEffectiveURLForSignin(const GURL& url) {
454 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
455
456 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03457 // Copy the path because the argument to SetPathStr must outlive
458 // the Replacements object.
459 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30460 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03461 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30462 effective_url = effective_url.ReplaceComponents(replacements);
463 return effective_url;
464}
[email protected]d5bcd06f2013-04-21 08:07:24465#endif
[email protected]970c63e2013-03-07 00:25:30466
[email protected]eabbfb12013-04-05 23:28:35467void SetApplicationLocaleOnIOThread(const std::string& locale) {
468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
469 g_io_thread_application_locale.Get() = locale;
470}
471
[email protected]9dbfff12011-07-01 19:37:07472} // namespace
[email protected]c5dbef02011-05-13 05:06:09473
[email protected]d977f9c2011-03-14 16:10:26474namespace chrome {
475
[email protected]e461da2f2012-02-16 19:06:40476ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40477#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40478 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
479 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40480#endif
[email protected]1deace22013-05-22 06:14:46481
482 permissions_policy_delegate_.reset(
483 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40484}
485
486ChromeContentBrowserClient::~ChromeContentBrowserClient() {
487}
488
[email protected]bca18382012-06-25 19:15:23489// static
[email protected]c753f142013-02-10 13:14:04490void ChromeContentBrowserClient::RegisterUserPrefs(
[email protected]443e9312013-05-06 06:17:34491 user_prefs::PrefRegistrySyncable* registry) {
492 registry->RegisterBooleanPref(
493 prefs::kDisable3DAPIs,
494 false,
495 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
496 registry->RegisterBooleanPref(
497 prefs::kEnableHyperlinkAuditing,
498 true,
499 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
500 registry->RegisterBooleanPref(
501 prefs::kEnableMemoryInfo,
502 false,
503 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23504}
505
[email protected]eabbfb12013-04-05 23:28:35506// static
507void ChromeContentBrowserClient::SetApplicationLocale(
508 const std::string& locale) {
509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
510
511 // This object is guaranteed to outlive all threads so we don't have to
512 // worry about the lack of refcounting and can just post as Unretained.
513 //
514 // The common case is that this function is called early in Chrome startup
515 // before any threads are created (it will also be called later if the user
516 // changes the pref). In this case, there will be no threads created and
517 // posting will fail. When there are no threads, we can just set the string
518 // without worrying about threadsafety.
519 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
520 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
521 g_io_thread_application_locale.Get() = locale;
522 }
523}
524
[email protected]50462bf02011-11-21 19:13:31525content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
526 const content::MainFunctionParams& parameters) {
527 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30528 // Construct the Main browser parts based on the OS type.
529#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31530 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04531#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31532 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30533#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22534 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26535#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31536 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14537#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09538 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30539#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31540 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04541#else
[email protected]b48c9182011-10-26 18:03:30542 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31543 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30544#endif
545
[email protected]7e75e4a2013-05-17 17:20:03546 chrome::AddProfilesExtraParts(main_parts);
547
[email protected]c7480942011-11-08 19:18:27548 // Construct additional browser parts. Stages are called in the order in
549 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22550#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41551 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04552#endif
[email protected]c7480942011-11-08 19:18:27553
554#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41555 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27556#endif
557
[email protected]dc04be7c2012-03-15 23:57:49558#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41559 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49560#endif
561
[email protected]e050ef142012-03-21 01:04:24562#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41563 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24564#endif
565
[email protected]95132f52013-04-12 02:19:04566 chrome::AddMetricsExtraParts(main_parts);
567
[email protected]50462bf02011-11-21 19:13:31568 return main_parts;
[email protected]f967b722011-09-07 00:58:04569}
570
[email protected]e94bbcb2012-09-07 05:33:57571std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19572 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57573 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53574 std::string partition_id;
575
576 // The partition ID for webview guest processes is the string value of its
577 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
578 if (site.SchemeIs(chrome::kGuestScheme))
579 partition_id = site.spec();
580
[email protected]056efdc2013-04-06 00:14:53581 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53582 return partition_id;
583}
584
585bool ChromeContentBrowserClient::IsValidStoragePartitionId(
586 content::BrowserContext* browser_context,
587 const std::string& partition_id) {
588 // The default ID is empty and is always valid.
589 if (partition_id.empty())
590 return true;
591
592 return GURL(partition_id).is_valid();
593}
594
595void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
596 content::BrowserContext* browser_context,
597 const GURL& site,
[email protected]14acc642012-11-17 12:20:10598 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53599 std::string* partition_domain,
600 std::string* partition_name,
601 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10602 // Default to the browser-wide storage partition and override based on |site|
603 // below.
604 partition_domain->clear();
605 partition_name->clear();
606 *in_memory = false;
607
[email protected]1bc28312012-11-08 08:31:53608 // For the webview tag, we create special guest processes, which host the
609 // tag content separately from the main application that embeds the tag.
610 // A webview tag can specify both the partition name and whether the storage
611 // for that partition should be persisted. Each tag gets a SiteInstance with
612 // a specially formatted URL, based on the application it is hosted by and
613 // the partition requested by it. The format for that URL is:
614 // chrome-guest://partition_domain/persist?partition_name
615 if (site.SchemeIs(chrome::kGuestScheme)) {
616 // Since guest URLs are only used for packaged apps, there must be an app
617 // id in the URL.
618 CHECK(site.has_host());
619 *partition_domain = site.host();
620 // Since persistence is optional, the path must either be empty or the
621 // literal string.
622 *in_memory = (site.path() != "/persist");
623 // The partition name is user supplied value, which we have encoded when the
624 // URL was created, so it needs to be decoded.
625 *partition_name = net::UnescapeURLComponent(site.query(),
626 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10627 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
628 // If |can_be_default| is false, the caller is stating that the |site|
629 // should be parsed as if it had isolated storage. In particular it is
630 // important to NOT check ExtensionService for the is_storage_isolated()
631 // attribute because this code path is run during Extension uninstall
632 // to do cleanup after the Extension has already been unloaded from the
633 // ExtensionService.
634 bool is_isolated = !can_be_default;
635 if (can_be_default) {
636 const Extension* extension = NULL;
637 Profile* profile = Profile::FromBrowserContext(browser_context);
638 ExtensionService* extension_service =
639 extensions::ExtensionSystem::Get(profile)->extension_service();
640 if (extension_service) {
641 extension = extension_service->extensions()->
642 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43643 if (extension &&
644 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10645 is_isolated = true;
646 }
647 }
648 }
[email protected]1bc28312012-11-08 08:31:53649
[email protected]14acc642012-11-17 12:20:10650 if (is_isolated) {
651 CHECK(site.has_host());
652 // For extensions with isolated storage, the the host of the |site| is
653 // the |partition_domain|. The |in_memory| and |partition_name| are only
654 // used in guest schemes so they are cleared here.
655 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53656 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10657 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53658 }
[email protected]d1198fd2012-08-13 22:50:19659 }
660
[email protected]14acc642012-11-17 12:20:10661 // Assert that if |can_be_default| is false, the code above must have found a
662 // non-default partition. If this fails, the caller has a serious logic
663 // error about which StoragePartition they expect to be in and it is not
664 // safe to continue.
665 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44666}
667
[email protected]38b098f2012-03-14 21:11:57668content::WebContentsViewDelegate*
669 ChromeContentBrowserClient::GetWebContentsViewDelegate(
670 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27671 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32672}
673
[email protected]24665682013-02-25 20:59:38674// Check if the extension activity log is enabled for the profile.
675static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33676 // crbug.com/247908 - This should be IsLogEnabled except for an issue
677 // in chrome_frame_net_tests
678 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38679}
680
[email protected]44295a12013-06-05 08:45:46681void ChromeContentBrowserClient::GuestWebContentsAttached(
682 WebContents* guest_web_contents,
683 WebContents* embedder_web_contents,
684 int browser_plugin_instance_id) {
[email protected]44703cc72013-01-24 04:56:06685 Profile* profile = Profile::FromBrowserContext(
686 embedder_web_contents->GetBrowserContext());
687 ExtensionService* service =
688 extensions::ExtensionSystem::Get(profile)->extension_service();
689 if (!service)
690 return;
691 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
692 const Extension* extension = service->extensions()->
693 GetExtensionOrAppByURL(ExtensionURLInfo(url));
694 if (!extension)
695 return;
696 std::vector<ExtensionMsg_Loaded_Params> extensions;
697 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
698 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
[email protected]44295a12013-06-05 08:45:46699 new WebViewGuest(guest_web_contents,
700 embedder_web_contents,
701 extension->id(),
702 browser_plugin_instance_id);
[email protected]44703cc72013-01-24 04:56:06703}
704
[email protected]f3b1a082011-11-18 00:34:30705void ChromeContentBrowserClient::RenderProcessHostCreated(
706 content::RenderProcessHost* host) {
707 int id = host->GetID();
708 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41709 net::URLRequestContextGetter* context =
710 profile->GetRequestContextForRenderProcess(id);
711
[email protected]f3b1a082011-11-18 00:34:30712 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41713 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55714#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30715 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55716#endif
[email protected]658677f2012-06-09 06:04:02717#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08718 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03719#endif
[email protected]f3b1a082011-11-18 00:34:30720 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02721 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30722 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56723#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21724 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56725#endif
[email protected]43535512013-02-20 20:41:41726 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
727 id, profile, context));
[email protected]2736c032012-05-11 18:06:07728 host->GetChannel()->AddFilter(
729 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27730 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33731 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31732#if defined(ENABLE_WEBRTC)
733 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
734#endif
[email protected]3e69bc82011-05-26 23:22:38735
[email protected]2ccf45c2011-08-19 23:35:50736 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
737 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07738
[email protected]24665682013-02-25 20:59:38739 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
740 IsExtensionActivityLogEnabledForProfile(profile)));
741
[email protected]39a5b532011-10-22 01:47:07742 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56743
744 RendererContentSettingRules rules;
745 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
746 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14747}
748
[email protected]95c95552013-05-03 04:21:22749GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
750 content::BrowserContext* browser_context,
751 const GURL& url,
752 bool is_renderer_initiated,
753 content::SiteInstance* current_instance) {
754 Profile* profile = Profile::FromBrowserContext(browser_context);
755 if (!profile)
756 return url;
757
758 // Only return the privileged instant URL if we are entering from a browser-
759 // initiated navigation or if we are already in the instant process.
760 bool is_instant_process = false;
761 int process_id = current_instance->GetProcess()->GetID();
762 InstantService* instant_service =
763 InstantServiceFactory::GetForProfile(profile);
764 if (instant_service)
765 is_instant_process = instant_service->IsInstantProcess(process_id);
766
767 DCHECK_EQ(is_instant_process,
768 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
769 if (!is_renderer_initiated || is_instant_process) {
770 // If the input |url| should be assigned to the Instant renderer, make its
771 // privileged URL distinct from other URLs on the search provider's domain.
772 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
773 return chrome::GetPrivilegedURLForInstant(url, profile);
774 }
775
776 return url;
777}
778
[email protected]3d7474ff2011-07-27 17:47:37779GURL ChromeContentBrowserClient::GetEffectiveURL(
780 content::BrowserContext* browser_context, const GURL& url) {
781 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52782 if (!profile)
783 return url;
784
[email protected]d5bcd06f2013-04-21 08:07:24785#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30786 // If the input |url| should be assigned to the Signin renderer, make its
787 // effective URL distinct from other URLs on the signin service's domain.
788 // Note that the signin renderer will be allowed to sign the user in to
789 // Chrome.
790 if (SigninManager::IsWebBasedSigninFlowURL(url))
791 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24792#endif
[email protected]970c63e2013-03-07 00:25:30793
[email protected]c5dec6292013-01-25 04:54:52794 // If the input |url| is part of an installed app, the effective URL is an
795 // extension URL with the ID of that extension as the host. This has the
796 // effect of grouping apps together in a common SiteInstance.
797 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13798 extensions::ExtensionSystem::Get(profile)->extension_service();
799 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08800 return url;
801
[email protected]06bdd2b2012-11-30 18:47:13802 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44803 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08804 if (!extension)
805 return url;
806
[email protected]15877ca2011-11-18 22:40:52807 // Bookmark apps do not use the hosted app process model, and should be
808 // treated as normal URLs.
809 if (extension->from_bookmark())
810 return url;
811
[email protected]36fb2c7c2011-04-04 15:49:08812 // If the URL is part of an extension's web extent, convert it to an
813 // extension URL.
814 return extension->GetResourceURL(url.path());
815}
816
[email protected]056ad2a2011-07-12 02:13:55817bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37818 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52819 // Non-extension, non-Instant URLs should generally use
820 // process-per-site-instance. Because we expect to use the effective URL,
821 // URLs for hosted apps (apart from bookmark apps) should have an extension
822 // scheme by now.
823
824 Profile* profile = Profile::FromBrowserContext(browser_context);
825 if (!profile)
826 return false;
827
[email protected]165fe422013-03-27 06:34:03828 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52829 return true;
830
[email protected]d5bcd06f2013-04-21 08:07:24831#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30832 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
833 return true;
[email protected]d5bcd06f2013-04-21 08:07:24834#endif
[email protected]970c63e2013-03-07 00:25:30835
[email protected]885c0e92012-11-13 20:27:42836 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55837 return false;
838
[email protected]c5dec6292013-01-25 04:54:52839 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13840 extensions::ExtensionSystem::Get(profile)->extension_service();
841 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55842 return false;
843
[email protected]06bdd2b2012-11-30 18:47:13844 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44845 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55846 if (!extension)
847 return false;
848
849 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53850 // permission, or that does not allow JavaScript access to the background
851 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55852 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40853 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06854 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29855 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53856 return false;
857 }
858 }
[email protected]056ad2a2011-07-12 02:13:55859
[email protected]7b54ca02012-03-02 18:06:53860 // Hosted apps that have script access to their background page must use
861 // process per site, since all instances can make synchronous calls to the
862 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55863 return true;
864}
865
[email protected]672c8c12013-03-07 12:30:06866// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41867void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
868 std::vector<std::string>* additional_schemes) {
869 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06870}
871
[email protected]6bd30072013-02-08 18:17:11872net::URLRequestContextGetter*
873ChromeContentBrowserClient::CreateRequestContext(
874 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06875 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11876 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06877 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11878}
879
880net::URLRequestContextGetter*
881ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
882 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40883 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11884 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06885 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11886 Profile* profile = Profile::FromBrowserContext(browser_context);
887 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06888 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11889}
890
[email protected]46fb9442011-12-09 17:57:47891bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
892 return ProfileIOData::IsHandledURL(url);
893}
894
[email protected]c4365fa42013-05-14 01:08:24895bool ChromeContentBrowserClient::CanCommitURL(
896 content::RenderProcessHost* process_host,
897 const GURL& url) {
898 // We need to let most extension URLs commit in any process, since this can
899 // be allowed due to web_accessible_resources. Most hosted app URLs may also
900 // load in any process (e.g., in an iframe). However, the Chrome Web Store
901 // cannot be loaded in iframes and should never be requested outside its
902 // process.
903 Profile* profile =
904 Profile::FromBrowserContext(process_host->GetBrowserContext());
905 ExtensionService* service =
906 extensions::ExtensionSystem::Get(profile)->extension_service();
907 if (!service)
908 return true;
909 const Extension* new_extension =
910 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
911 if (new_extension &&
912 new_extension->is_hosted_app() &&
913 new_extension->id() == extension_misc::kWebStoreAppId &&
914 !service->process_map()->Contains(new_extension->id(),
915 process_host->GetID())) {
916 return false;
917 }
918
919 return true;
920}
921
[email protected]2a5221b2011-09-27 23:07:31922bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30923 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31924 const GURL& site_url) {
925 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30926 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52927 // This may be NULL during tests. In that case, just assume any site can
928 // share any host.
929 if (!profile)
930 return true;
931
[email protected]d43f99fe2013-04-03 00:20:14932 // Instant URLs should only be in the instant process and instant process
933 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52934 InstantService* instant_service =
935 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14936 if (instant_service) {
937 bool is_instant_process = instant_service->IsInstantProcess(
938 process_host->GetID());
939 bool should_be_in_instant_process =
940 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
941 if (is_instant_process || should_be_in_instant_process)
942 return is_instant_process && should_be_in_instant_process;
943 }
[email protected]c5dec6292013-01-25 04:54:52944
[email protected]d5bcd06f2013-04-21 08:07:24945#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30946 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
947 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
948 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:24949#endif
[email protected]970c63e2013-03-07 00:25:30950
[email protected]06bdd2b2012-11-30 18:47:13951 ExtensionService* service =
952 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46953 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31954
[email protected]ffa97602011-11-17 17:55:52955 // Don't allow the Task Manager to share a process with anything else.
956 // Otherwise it can affect the renderers it is observing.
957 // Note: we could create another RenderProcessHostPrivilege bucket for
958 // this to allow multiple chrome://tasks instances to share, but that's
959 // a very unlikely case without serious consequences.
960 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
961 return false;
962
[email protected]8d3132f62011-10-12 07:13:42963 // These may be NULL during tests. In that case, just assume any site can
964 // share any host.
[email protected]6f371442011-11-09 06:45:46965 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31966 return true;
967
[email protected]eec0b33c2011-12-05 22:09:45968 // Otherwise, just make sure the process privilege matches the privilege
969 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57970 RenderProcessHostPrivilege privilege_required =
971 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45972 return GetProcessPrivilege(process_host, process_map, service) ==
973 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31974}
975
[email protected]76411f412012-02-22 18:56:06976// This function is trying to limit the amount of processes used by extensions
977// with background pages. It uses a globally set percentage of processes to
978// run such extensions and if the limit is exceeded, it returns true, to
979// indicate to the content module to group extensions together.
980bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
981 content::BrowserContext* browser_context, const GURL& url) {
982 // It has to be a valid URL for us to check for an extension.
983 if (!url.is_valid())
984 return false;
985
986 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19987 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13988 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06989 if (!service)
990 return false;
991
992 // We have to have a valid extension with background page to proceed.
993 const Extension* extension =
994 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
995 if (!extension)
996 return false;
[email protected]9367eabc2013-03-01 01:29:29997 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06998 return false;
999
1000 std::set<int> process_ids;
1001 size_t max_process_count =
1002 content::RenderProcessHost::GetMaxRendererProcessCount();
1003
1004 // Go through all profiles to ensure we have total count of extension
1005 // processes containing background pages, otherwise one profile can
1006 // starve the other.
1007 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1008 GetLoadedProfiles();
1009 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031010 ExtensionProcessManager* epm =
1011 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321012 for (ExtensionProcessManager::const_iterator iter =
1013 epm->background_hosts().begin();
1014 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131015 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321016 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061017 }
1018 }
1019
1020 if (process_ids.size() >
1021 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1022 return true;
1023 }
1024
1025 return false;
1026}
1027
[email protected]6f371442011-11-09 06:45:461028void ChromeContentBrowserClient::SiteInstanceGotProcess(
1029 SiteInstance* site_instance) {
1030 CHECK(site_instance->HasProcess());
1031
1032 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021033 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521034 if (!profile)
1035 return;
1036
1037 // Remember the ID of the Instant process to signal the renderer process
1038 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031039 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321040 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521041 InstantService* instant_service =
1042 InstantServiceFactory::GetForProfile(profile);
1043 if (instant_service)
1044 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1045 }
1046
[email protected]d5bcd06f2013-04-21 08:07:241047#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301048 // We only expect there to be one signin process as we use process-per-site
1049 // for signin URLs. The signin process will be cleared from SigninManager
1050 // when the renderer is destroyed.
1051 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1052 SigninManager* signin_manager =
1053 SigninManagerFactory::GetForProfile(profile);
1054 if (signin_manager)
1055 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461056 BrowserThread::PostTask(
1057 BrowserThread::IO, FROM_HERE,
1058 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1059 extensions::ExtensionSystem::Get(profile)->info_map(),
1060 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301061 }
[email protected]d5bcd06f2013-04-21 08:07:241062#endif
[email protected]970c63e2013-03-07 00:25:301063
[email protected]06bdd2b2012-11-30 18:47:131064 ExtensionService* service =
1065 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461066 if (!service)
1067 return;
1068
1069 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441070 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591071 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461072 if (!extension)
1073 return;
1074
[email protected]6bc04fd82011-12-04 02:29:351075 service->process_map()->Insert(extension->id(),
1076 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331077 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461078 BrowserThread::PostTask(
1079 BrowserThread::IO, FROM_HERE,
1080 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591081 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461082 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351083 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331084 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461085}
1086
1087void ChromeContentBrowserClient::SiteInstanceDeleting(
1088 SiteInstance* site_instance) {
1089 if (!site_instance->HasProcess())
1090 return;
1091
1092 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021093 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131094 ExtensionService* service =
1095 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461096 if (!service)
1097 return;
1098
1099 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441100 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591101 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461102 if (!extension)
1103 return;
1104
[email protected]6bc04fd82011-12-04 02:29:351105 service->process_map()->Remove(extension->id(),
1106 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331107 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461108 BrowserThread::PostTask(
1109 BrowserThread::IO, FROM_HERE,
1110 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591111 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461112 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351113 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331114 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461115}
1116
[email protected]f05763972012-06-06 18:17:261117bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141118 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081119 const GURL& current_url,
1120 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261121 if (current_url.is_empty()) {
1122 // Always choose a new process when navigating to extension URLs. The
1123 // process grouping logic will combine all of a given extension's pages
1124 // into the same process.
[email protected]885c0e92012-11-13 20:27:421125 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261126 return true;
[email protected]e3daf3c2011-10-05 21:17:081127
[email protected]f05763972012-06-06 18:17:261128 return false;
1129 }
1130
1131 // Also, we must switch if one is an extension and the other is not the exact
1132 // same extension.
[email protected]885c0e92012-11-13 20:27:421133 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1134 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261135 if (current_url.GetOrigin() != new_url.GetOrigin())
1136 return true;
1137 }
1138
[email protected]e9841fbd2013-02-22 23:12:141139 // The checks below only matter if we can retrieve which extensions are
1140 // installed.
1141 Profile* profile =
1142 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1143 ExtensionService* service =
1144 extensions::ExtensionSystem::Get(profile)->extension_service();
1145 if (!service)
1146 return false;
1147
1148 // We must swap if the URL is for an extension and we are not using an
1149 // extension process.
1150 const Extension* new_extension =
1151 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1152 // Ignore all hosted apps except the Chrome Web Store, since they do not
1153 // require their own BrowsingInstance (e.g., postMessage is ok).
1154 if (new_extension &&
1155 new_extension->is_hosted_app() &&
1156 new_extension->id() != extension_misc::kWebStoreAppId)
1157 new_extension = NULL;
1158 if (new_extension &&
1159 site_instance->HasProcess() &&
1160 !service->process_map()->Contains(new_extension->id(),
1161 site_instance->GetProcess()->GetID()))
1162 return true;
1163
[email protected]f05763972012-06-06 18:17:261164 return false;
[email protected]e3daf3c2011-10-05 21:17:081165}
1166
[email protected]395045c2012-05-22 15:04:381167bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1168 content::ResourceContext* resource_context, const GURL& current_url,
1169 const GURL& new_url) {
1170 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1171 return extensions::CrossesExtensionProcessBoundary(
1172 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171173 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381174}
1175
[email protected]763ec4ca2011-04-29 15:48:121176std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1177 const std::string& alias_name) {
1178 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1179}
1180
[email protected]b80f68432011-05-02 17:22:301181void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1182 CommandLine* command_line, int child_process_id) {
1183#if defined(USE_LINUX_BREAKPAD)
1184 if (IsCrashReporterEnabled()) {
1185 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1186 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1187 }
1188#elif defined(OS_MACOSX)
1189 if (IsCrashReporterEnabled()) {
1190 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1191 child_process_logging::GetClientId());
1192 }
1193#endif // OS_MACOSX
1194
[email protected]f1933792011-06-14 00:49:341195 if (logging::DialogsAreSuppressed())
1196 command_line->AppendSwitch(switches::kNoErrorDialogs);
1197
[email protected]b80f68432011-05-02 17:22:301198 std::string process_type =
1199 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171200 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321201
1202 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1203 command_line->AppendSwitch(switches::kChromeFrame);
1204
[email protected]718eab62011-10-05 21:16:521205 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451206 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301207 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1208 if (!user_data_dir.empty())
1209 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1210#if defined(OS_CHROMEOS)
1211 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441212 browser_command_line.GetSwitchValueASCII(
1213 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301214 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441215 command_line->AppendSwitchASCII(
1216 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301217#endif
1218
[email protected]f3b1a082011-11-18 00:34:301219 content::RenderProcessHost* process =
1220 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371221 if (process) {
1222 Profile* profile = Profile::FromBrowserContext(
1223 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131224 ExtensionService* extension_service =
1225 extensions::ExtensionSystem::Get(profile)->extension_service();
1226 if (extension_service) {
1227 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001228 if (process_map && process_map->Contains(process->GetID()))
1229 command_line->AppendSwitch(switches::kExtensionProcess);
1230 }
[email protected]b80f68432011-05-02 17:22:301231
[email protected]a8d851f82011-12-21 00:32:371232 PrefService* prefs = profile->GetPrefs();
1233 // Currently this pref is only registered if applied via a policy.
1234 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1235 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1236 // Turn this policy into a command line switch.
1237 command_line->AppendSwitch(switches::kDisable3DAPIs);
1238 }
[email protected]718eab62011-10-05 21:16:521239
[email protected]a8d851f82011-12-21 00:32:371240 // Disable client-side phishing detection in the renderer if it is
1241 // disabled in the Profile preferences or the browser process.
1242 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1243 !g_browser_process->safe_browsing_detection_service()) {
1244 command_line->AppendSwitch(
1245 switches::kDisableClientSidePhishingDetection);
1246 }
[email protected]0045b0f42012-07-26 11:52:081247
1248 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211249 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521250
1251 InstantService* instant_service =
1252 InstantServiceFactory::GetForProfile(profile);
1253 if (instant_service &&
1254 instant_service->IsInstantProcess(process->GetID()))
1255 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301256
[email protected]d5bcd06f2013-04-21 08:07:241257#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301258 SigninManager* signin_manager =
1259 SigninManagerFactory::GetForProfile(profile);
1260 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1261 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241262#endif
[email protected]47c7ec82012-01-18 03:29:211263 }
[email protected]4287a3d2011-06-13 23:56:511264
[email protected]87552982012-11-02 17:21:401265 if (content::IsThreadedCompositingEnabled())
1266 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1267
[email protected]16dc42452013-04-09 04:37:191268 if (message_center::IsRichNotificationEnabled())
1269 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191270
[email protected]47c7ec82012-01-18 03:29:211271 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511272 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171273 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481274 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171275 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511276 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481277 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511278 switches::kAllowScriptingGallery,
1279 switches::kAppsCheckoutURL,
1280 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311281 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511282 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501283 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531284 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111285 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531286 switches::kEnableAdview,
1287 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211288 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511289 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511290 switches::kEnableIPCFuzzing,
1291 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451292 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481293 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051294 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511295 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291296 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511297 switches::kMemoryProfiling,
1298 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371299 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371300 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511301 switches::kPpapiFlashArgs,
1302 switches::kPpapiFlashInProcess,
1303 switches::kPpapiFlashPath,
1304 switches::kPpapiFlashVersion,
1305 switches::kProfilingAtStart,
1306 switches::kProfilingFile,
1307 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371308 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511309 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291310 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381311 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511312 };
1313
1314 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1315 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171316 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381317 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351318 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381319 switches::kEnableExperimentalExtensionApis,
1320 switches::kWhitelistedExtensionID,
1321 };
1322
1323 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1324 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511325 } else if (process_type == switches::kPluginProcess) {
1326 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441327#if defined(OS_CHROMEOS)
1328 chromeos::switches::kLoginProfile,
1329#endif
[email protected]4287a3d2011-06-13 23:56:511330 switches::kMemoryProfiling,
1331 switches::kSilentDumpOnDCHECK,
1332 switches::kUserDataDir,
1333 };
1334
1335 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1336 arraysize(kSwitchNames));
1337 } else if (process_type == switches::kZygoteProcess) {
1338 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511339 switches::kUserDataDir, // Make logs go to the right file.
1340 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501341 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511342 switches::kPpapiFlashInProcess,
1343 switches::kPpapiFlashPath,
1344 switches::kPpapiFlashVersion,
1345 };
1346
1347 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1348 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111349 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001350 base::FilePath user_data_dir =
1351 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1352 if (!user_data_dir.empty())
1353 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111354 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1355 // because GPU is expected to be unreliable.
1356 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1357 !command_line->HasSwitch(switches::kDisableBreakpad))
1358 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301359 }
[email protected]6f08af82011-09-15 01:19:031360
1361 // The command line switch kEnableBenchmarking needs to be specified along
1362 // with the kEnableStatsTable switch to ensure that the stats table global
1363 // is initialized correctly.
1364 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1365 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301366}
1367
1368std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431369 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351370 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301371 return g_browser_process->GetApplicationLocale();
1372}
1373
[email protected]597a867b2011-11-18 18:31:201374std::string ChromeContentBrowserClient::GetAcceptLangs(
1375 content::BrowserContext* context) {
1376 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371377 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081378}
1379
[email protected]9ec0f452012-05-31 15:58:531380gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221381 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531382 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081383}
1384
[email protected]a2176792011-05-08 19:30:491385bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091386 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191387 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201388 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201390 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051391 return io_data->GetCookieSettings()->
1392 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491393}
1394
[email protected]ed24fad2011-05-10 22:44:011395bool ChromeContentBrowserClient::AllowGetCookie(
1396 const GURL& url,
1397 const GURL& first_party,
1398 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201399 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011400 int render_process_id,
1401 int render_view_id) {
1402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201403 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051404 bool allow = io_data->GetCookieSettings()->
1405 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011406
[email protected]8093a542011-05-13 07:29:321407 BrowserThread::PostTask(
1408 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031409 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431410 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011411 return allow;
1412}
1413
1414bool ChromeContentBrowserClient::AllowSetCookie(
1415 const GURL& url,
1416 const GURL& first_party,
1417 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201418 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011419 int render_process_id,
1420 int render_view_id,
1421 net::CookieOptions* options) {
1422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201423 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051424 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1425 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1426
[email protected]8093a542011-05-13 07:29:321427 BrowserThread::PostTask(
1428 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031429 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431430 render_view_id, url, first_party, cookie_line, *options,
1431 !allow));
[email protected]ed24fad2011-05-10 22:44:011432 return allow;
1433}
1434
[email protected]d5a19162011-06-30 18:51:541435bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201436 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201438 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431439 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1440 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261441
[email protected]bf510ed2012-06-05 08:31:431442 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1443 // Could we even support per-origin settings?
1444 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541445}
1446
[email protected]5c5a88e2011-11-12 00:45:351447bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351448 const GURL& url,
1449 const string16& name,
1450 const string16& display_name,
1451 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201452 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481453 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351454 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201455 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351456 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1457 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1458
[email protected]62151052012-02-01 18:40:481459 // Record access to database for potential display in UI.
1460 std::vector<std::pair<int, int> >::const_iterator i;
1461 for (i = render_views.begin(); i != render_views.end(); ++i) {
1462 BrowserThread::PostTask(
1463 BrowserThread::UI, FROM_HERE,
1464 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1465 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351466 }
1467
1468 return allow;
1469}
1470
1471bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351472 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201473 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481474 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201476 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351477 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1478 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1479
[email protected]62151052012-02-01 18:40:481480 // Record access to file system for potential display in UI.
1481 std::vector<std::pair<int, int> >::const_iterator i;
1482 for (i = render_views.begin(); i != render_views.end(); ++i) {
1483 BrowserThread::PostTask(
1484 BrowserThread::UI, FROM_HERE,
1485 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1486 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351487 }
1488
1489 return allow;
1490}
1491
[email protected]7c5ff9a2012-03-02 07:42:491492bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1493 const GURL& url,
1494 const string16& name,
1495 content::ResourceContext* context,
1496 const std::vector<std::pair<int, int> >& render_views) {
1497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1498 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1499 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1500 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1501
1502 // Record access to IndexedDB for potential display in UI.
1503 std::vector<std::pair<int, int> >::const_iterator i;
1504 for (i = render_views.begin(); i != render_views.end(); ++i) {
1505 BrowserThread::PostTask(
1506 BrowserThread::UI, FROM_HERE,
1507 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1508 i->first, i->second, url, name, !allow));
1509 }
1510
1511 return allow;
1512}
1513
[email protected]6133f922011-07-01 21:34:341514net::URLRequestContext*
1515ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201516 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421518 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201519 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341520 return io_data->extensions_request_context();
1521 }
1522
1523 return NULL;
1524}
1525
[email protected]317f96c92011-05-31 06:53:411526QuotaPermissionContext*
1527ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1528 return new ChromeQuotaPermissionContext();
1529}
1530
[email protected]848dd042011-06-04 18:24:031531void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171532 int render_process_id,
1533 int render_view_id,
1534 int cert_error,
1535 const net::SSLInfo& ssl_info,
1536 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021537 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031538 bool overridable,
[email protected]d9be47702012-05-16 03:41:221539 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171540 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001541 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021542 if (resource_type != ResourceType::MAIN_FRAME) {
1543 // A sub-resource has a certificate error. The user doesn't really
1544 // have a context for making the right decision, so block the
1545 // request hard, without an info bar to allow showing the insecure
1546 // content.
[email protected]8c965c22013-05-23 19:28:001547 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021548 return;
1549 }
1550
[email protected]f9034cf2011-07-21 12:43:411551 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131552 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171553 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411554 if (!tab) {
1555 NOTREACHED();
1556 return;
1557 }
1558 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501559 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301560 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011561 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1562 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411563 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171564 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411565 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001566 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411567 return;
1568 }
1569 }
1570
[email protected]1e87df32012-09-12 04:53:191571#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231572 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1573 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1574 if (captive_portal_tab_helper)
1575 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191576#endif
1577
[email protected]f9034cf2011-07-21 12:43:411578 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221579 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1580 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031581}
1582
[email protected]c99c442e2011-08-24 11:37:301583void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451584 int render_process_id,
1585 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401586 const net::HttpNetworkSession* network_session,
1587 net::SSLCertRequestInfo* cert_request_info,
1588 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131589 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451590 render_process_id, render_view_id);
1591 if (!tab) {
1592 NOTREACHED();
1593 return;
1594 }
1595
[email protected]6786bf402011-12-03 15:19:451596 GURL requesting_url("https://" + cert_request_info->host_and_port);
1597 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1598 << cert_request_info->host_and_port;
1599
[email protected]627e0512011-12-21 22:55:301600 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451601 scoped_ptr<Value> filter(
1602 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1603 requesting_url,
1604 requesting_url,
1605 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1606 std::string(), NULL));
1607
1608 if (filter.get()) {
1609 // Try to automatically select a client certificate.
1610 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1611 DictionaryValue* filter_dict =
1612 static_cast<DictionaryValue*>(filter.get());
1613
1614 const std::vector<scoped_refptr<net::X509Certificate> >&
1615 all_client_certs = cert_request_info->client_certs;
1616 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091617 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451618 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091619 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451620 return;
1621 }
1622 }
1623 } else {
1624 NOTREACHED();
1625 }
1626 }
1627
[email protected]11feec322012-09-18 03:58:521628 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1629 if (!ssl_tab_helper) {
1630 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451631 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141632 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401633 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451634 return;
1635 }
[email protected]11feec322012-09-18 03:58:521636 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401637 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451638}
1639
[email protected]3b455502012-12-11 18:22:581640void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451641 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581642 net::CertificateMimeType cert_type,
1643 const void* cert_data,
1644 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451645 int render_process_id,
1646 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581647 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1648 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451649}
1650
[email protected]dc73a7b2012-03-25 15:27:181651content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561652 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181653}
1654
[email protected]941623e2011-06-07 23:06:041655void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1656 const GURL& source_origin,
1657 int callback_context,
1658 int render_process_id,
1659 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111660#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1662 WebContents* contents =
1663 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1664 if (!contents) {
[email protected]941623e2011-06-07 23:06:041665 NOTREACHED();
1666 return;
1667 }
1668
[email protected]d0d9c3ee2012-06-19 03:07:021669 // Skip showing the infobar if the request comes from an extension, and that
1670 // extension has the 'notify' permission. (If the extension does not have the
1671 // permission, the user will still be prompted.)
1672 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011673 ExtensionInfoMap* extension_info_map =
1674 extensions::ExtensionSystem::Get(profile)->info_map();
1675 DesktopNotificationService* notification_service =
1676 DesktopNotificationServiceFactory::GetForProfile(profile);
1677 const Extension* extension = NULL;
1678 if (extension_info_map) {
1679 ExtensionSet extensions;
1680 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1681 source_origin, render_process_id,
1682 extensions::APIPermission::kNotification, &extensions);
1683 for (ExtensionSet::const_iterator iter = extensions.begin();
1684 iter != extensions.end(); ++iter) {
1685 if (notification_service->IsExtensionEnabled((*iter)->id())) {
1686 extension = *iter;
1687 break;
1688 }
1689 }
1690 }
[email protected]eb4832a2012-12-08 01:57:521691 RenderViewHost* rvh =
1692 RenderViewHost::FromID(render_process_id, render_view_id);
1693 if (IsExtensionWithPermissionOrSuggestInConsole(
1694 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021695 if (rvh)
1696 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1697 return;
1698 }
1699
[email protected]c7cd5942013-04-30 03:31:011700 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021701 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111702#else
1703 NOTIMPLEMENTED();
1704#endif
[email protected]941623e2011-06-07 23:06:041705}
1706
1707WebKit::WebNotificationPresenter::Permission
1708 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021709 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201710 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021711 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111712#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041713 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201714 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041715
[email protected]c7cd5942013-04-30 03:31:011716 DesktopNotificationService* notification_service =
1717 io_data->GetNotificationService();
1718 if (notification_service) {
1719 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1720 ExtensionSet extensions;
1721 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1722 source_origin, render_process_id,
1723 extensions::APIPermission::kNotification, &extensions);
1724 for (ExtensionSet::const_iterator iter = extensions.begin();
1725 iter != extensions.end(); ++iter) {
1726 if (notification_service->IsExtensionEnabled((*iter)->id()))
1727 return WebKit::WebNotificationPresenter::PermissionAllowed;
1728 }
1729
1730 return notification_service->HasPermission(source_origin);
1731 }
1732
1733 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111734#else
1735 return WebKit::WebNotificationPresenter::PermissionAllowed;
1736#endif
[email protected]941623e2011-06-07 23:06:041737}
1738
1739void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171740 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041741 int render_process_id,
1742 int render_view_id,
1743 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111744#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041745 RenderViewHost* rvh = RenderViewHost::FromID(
1746 render_process_id, render_view_id);
1747 if (!rvh) {
1748 NOTREACHED();
1749 return;
1750 }
1751
[email protected]9f76c1e2012-03-05 15:15:581752 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301753 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041754 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371755 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041756 service->ShowDesktopNotification(
1757 params, render_process_id, render_view_id,
1758 worker ? DesktopNotificationService::WorkerNotification :
1759 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111760#else
1761 NOTIMPLEMENTED();
1762#endif
[email protected]941623e2011-06-07 23:06:041763}
1764
1765void ChromeContentBrowserClient::CancelDesktopNotification(
1766 int render_process_id,
1767 int render_view_id,
1768 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111769#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041770 RenderViewHost* rvh = RenderViewHost::FromID(
1771 render_process_id, render_view_id);
1772 if (!rvh) {
1773 NOTREACHED();
1774 return;
1775 }
1776
[email protected]9f76c1e2012-03-05 15:15:581777 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301778 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041779 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371780 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041781 service->CancelDesktopNotification(
1782 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111783#else
1784 NOTIMPLEMENTED();
1785#endif
[email protected]941623e2011-06-07 23:06:041786}
1787
[email protected]9f3fba52011-06-08 20:37:191788bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351789 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021790 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191791 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201792 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011793 int render_process_id,
1794 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191795 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011796
1797 *no_javascript_access = false;
1798
[email protected]9f3fba52011-06-08 20:37:191799 // If the opener is trying to create a background window but doesn't have
1800 // the appropriate permission, fail the attempt.
1801 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201802 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531803 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1804
[email protected]03b6d552012-03-29 04:03:011805 if (!map->SecurityOriginHasAPIPermission(
1806 source_origin,
1807 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061808 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011809 return false;
1810 }
1811
[email protected]7b54ca02012-03-02 18:06:531812 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1813 // return a recently installed Extension even if this CanCreateWindow call
1814 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011815 // because the permission check above would have caused an early return
1816 // already. We must use the full URL to find hosted apps, though, and not
1817 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531818 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351819 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291820 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011821 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191822 }
[email protected]056efdc2013-04-06 00:14:531823
1824 // No new browser window (popup or tab) in app mode.
1825 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1826 chrome::IsRunningInForcedAppMode()) {
1827 return false;
1828 }
1829
[email protected]9f3fba52011-06-08 20:37:191830 return true;
1831}
1832
1833std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201834 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191835 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1836 // Check if it's an extension-created worker, in which case we want to use
1837 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201838 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191839 const Extension* extension =
1840 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1841 return extension ? extension->name() : std::string();
1842}
1843
[email protected]99907362012-01-11 05:41:401844void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1845 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171846}
1847
[email protected]7a06d282013-05-03 04:39:331848// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021849content::SpeechRecognitionManagerDelegate*
1850 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]3bd0aab2013-05-30 20:07:491851#if !defined(OS_ANDROID)
[email protected]c52b2892012-03-07 11:01:021852 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321853#else
[email protected]3bd0aab2013-05-30 20:07:491854 // TODO(janx): Implement speech::AndroidSpeechRecognitionManagerDelegate
1855 // (see crbug.com/222352).
[email protected]a03f2d32012-03-14 00:26:321856 return NULL;
1857#endif
[email protected]66cfec62012-02-24 17:57:511858}
1859
[email protected]ae6e9912011-07-27 01:18:281860net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1861 return g_browser_process->net_log();
1862}
1863
[email protected]32538d92011-08-25 00:09:231864AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1865 return new ChromeAccessTokenStore();
1866}
1867
[email protected]dbae6b02011-06-29 23:51:411868bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011869 return true;
[email protected]dbae6b02011-06-29 23:51:411870}
1871
[email protected]64d69de42012-02-06 00:19:541872void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321873 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061874 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581875 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061876 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061877
[email protected]f3986f82012-01-03 20:00:061878 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541879 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061880 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541881 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061882 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541883 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061884 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541885 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061886 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541887 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061888 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541889 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031890 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1891 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061892
[email protected]64d69de42012-02-06 00:19:541893 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401894 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541895 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401896 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541897 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401898 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541899 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401900 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061901
[email protected]ddf72142012-05-22 04:52:401902 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061903
[email protected]64d69de42012-02-06 00:19:541904 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401905 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541906 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061907 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541908 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061909 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1910 const DictionaryValue* inspector_settings =
1911 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1912 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181913 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1914 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061915 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181916 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541917 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181918 std::make_pair(iter.key(), value));
1919 }
[email protected]f3986f82012-01-03 20:00:061920 }
1921 }
[email protected]64d69de42012-02-06 00:19:541922 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061923
[email protected]ddf72142012-05-22 04:52:401924 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541925 web_prefs->javascript_enabled = false;
1926 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1927 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401928 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541929 web_prefs->plugins_enabled = false;
1930 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1931 web_prefs->java_enabled = false;
1932 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401933 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061934
[email protected]64d69de42012-02-06 00:19:541935 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1936 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061937
[email protected]64d69de42012-02-06 00:19:541938 web_prefs->memory_info_enabled =
1939 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1940 web_prefs->allow_displaying_insecure_content =
1941 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1942 web_prefs->allow_running_insecure_content =
1943 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321944#if defined(OS_ANDROID)
1945 web_prefs->font_scale_factor =
1946 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1947 web_prefs->force_enable_zoom =
1948 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451949#if defined(GOOGLE_TV)
1950 web_prefs->user_gesture_required_for_media_playback = false;
1951#endif
[email protected]d3b935f2012-10-19 23:14:321952#endif
[email protected]5c915252013-05-07 13:15:391953
[email protected]af4256d52013-06-04 20:39:071954#if defined(OS_ANDROID)
1955 web_prefs->password_echo_enabled =
1956 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
1957#else
[email protected]9d06d88d2012-02-23 22:37:081958 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:071959#endif
1960
[email protected]5c915252013-05-07 13:15:391961#if defined(OS_CHROMEOS)
1962 // Enable password echo during OOBE when keyboard driven flag is set.
1963 if (chromeos::UserManager::IsInitialized() &&
1964 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
1965 !chromeos::StartupUtils::IsOobeCompleted()) {
1966 bool keyboard_driven_oobe = false;
1967 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]e8f3f9982013-05-10 20:59:531968 chromeos::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:391969 if (keyboard_driven_oobe)
1970 web_prefs->password_echo_enabled = true;
1971 }
1972#endif
[email protected]f3986f82012-01-03 20:00:061973
[email protected]46f8e742013-05-03 18:37:141974#if defined(OS_ANDROID)
1975 web_prefs->user_style_sheet_enabled = false;
1976#else
[email protected]64d69de42012-02-06 00:19:541977 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151978 UserStyleSheetWatcher* user_style_sheet_watcher =
1979 UserStyleSheetWatcherFactory::GetForProfile(profile);
1980 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541981 web_prefs->user_style_sheet_enabled = true;
1982 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151983 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541984 } else {
1985 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061986 }
[email protected]46f8e742013-05-03 18:37:141987#endif
[email protected]f3986f82012-01-03 20:00:061988
[email protected]cfadadd2013-04-03 04:43:021989 web_prefs->asynchronous_spell_checking_enabled = true;
1990 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:571991
[email protected]64d69de42012-02-06 00:19:541992 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061993 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541994 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061995 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541996 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061997 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1998
1999 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542000 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062001 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542002 web_prefs->default_encoding);
2003 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402004 prefs->ClearPref(prefs::kDefaultCharset);
2005 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062006 }
[email protected]64d69de42012-02-06 00:19:542007 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062008
[email protected]88ecf66d2012-12-11 22:53:472009 if (content::IsForceCompositingModeEnabled())
2010 web_prefs->force_compositing_mode = true;
2011
[email protected]299d7f12012-05-23 05:31:152012 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232013 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132014 ExtensionService* service =
2015 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062016 if (service) {
[email protected]1bc28312012-11-08 08:31:532017 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2018 const Extension* extension = service->extensions()->GetByID(url.host());
2019 // Ensure that we are only granting extension preferences to URLs with
2020 // the correct scheme. Without this check, chrome-guest:// schemes used by
2021 // webview tags as well as hosts that happen to match the id of an
2022 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422023 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532024 extension_webkit_preferences::SetPreferences(
2025 extension, view_type, web_prefs);
2026 }
[email protected]f3986f82012-01-03 20:00:062027 }
2028
[email protected]cb2edf22013-04-01 20:25:232029 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542030 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232031 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062032 // Disable all kinds of acceleration for background pages.
2033 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542034 web_prefs->force_compositing_mode = false;
2035 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062036 }
[email protected]2e21fe292012-03-02 22:52:322037
2038#if defined(FILE_MANAGER_EXTENSION)
2039 // Override the default of suppressing HW compositing for WebUI pages for the
2040 // file manager, which is implemented using WebUI but wants HW acceleration
2041 // for video decode & render.
2042 if (url.spec() == chrome::kChromeUIFileManagerURL) {
2043 web_prefs->accelerated_compositing_enabled = true;
2044 web_prefs->accelerated_2d_canvas_enabled = true;
2045 }
2046#endif
[email protected]181a95ee2011-07-12 19:26:362047}
2048
2049void ChromeContentBrowserClient::UpdateInspectorSetting(
2050 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062051 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582052 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062053 DictionaryPrefUpdate update(
2054 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2055 prefs::kWebKitInspectorSettings);
2056 DictionaryValue* inspector_settings = update.Get();
2057 inspector_settings->SetWithoutPathExpansion(key,
2058 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362059}
2060
[email protected]b8148ac2011-07-13 22:03:252061void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2062 BrowserURLHandler* handler) {
2063 // Add the default URL handlers.
2064 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2065 BrowserURLHandler::null_handler());
2066 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2067 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2068
[email protected]b3adbd02011-11-30 22:23:272069 // about: handler. Must come before chrome: handler, since it will
2070 // rewrite about: urls to chrome: URLs and then expect chrome: to
2071 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252072 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2073 BrowserURLHandler::null_handler());
2074 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242075 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252076}
2077
2078void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372079 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582080 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472081 BrowsingDataRemover* remover =
2082 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552083 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2084 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252085 // BrowsingDataRemover takes care of deleting itself when done.
2086}
2087
2088void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372089 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582090 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472091 BrowsingDataRemover* remover =
2092 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232093 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552094 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252095 // BrowsingDataRemover takes care of deleting itself when done.
2096}
2097
[email protected]650b2d52013-02-10 03:41:452098base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322099 return download_util::GetDefaultDownloadDirectory();
2100}
2101
[email protected]c9b6eb62011-10-18 20:49:392102std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2103 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2104}
2105
[email protected]b7631cc2012-09-15 05:08:382106void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2107 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542108#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382109 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2110 scoped_ptr<ppapi::host::HostFactory>(
2111 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542112#endif
[email protected]b7631cc2012-09-15 05:08:382113}
2114
[email protected]0c7193742012-11-07 19:05:032115content::BrowserPpapiHost*
2116 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2117 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132118 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032119 while (!iter.Done()) {
2120 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2121 if (host->process() &&
2122 host->process()->GetData().id == plugin_process_id) {
2123 // Found the plugin.
2124 return host->browser_ppapi_host();
2125 }
2126 ++iter;
2127 }
2128 return NULL;
2129}
2130
[email protected]7b38b192013-03-23 18:39:312131bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2132 content::BrowserContext* browser_context, const GURL& site_url) {
2133 if (CommandLine::ForCurrentProcess()->HasSwitch(
2134 switches::kEnableBrowserPluginForAllViewTypes))
2135 return true;
2136
2137 Profile* profile = Profile::FromBrowserContext(browser_context);
2138 ExtensionService* service =
2139 extensions::ExtensionSystem::Get(profile)->extension_service();
2140 if (!service)
2141 return false;
2142
2143 const Extension* extension = service->extensions()->
2144 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2145 if (!extension)
2146 return false;
2147
[email protected]c2d2f102013-04-29 16:42:582148 return extension->HasAPIPermission(APIPermission::kWebView) ||
2149 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312150}
2151
[email protected]38cd8f7f2012-06-15 22:06:072152bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582153 content::BrowserContext* browser_context,
2154 const GURL& url,
2155 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402156#if defined(ENABLE_PLUGINS)
2157 return IsExtensionOrSharedModuleWhitelisted(
2158 Profile::FromBrowserContext(browser_context),
2159 url,
2160 allowed_socket_origins_,
2161 switches::kAllowNaClSocketAPI);
2162#else
[email protected]a658d452012-03-02 12:45:292163 return false;
[email protected]93f72062013-05-29 20:29:402164#endif
[email protected]e461da2f2012-02-16 19:06:402165}
2166
[email protected]650b2d52013-02-10 03:41:452167base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2168 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142169 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2170 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2171}
2172
[email protected]a28e3302013-02-03 03:50:432173ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2174 WebContents* web_contents) {
2175 return new ChromeSelectFilePolicy(web_contents);
2176}
2177
[email protected]7d9424702013-04-14 13:14:162178void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2179 std::vector<std::string>* additional_allowed_schemes) {
2180 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2181 additional_allowed_schemes);
2182 additional_allowed_schemes->push_back(kChromeUIScheme);
2183 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2184}
2185
[email protected]02250952013-04-24 23:52:532186void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2187 const base::FilePath& storage_partition_path,
2188 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2189#if !defined(OS_ANDROID)
2190 additional_providers->push_back(new MediaFileSystemMountPointProvider(
2191 storage_partition_path));
2192#endif
2193}
2194
[email protected]e60c0232011-11-11 19:56:352195#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182196void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2197 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382198 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082199 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392200#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452201 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392202 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2203 DCHECK(!data_path.empty());
2204
2205 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452206 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392207 base::PlatformFile f =
2208 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2209 DCHECK(f != base::kInvalidPlatformFileValue);
2210 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2211 FileDescriptor(f, true)));
2212
[email protected]650b2d52013-02-10 03:41:452213 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392214 data_path.AppendASCII("chrome_100_percent.pak");
2215 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2216 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372217 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392218 FileDescriptor(f, true)));
2219
2220 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452221 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392222 GetLocaleFilePath(locale, false);
2223 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2224 DCHECK(f != base::kInvalidPlatformFileValue);
2225 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2226 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382227
[email protected]650b2d52013-02-10 03:41:452228 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372229 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2230 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2231 DCHECK(f != base::kInvalidPlatformFileValue);
2232 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2233 FileDescriptor(f, true)));
2234
[email protected]40da3e0c2012-10-24 22:03:382235#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432236 if (IsCrashReporterEnabled()) {
2237 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2238 if (f == base::kInvalidPlatformFileValue) {
2239 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2240 "be disabled for this process.";
2241 } else {
2242 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2243 FileDescriptor(f, true)));
2244 }
[email protected]40da3e0c2012-10-24 22:03:382245 }
2246#endif // defined(USE_LINUX_BREAKPAD)
2247
2248#else
2249 int crash_signal_fd = GetCrashSignalFD(command_line);
2250 if (crash_signal_fd >= 0) {
2251 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2252 FileDescriptor(crash_signal_fd,
2253 false)));
2254 }
[email protected]29699c22012-10-03 23:57:392255#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302256}
[email protected]e60c0232011-11-11 19:56:352257#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302258
[email protected]4a65826d2011-08-25 16:04:012259#if defined(OS_WIN)
2260const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2261 return chrome::kBrowserResourcesDll;
2262}
[email protected]34f48682013-03-20 00:30:182263
2264void ChromeContentBrowserClient::PreSpawnRenderer(
2265 sandbox::TargetPolicy* policy,
2266 bool* success) {
2267 // This code is duplicated in nacl_exe_win_64.cc.
2268 // Allow the server side of a pipe restricted to the "chrome.nacl."
2269 // namespace so that it cannot impersonate other system or other chrome
2270 // service pipes.
2271 sandbox::ResultCode result = policy->AddRule(
2272 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2273 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2274 L"\\\\.\\pipe\\chrome.nacl.*");
2275 if (result != sandbox::SBOX_ALL_OK) {
2276 *success = false;
2277 return;
2278 }
2279
2280 // Renderers need to send named pipe handles and shared memory
2281 // segment handles to NaCl loader processes.
2282 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2283 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2284 L"File");
2285 if (result != sandbox::SBOX_ALL_OK) {
2286 *success = false;
2287 return;
2288 }
2289}
[email protected]4a65826d2011-08-25 16:04:012290#endif
2291
[email protected]37a72af2011-06-13 05:42:012292#if defined(USE_NSS)
2293crypto::CryptoModuleBlockingPasswordDelegate*
2294 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2295 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292296 return chrome::NewCryptoModuleBlockingDialogDelegate(
2297 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012298}
2299#endif
2300
[email protected]d977f9c2011-03-14 16:10:262301} // namespace chrome