blob: d545ba3be8b2c47d73cd349e7f6d9b03e9b9f69a [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]e7463412013-06-10 22:53:4616#include "base/strings/string_number_conversions.h"
[email protected]135cb802013-06-09 16:44:2017#include "base/strings/utf_string_conversions.h"
[email protected]30a306f42013-06-10 03:09:0318#include "base/threading/sequenced_worker_pool.h"
[email protected]b80f68432011-05-02 17:22:3019#include "chrome/app/breakpad_mac.h"
[email protected]056efdc2013-04-06 00:14:5320#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]b8148ac2011-07-13 22:03:2521#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3022#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4723#include "chrome/browser/browsing_data/browsing_data_helper.h"
24#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1225#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4126#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4127#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5628#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0529#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4530#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3231#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0832#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3233#include "chrome/browser/download/download_util.h"
[email protected]17263b22013-05-16 03:29:2234#include "chrome/browser/extensions/activity_log/activity_log.h"
[email protected]2b33dcd02012-03-18 01:34:1635#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]1deace22013-05-22 06:14:4636#include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
[email protected]76411f412012-02-22 18:56:0637#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0438#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3339#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2640#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0841#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2542#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0643#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5244#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2345#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1246#include "chrome/browser/google/google_util.h"
[email protected]11158e2d2013-02-01 02:31:5647#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0448#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]0c7193742012-11-07 19:05:0349#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2850#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0451#include "chrome/browser/notifications/desktop_notification_service.h"
52#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]93f72062013-05-29 20:29:4053#include "chrome/browser/pepper_permission_util.h"
[email protected]0609b17f2011-05-31 20:13:4254#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5655#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0656#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4157#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5058#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0759#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4160#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1461#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0362#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1463#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3264#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0665#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1466#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3867#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4368#include "chrome/browser/search/instant_service.h"
69#include "chrome/browser/search/instant_service_factory.h"
70#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1471#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0272#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3373#include "chrome/browser/speech/tts_message_filter.h"
[email protected]8ec71262011-07-28 08:12:4674#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5875#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0376#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5277#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4578#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5479#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4380#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]b5d73422012-06-02 23:46:4481#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5082#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]970c63e2013-03-07 00:25:3083#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
[email protected]f3986f82012-01-03 20:00:0684#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1585#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2786#include "chrome/browser/validation_message_message_filter.h"
[email protected]db9f2142013-05-27 22:56:1687#include "chrome/browser/webview/webview_guest.h"
[email protected]b80f68432011-05-02 17:22:3088#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0189#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1490#include "chrome/common/chrome_paths.h"
[email protected]f3b357692013-03-22 05:16:1391#include "chrome/common/chrome_process_type.h"
[email protected]b80f68432011-05-02 17:22:3092#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2993#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0494#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3895#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4496#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4397#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:2998#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]157cc902012-11-02 06:31:5899#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:34100#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:12101#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38102#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09103#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53104#include "chromeos/chromeos_constants.h"
[email protected]75fee372013-03-06 00:42:44105#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43106#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30107#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38108#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03109#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31110#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03111#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59112#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36113#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30114#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33115#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05116#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33117#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19118#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10119#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43120#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18121#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23122#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42123#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39124#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23125#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53126#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58127#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34128#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06129#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57130#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38131#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39132#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08133#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24134#include "ui/message_center/message_center_util.h"
[email protected]fab55e72013-05-31 07:06:18135#include "webkit/common/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04136#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26137
[email protected]b48c9182011-10-26 18:03:30138#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38139#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18140#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38141#elif defined(OS_MACOSX)
142#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56143#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30144#elif defined(OS_CHROMEOS)
145#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]5c915252013-05-07 13:15:39146#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49147#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]5c915252013-05-07 13:15:39148#include "chrome/browser/chromeos/system/statistics_provider.h"
[email protected]931d1042013-04-05 17:50:44149#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26150#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30151#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09152#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38153#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09154#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39155#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30156#elif defined(OS_POSIX)
157#include "chrome/browser/chrome_browser_main_posix.h"
158#endif
159
[email protected]6653c192012-04-10 22:52:44160#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30161#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12162#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43163#endif
[email protected]b80f68432011-05-02 17:22:30164
[email protected]1e87df32012-09-12 04:53:19165#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
166#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
167#endif
168
[email protected]29699c22012-10-03 23:57:39169#if defined(OS_ANDROID)
170#include "ui/base/ui_base_paths.h"
171#endif
172
[email protected]37a72af2011-06-13 05:42:01173#if defined(USE_NSS)
174#include "chrome/browser/ui/crypto_module_password_dialog.h"
175#endif
176
[email protected]d5bcd06f2013-04-21 08:07:24177#if !defined(OS_CHROMEOS)
178#include "chrome/browser/signin/signin_manager.h"
179#include "chrome/browser/signin/signin_manager_factory.h"
180#endif
181
[email protected]02250952013-04-24 23:52:53182#if !defined(OS_ANDROID)
183#include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h"
184#endif
185
[email protected]6ef98b5a2013-05-31 23:58:31186#if defined(ENABLE_WEBRTC)
187#include "chrome/browser/media/webrtc_logging_handler_host.h"
188#endif
189
[email protected]c7abd422012-09-25 00:20:08190using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47191using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03192using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39193using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31194using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59195using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08196using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00197using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11198using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33199using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13200using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06201using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34202using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40203using extensions::Manifest;
[email protected]631bb742011-11-02 11:29:39204
[email protected]c5dbef02011-05-13 05:06:09205namespace {
206
[email protected]eabbfb12013-04-05 23:28:35207// Cached version of the locale so we can return the locale on the I/O
208// thread.
209base::LazyInstance<std::string> g_io_thread_application_locale;
210
[email protected]93f72062013-05-29 20:29:40211#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40212const char* kPredefinedAllowedSocketOrigins[] = {
213 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18214 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45215 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
216 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
217 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
218 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35219 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54220 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
221 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
222 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
223 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
224 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
225 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38226 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58227 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29228 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
229 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
230 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
231 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
232 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40233};
[email protected]93f72062013-05-29 20:29:40234#endif
[email protected]e461da2f2012-02-16 19:06:40235
[email protected]f8f93eb2012-09-25 03:06:24236// Returns a copy of the given url with its host set to given host and path set
237// to given path. Other parts of the url will be the same.
238GURL ReplaceURLHostAndPath(const GURL& url,
239 const std::string& host,
240 const std::string& path) {
241 url_canon::Replacements<char> replacements;
242 replacements.SetHost(host.c_str(),
243 url_parse::Component(0, host.length()));
244 replacements.SetPath(path.c_str(),
245 url_parse::Component(0, path.length()));
246 return url.ReplaceComponents(replacements);
247}
248
249// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
250GURL AddUberHost(const GURL& url) {
251 const std::string uber_host = chrome::kChromeUIUberHost;
252 const std::string new_path = url.host() + url.path();
253
254 return ReplaceURLHostAndPath(url, uber_host, new_path);
255}
256
[email protected]045bf7c2012-09-28 20:27:36257// If url->host() is "chrome" and url->path() has characters other than the
258// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
259// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24260bool RemoveUberHost(GURL* url) {
261 if (url->host() != chrome::kChromeUIUberHost)
262 return false;
263
[email protected]045bf7c2012-09-28 20:27:36264 if (url->path().empty() || url->path() == "/")
265 return false;
266
[email protected]f8f93eb2012-09-25 03:06:24267 const std::string old_path = url->path();
268
269 const std::string::size_type separator = old_path.find('/', 1);
270 std::string new_host;
271 std::string new_path;
272 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36273 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24274 } else {
275 new_host = old_path.substr(1, separator - 1);
276 new_path = old_path.substr(separator);
277 }
278
279 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
280
281 return true;
282}
283
[email protected]b8148ac2011-07-13 22:03:25284// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42285bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24286 // Do not handle special URLs such as "about:foo"
287 if (!url->host().empty()) {
288 const GURL chrome_url = AddUberHost(*url);
289
290 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
291 // be called.
292 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
293 browser_context, chrome_url))
294 return true;
295 }
296
[email protected]863f70a2012-01-27 02:05:50297 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
298 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25299 return false;
300
[email protected]fe69558d2012-03-12 11:34:49301#if defined(OS_CHROMEOS)
302 // Special case : in ChromeOS in Guest mode bookmarks and history are
303 // disabled for security reasons. New tab page explains the reasons, so
304 // we redirect user to new tab page.
305 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
306 if (url->SchemeIs(chrome::kChromeUIScheme) &&
307 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
308 url->DomainIs(chrome::kChromeUIHistoryHost))) {
309 // Rewrite with new tab URL
310 *url = GURL(chrome::kChromeUINewTabURL);
311 }
312 }
313#endif
314
[email protected]b8148ac2011-07-13 22:03:25315 // Special case the new tab page. In older versions of Chrome, the new tab
316 // page was hosted at chrome-internal:<blah>. This might be in people's saved
317 // sessions or bookmarks, so we say any URL with that scheme triggers the new
318 // tab page.
319 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
320 // Rewrite it with the proper new tab URL.
321 *url = GURL(chrome::kChromeUINewTabURL);
322 }
323
324 return true;
325}
326
[email protected]f8f93eb2012-09-25 03:06:24327// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
328// "chrome://foo/".
329bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
330 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
331 return false;
332
333 return RemoveUberHost(url);
334}
335
[email protected]8d3132f62011-10-12 07:13:42336// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
337// below. Extension, and isolated apps require different privileges to be
338// granted to their RenderProcessHosts. This classification allows us to make
339// sure URLs are served by hosts with the right set of privileges.
340enum RenderProcessHostPrivilege {
341 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45342 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42343 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45344 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42345};
346
347RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
348 const GURL& url,
349 ExtensionService* service) {
350 // Default to a normal renderer cause it is lower privileged. This should only
351 // occur if the URL on a site instance is either malformed, or uninitialized.
352 // If it is malformed, then there is no need for better privileges anyways.
353 // If it is uninitialized, but eventually settles on being an a scheme other
354 // than normal webrenderer, the navigation logic will correct us out of band
355 // anyways.
356 if (!url.is_valid())
357 return PRIV_NORMAL;
358
[email protected]885c0e92012-11-13 20:27:42359 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44360 const Extension* extension =
361 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43362 if (extension &&
363 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42364 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45365 if (extension && extension->is_hosted_app())
366 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42367
368 return PRIV_EXTENSION;
369 }
370
371 return PRIV_NORMAL;
372}
373
374RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30375 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46376 extensions::ProcessMap* process_map,
377 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46378 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30379 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46380 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21381 return PRIV_NORMAL;
382
[email protected]6f371442011-11-09 06:45:46383 for (std::set<std::string>::iterator iter = extension_ids.begin();
384 iter != extension_ids.end(); ++iter) {
385 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43386 if (extension &&
387 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42388 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45389 if (extension && extension->is_hosted_app())
390 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42391 }
392
[email protected]676f6ab2011-10-19 20:23:21393 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42394}
395
[email protected]6786bf402011-12-03 15:19:45396bool CertMatchesFilter(const net::X509Certificate& cert,
397 const base::DictionaryValue& filter) {
398 // TODO(markusheintz): This is the minimal required filter implementation.
399 // Implement a better matcher.
400
401 // An empty filter matches any client certificate since no requirements are
402 // specified at all.
403 if (filter.empty())
404 return true;
405
406 std::string common_name;
407 if (filter.GetString("ISSUER.CN", &common_name) &&
408 (cert.issuer().common_name == common_name)) {
409 return true;
410 }
411 return false;
412}
413
[email protected]f3986f82012-01-03 20:00:06414// Fills |map| with the per-script font prefs under path |map_name|.
415void FillFontFamilyMap(const PrefService* prefs,
416 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53417 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06418 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
419 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
420 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
421 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23422 if (!font_family.empty())
423 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06424 }
425}
426
[email protected]a1733df2012-06-22 11:24:18427#if defined(OS_POSIX) && !defined(OS_MACOSX)
428int GetCrashSignalFD(const CommandLine& command_line) {
429 if (command_line.HasSwitch(switches::kExtensionProcess)) {
430 ExtensionCrashHandlerHostLinux* crash_handler =
431 ExtensionCrashHandlerHostLinux::GetInstance();
432 return crash_handler->GetDeathSignalSocket();
433 }
434
435 std::string process_type =
436 command_line.GetSwitchValueASCII(switches::kProcessType);
437
438 if (process_type == switches::kRendererProcess)
439 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
440
441 if (process_type == switches::kPluginProcess)
442 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
443
444 if (process_type == switches::kPpapiPluginProcess)
445 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
446
447 if (process_type == switches::kGpuProcess)
448 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
449
450 return -1;
451}
452#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
453
[email protected]d5bcd06f2013-04-21 08:07:24454#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30455GURL GetEffectiveURLForSignin(const GURL& url) {
456 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
457
458 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03459 // Copy the path because the argument to SetPathStr must outlive
460 // the Replacements object.
461 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30462 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03463 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30464 effective_url = effective_url.ReplaceComponents(replacements);
465 return effective_url;
466}
[email protected]d5bcd06f2013-04-21 08:07:24467#endif
[email protected]970c63e2013-03-07 00:25:30468
[email protected]eabbfb12013-04-05 23:28:35469void SetApplicationLocaleOnIOThread(const std::string& locale) {
470 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
471 g_io_thread_application_locale.Get() = locale;
472}
473
[email protected]9dbfff12011-07-01 19:37:07474} // namespace
[email protected]c5dbef02011-05-13 05:06:09475
[email protected]d977f9c2011-03-14 16:10:26476namespace chrome {
477
[email protected]e461da2f2012-02-16 19:06:40478ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40479#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40480 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
481 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40482#endif
[email protected]1deace22013-05-22 06:14:46483
484 permissions_policy_delegate_.reset(
485 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40486}
487
488ChromeContentBrowserClient::~ChromeContentBrowserClient() {
489}
490
[email protected]bca18382012-06-25 19:15:23491// static
[email protected]c753f142013-02-10 13:14:04492void ChromeContentBrowserClient::RegisterUserPrefs(
[email protected]443e9312013-05-06 06:17:34493 user_prefs::PrefRegistrySyncable* registry) {
494 registry->RegisterBooleanPref(
495 prefs::kDisable3DAPIs,
496 false,
497 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
498 registry->RegisterBooleanPref(
499 prefs::kEnableHyperlinkAuditing,
500 true,
501 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
502 registry->RegisterBooleanPref(
503 prefs::kEnableMemoryInfo,
504 false,
505 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23506}
507
[email protected]eabbfb12013-04-05 23:28:35508// static
509void ChromeContentBrowserClient::SetApplicationLocale(
510 const std::string& locale) {
511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
512
513 // This object is guaranteed to outlive all threads so we don't have to
514 // worry about the lack of refcounting and can just post as Unretained.
515 //
516 // The common case is that this function is called early in Chrome startup
517 // before any threads are created (it will also be called later if the user
518 // changes the pref). In this case, there will be no threads created and
519 // posting will fail. When there are no threads, we can just set the string
520 // without worrying about threadsafety.
521 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
522 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
523 g_io_thread_application_locale.Get() = locale;
524 }
525}
526
[email protected]50462bf02011-11-21 19:13:31527content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
528 const content::MainFunctionParams& parameters) {
529 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30530 // Construct the Main browser parts based on the OS type.
531#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31532 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04533#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31534 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30535#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22536 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26537#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31538 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14539#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09540 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30541#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31542 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04543#else
[email protected]b48c9182011-10-26 18:03:30544 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31545 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30546#endif
547
[email protected]7e75e4a2013-05-17 17:20:03548 chrome::AddProfilesExtraParts(main_parts);
549
[email protected]c7480942011-11-08 19:18:27550 // Construct additional browser parts. Stages are called in the order in
551 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22552#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41553 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04554#endif
[email protected]c7480942011-11-08 19:18:27555
556#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41557 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27558#endif
559
[email protected]dc04be7c2012-03-15 23:57:49560#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41561 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49562#endif
563
[email protected]e050ef142012-03-21 01:04:24564#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41565 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24566#endif
567
[email protected]95132f52013-04-12 02:19:04568 chrome::AddMetricsExtraParts(main_parts);
569
[email protected]50462bf02011-11-21 19:13:31570 return main_parts;
[email protected]f967b722011-09-07 00:58:04571}
572
[email protected]e94bbcb2012-09-07 05:33:57573std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19574 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57575 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53576 std::string partition_id;
577
578 // The partition ID for webview guest processes is the string value of its
579 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
580 if (site.SchemeIs(chrome::kGuestScheme))
581 partition_id = site.spec();
582
[email protected]056efdc2013-04-06 00:14:53583 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53584 return partition_id;
585}
586
587bool ChromeContentBrowserClient::IsValidStoragePartitionId(
588 content::BrowserContext* browser_context,
589 const std::string& partition_id) {
590 // The default ID is empty and is always valid.
591 if (partition_id.empty())
592 return true;
593
594 return GURL(partition_id).is_valid();
595}
596
597void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
598 content::BrowserContext* browser_context,
599 const GURL& site,
[email protected]14acc642012-11-17 12:20:10600 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53601 std::string* partition_domain,
602 std::string* partition_name,
603 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10604 // Default to the browser-wide storage partition and override based on |site|
605 // below.
606 partition_domain->clear();
607 partition_name->clear();
608 *in_memory = false;
609
[email protected]1bc28312012-11-08 08:31:53610 // For the webview tag, we create special guest processes, which host the
611 // tag content separately from the main application that embeds the tag.
612 // A webview tag can specify both the partition name and whether the storage
613 // for that partition should be persisted. Each tag gets a SiteInstance with
614 // a specially formatted URL, based on the application it is hosted by and
615 // the partition requested by it. The format for that URL is:
616 // chrome-guest://partition_domain/persist?partition_name
617 if (site.SchemeIs(chrome::kGuestScheme)) {
618 // Since guest URLs are only used for packaged apps, there must be an app
619 // id in the URL.
620 CHECK(site.has_host());
621 *partition_domain = site.host();
622 // Since persistence is optional, the path must either be empty or the
623 // literal string.
624 *in_memory = (site.path() != "/persist");
625 // The partition name is user supplied value, which we have encoded when the
626 // URL was created, so it needs to be decoded.
627 *partition_name = net::UnescapeURLComponent(site.query(),
628 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10629 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
630 // If |can_be_default| is false, the caller is stating that the |site|
631 // should be parsed as if it had isolated storage. In particular it is
632 // important to NOT check ExtensionService for the is_storage_isolated()
633 // attribute because this code path is run during Extension uninstall
634 // to do cleanup after the Extension has already been unloaded from the
635 // ExtensionService.
636 bool is_isolated = !can_be_default;
637 if (can_be_default) {
638 const Extension* extension = NULL;
639 Profile* profile = Profile::FromBrowserContext(browser_context);
640 ExtensionService* extension_service =
641 extensions::ExtensionSystem::Get(profile)->extension_service();
642 if (extension_service) {
643 extension = extension_service->extensions()->
644 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43645 if (extension &&
646 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10647 is_isolated = true;
648 }
649 }
650 }
[email protected]1bc28312012-11-08 08:31:53651
[email protected]14acc642012-11-17 12:20:10652 if (is_isolated) {
653 CHECK(site.has_host());
654 // For extensions with isolated storage, the the host of the |site| is
655 // the |partition_domain|. The |in_memory| and |partition_name| are only
656 // used in guest schemes so they are cleared here.
657 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53658 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10659 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53660 }
[email protected]d1198fd2012-08-13 22:50:19661 }
662
[email protected]14acc642012-11-17 12:20:10663 // Assert that if |can_be_default| is false, the code above must have found a
664 // non-default partition. If this fails, the caller has a serious logic
665 // error about which StoragePartition they expect to be in and it is not
666 // safe to continue.
667 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44668}
669
[email protected]38b098f2012-03-14 21:11:57670content::WebContentsViewDelegate*
671 ChromeContentBrowserClient::GetWebContentsViewDelegate(
672 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27673 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32674}
675
[email protected]24665682013-02-25 20:59:38676// Check if the extension activity log is enabled for the profile.
677static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33678 // crbug.com/247908 - This should be IsLogEnabled except for an issue
679 // in chrome_frame_net_tests
680 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38681}
682
[email protected]44295a12013-06-05 08:45:46683void ChromeContentBrowserClient::GuestWebContentsAttached(
684 WebContents* guest_web_contents,
685 WebContents* embedder_web_contents,
686 int browser_plugin_instance_id) {
[email protected]44703cc72013-01-24 04:56:06687 Profile* profile = Profile::FromBrowserContext(
688 embedder_web_contents->GetBrowserContext());
689 ExtensionService* service =
690 extensions::ExtensionSystem::Get(profile)->extension_service();
691 if (!service)
692 return;
693 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
694 const Extension* extension = service->extensions()->
695 GetExtensionOrAppByURL(ExtensionURLInfo(url));
696 if (!extension)
697 return;
698 std::vector<ExtensionMsg_Loaded_Params> extensions;
699 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
700 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
[email protected]44295a12013-06-05 08:45:46701 new WebViewGuest(guest_web_contents,
702 embedder_web_contents,
703 extension->id(),
704 browser_plugin_instance_id);
[email protected]44703cc72013-01-24 04:56:06705}
706
[email protected]f3b1a082011-11-18 00:34:30707void ChromeContentBrowserClient::RenderProcessHostCreated(
708 content::RenderProcessHost* host) {
709 int id = host->GetID();
710 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41711 net::URLRequestContextGetter* context =
712 profile->GetRequestContextForRenderProcess(id);
713
[email protected]f3b1a082011-11-18 00:34:30714 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41715 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55716#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30717 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55718#endif
[email protected]658677f2012-06-09 06:04:02719#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08720 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03721#endif
[email protected]f3b1a082011-11-18 00:34:30722 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02723 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30724 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56725#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21726 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56727#endif
[email protected]43535512013-02-20 20:41:41728 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
729 id, profile, context));
[email protected]2736c032012-05-11 18:06:07730 host->GetChannel()->AddFilter(
731 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27732 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33733 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31734#if defined(ENABLE_WEBRTC)
735 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
736#endif
[email protected]3e69bc82011-05-26 23:22:38737
[email protected]2ccf45c2011-08-19 23:35:50738 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
739 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07740
[email protected]24665682013-02-25 20:59:38741 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
742 IsExtensionActivityLogEnabledForProfile(profile)));
743
[email protected]39a5b532011-10-22 01:47:07744 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56745
746 RendererContentSettingRules rules;
747 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
748 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14749}
750
[email protected]95c95552013-05-03 04:21:22751GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
752 content::BrowserContext* browser_context,
753 const GURL& url,
754 bool is_renderer_initiated,
755 content::SiteInstance* current_instance) {
756 Profile* profile = Profile::FromBrowserContext(browser_context);
757 if (!profile)
758 return url;
759
760 // Only return the privileged instant URL if we are entering from a browser-
761 // initiated navigation or if we are already in the instant process.
762 bool is_instant_process = false;
763 int process_id = current_instance->GetProcess()->GetID();
764 InstantService* instant_service =
765 InstantServiceFactory::GetForProfile(profile);
766 if (instant_service)
767 is_instant_process = instant_service->IsInstantProcess(process_id);
768
769 DCHECK_EQ(is_instant_process,
770 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
771 if (!is_renderer_initiated || is_instant_process) {
772 // If the input |url| should be assigned to the Instant renderer, make its
773 // privileged URL distinct from other URLs on the search provider's domain.
774 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
775 return chrome::GetPrivilegedURLForInstant(url, profile);
776 }
777
778 return url;
779}
780
[email protected]3d7474ff2011-07-27 17:47:37781GURL ChromeContentBrowserClient::GetEffectiveURL(
782 content::BrowserContext* browser_context, const GURL& url) {
783 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52784 if (!profile)
785 return url;
786
[email protected]d5bcd06f2013-04-21 08:07:24787#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30788 // If the input |url| should be assigned to the Signin renderer, make its
789 // effective URL distinct from other URLs on the signin service's domain.
790 // Note that the signin renderer will be allowed to sign the user in to
791 // Chrome.
792 if (SigninManager::IsWebBasedSigninFlowURL(url))
793 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24794#endif
[email protected]970c63e2013-03-07 00:25:30795
[email protected]c5dec6292013-01-25 04:54:52796 // If the input |url| is part of an installed app, the effective URL is an
797 // extension URL with the ID of that extension as the host. This has the
798 // effect of grouping apps together in a common SiteInstance.
799 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13800 extensions::ExtensionSystem::Get(profile)->extension_service();
801 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08802 return url;
803
[email protected]06bdd2b2012-11-30 18:47:13804 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44805 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08806 if (!extension)
807 return url;
808
[email protected]15877ca2011-11-18 22:40:52809 // Bookmark apps do not use the hosted app process model, and should be
810 // treated as normal URLs.
811 if (extension->from_bookmark())
812 return url;
813
[email protected]36fb2c7c2011-04-04 15:49:08814 // If the URL is part of an extension's web extent, convert it to an
815 // extension URL.
816 return extension->GetResourceURL(url.path());
817}
818
[email protected]056ad2a2011-07-12 02:13:55819bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37820 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52821 // Non-extension, non-Instant URLs should generally use
822 // process-per-site-instance. Because we expect to use the effective URL,
823 // URLs for hosted apps (apart from bookmark apps) should have an extension
824 // scheme by now.
825
826 Profile* profile = Profile::FromBrowserContext(browser_context);
827 if (!profile)
828 return false;
829
[email protected]165fe422013-03-27 06:34:03830 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52831 return true;
832
[email protected]d5bcd06f2013-04-21 08:07:24833#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30834 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
835 return true;
[email protected]d5bcd06f2013-04-21 08:07:24836#endif
[email protected]970c63e2013-03-07 00:25:30837
[email protected]885c0e92012-11-13 20:27:42838 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55839 return false;
840
[email protected]c5dec6292013-01-25 04:54:52841 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13842 extensions::ExtensionSystem::Get(profile)->extension_service();
843 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55844 return false;
845
[email protected]06bdd2b2012-11-30 18:47:13846 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44847 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55848 if (!extension)
849 return false;
850
851 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53852 // permission, or that does not allow JavaScript access to the background
853 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55854 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40855 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06856 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29857 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53858 return false;
859 }
860 }
[email protected]056ad2a2011-07-12 02:13:55861
[email protected]7b54ca02012-03-02 18:06:53862 // Hosted apps that have script access to their background page must use
863 // process per site, since all instances can make synchronous calls to the
864 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55865 return true;
866}
867
[email protected]672c8c12013-03-07 12:30:06868// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41869void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
870 std::vector<std::string>* additional_schemes) {
871 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06872}
873
[email protected]6bd30072013-02-08 18:17:11874net::URLRequestContextGetter*
875ChromeContentBrowserClient::CreateRequestContext(
876 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06877 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11878 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06879 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11880}
881
882net::URLRequestContextGetter*
883ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
884 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40885 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11886 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06887 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11888 Profile* profile = Profile::FromBrowserContext(browser_context);
889 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06890 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11891}
892
[email protected]46fb9442011-12-09 17:57:47893bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
894 return ProfileIOData::IsHandledURL(url);
895}
896
[email protected]c4365fa42013-05-14 01:08:24897bool ChromeContentBrowserClient::CanCommitURL(
898 content::RenderProcessHost* process_host,
899 const GURL& url) {
900 // We need to let most extension URLs commit in any process, since this can
901 // be allowed due to web_accessible_resources. Most hosted app URLs may also
902 // load in any process (e.g., in an iframe). However, the Chrome Web Store
903 // cannot be loaded in iframes and should never be requested outside its
904 // process.
905 Profile* profile =
906 Profile::FromBrowserContext(process_host->GetBrowserContext());
907 ExtensionService* service =
908 extensions::ExtensionSystem::Get(profile)->extension_service();
909 if (!service)
910 return true;
911 const Extension* new_extension =
912 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
913 if (new_extension &&
914 new_extension->is_hosted_app() &&
915 new_extension->id() == extension_misc::kWebStoreAppId &&
916 !service->process_map()->Contains(new_extension->id(),
917 process_host->GetID())) {
918 return false;
919 }
920
921 return true;
922}
923
[email protected]2a5221b2011-09-27 23:07:31924bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30925 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31926 const GURL& site_url) {
927 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30928 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52929 // This may be NULL during tests. In that case, just assume any site can
930 // share any host.
931 if (!profile)
932 return true;
933
[email protected]d43f99fe2013-04-03 00:20:14934 // Instant URLs should only be in the instant process and instant process
935 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52936 InstantService* instant_service =
937 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14938 if (instant_service) {
939 bool is_instant_process = instant_service->IsInstantProcess(
940 process_host->GetID());
941 bool should_be_in_instant_process =
942 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
943 if (is_instant_process || should_be_in_instant_process)
944 return is_instant_process && should_be_in_instant_process;
945 }
[email protected]c5dec6292013-01-25 04:54:52946
[email protected]d5bcd06f2013-04-21 08:07:24947#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30948 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
949 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
950 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:24951#endif
[email protected]970c63e2013-03-07 00:25:30952
[email protected]06bdd2b2012-11-30 18:47:13953 ExtensionService* service =
954 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46955 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31956
[email protected]ffa97602011-11-17 17:55:52957 // Don't allow the Task Manager to share a process with anything else.
958 // Otherwise it can affect the renderers it is observing.
959 // Note: we could create another RenderProcessHostPrivilege bucket for
960 // this to allow multiple chrome://tasks instances to share, but that's
961 // a very unlikely case without serious consequences.
962 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
963 return false;
964
[email protected]8d3132f62011-10-12 07:13:42965 // These may be NULL during tests. In that case, just assume any site can
966 // share any host.
[email protected]6f371442011-11-09 06:45:46967 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31968 return true;
969
[email protected]eec0b33c2011-12-05 22:09:45970 // Otherwise, just make sure the process privilege matches the privilege
971 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57972 RenderProcessHostPrivilege privilege_required =
973 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45974 return GetProcessPrivilege(process_host, process_map, service) ==
975 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31976}
977
[email protected]76411f412012-02-22 18:56:06978// This function is trying to limit the amount of processes used by extensions
979// with background pages. It uses a globally set percentage of processes to
980// run such extensions and if the limit is exceeded, it returns true, to
981// indicate to the content module to group extensions together.
982bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
983 content::BrowserContext* browser_context, const GURL& url) {
984 // It has to be a valid URL for us to check for an extension.
985 if (!url.is_valid())
986 return false;
987
988 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19989 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13990 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06991 if (!service)
992 return false;
993
994 // We have to have a valid extension with background page to proceed.
995 const Extension* extension =
996 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
997 if (!extension)
998 return false;
[email protected]9367eabc2013-03-01 01:29:29999 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061000 return false;
1001
1002 std::set<int> process_ids;
1003 size_t max_process_count =
1004 content::RenderProcessHost::GetMaxRendererProcessCount();
1005
1006 // Go through all profiles to ensure we have total count of extension
1007 // processes containing background pages, otherwise one profile can
1008 // starve the other.
1009 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1010 GetLoadedProfiles();
1011 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031012 ExtensionProcessManager* epm =
1013 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321014 for (ExtensionProcessManager::const_iterator iter =
1015 epm->background_hosts().begin();
1016 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131017 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321018 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061019 }
1020 }
1021
1022 if (process_ids.size() >
1023 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1024 return true;
1025 }
1026
1027 return false;
1028}
1029
[email protected]6f371442011-11-09 06:45:461030void ChromeContentBrowserClient::SiteInstanceGotProcess(
1031 SiteInstance* site_instance) {
1032 CHECK(site_instance->HasProcess());
1033
1034 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021035 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521036 if (!profile)
1037 return;
1038
1039 // Remember the ID of the Instant process to signal the renderer process
1040 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031041 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321042 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521043 InstantService* instant_service =
1044 InstantServiceFactory::GetForProfile(profile);
1045 if (instant_service)
1046 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1047 }
1048
[email protected]d5bcd06f2013-04-21 08:07:241049#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301050 // We only expect there to be one signin process as we use process-per-site
1051 // for signin URLs. The signin process will be cleared from SigninManager
1052 // when the renderer is destroyed.
1053 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1054 SigninManager* signin_manager =
1055 SigninManagerFactory::GetForProfile(profile);
1056 if (signin_manager)
1057 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461058 BrowserThread::PostTask(
1059 BrowserThread::IO, FROM_HERE,
1060 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1061 extensions::ExtensionSystem::Get(profile)->info_map(),
1062 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301063 }
[email protected]d5bcd06f2013-04-21 08:07:241064#endif
[email protected]970c63e2013-03-07 00:25:301065
[email protected]06bdd2b2012-11-30 18:47:131066 ExtensionService* service =
1067 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461068 if (!service)
1069 return;
1070
1071 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441072 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591073 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461074 if (!extension)
1075 return;
1076
[email protected]6bc04fd82011-12-04 02:29:351077 service->process_map()->Insert(extension->id(),
1078 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331079 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461080 BrowserThread::PostTask(
1081 BrowserThread::IO, FROM_HERE,
1082 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591083 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461084 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351085 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331086 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461087}
1088
1089void ChromeContentBrowserClient::SiteInstanceDeleting(
1090 SiteInstance* site_instance) {
1091 if (!site_instance->HasProcess())
1092 return;
1093
1094 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021095 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131096 ExtensionService* service =
1097 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461098 if (!service)
1099 return;
1100
1101 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441102 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591103 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461104 if (!extension)
1105 return;
1106
[email protected]6bc04fd82011-12-04 02:29:351107 service->process_map()->Remove(extension->id(),
1108 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331109 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461110 BrowserThread::PostTask(
1111 BrowserThread::IO, FROM_HERE,
1112 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591113 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461114 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351115 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331116 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461117}
1118
[email protected]f05763972012-06-06 18:17:261119bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141120 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081121 const GURL& current_url,
1122 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261123 if (current_url.is_empty()) {
1124 // Always choose a new process when navigating to extension URLs. The
1125 // process grouping logic will combine all of a given extension's pages
1126 // into the same process.
[email protected]885c0e92012-11-13 20:27:421127 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261128 return true;
[email protected]e3daf3c2011-10-05 21:17:081129
[email protected]f05763972012-06-06 18:17:261130 return false;
1131 }
1132
1133 // Also, we must switch if one is an extension and the other is not the exact
1134 // same extension.
[email protected]885c0e92012-11-13 20:27:421135 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1136 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261137 if (current_url.GetOrigin() != new_url.GetOrigin())
1138 return true;
1139 }
1140
[email protected]e9841fbd2013-02-22 23:12:141141 // The checks below only matter if we can retrieve which extensions are
1142 // installed.
1143 Profile* profile =
1144 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1145 ExtensionService* service =
1146 extensions::ExtensionSystem::Get(profile)->extension_service();
1147 if (!service)
1148 return false;
1149
1150 // We must swap if the URL is for an extension and we are not using an
1151 // extension process.
1152 const Extension* new_extension =
1153 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1154 // Ignore all hosted apps except the Chrome Web Store, since they do not
1155 // require their own BrowsingInstance (e.g., postMessage is ok).
1156 if (new_extension &&
1157 new_extension->is_hosted_app() &&
1158 new_extension->id() != extension_misc::kWebStoreAppId)
1159 new_extension = NULL;
1160 if (new_extension &&
1161 site_instance->HasProcess() &&
1162 !service->process_map()->Contains(new_extension->id(),
1163 site_instance->GetProcess()->GetID()))
1164 return true;
1165
[email protected]f05763972012-06-06 18:17:261166 return false;
[email protected]e3daf3c2011-10-05 21:17:081167}
1168
[email protected]395045c2012-05-22 15:04:381169bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1170 content::ResourceContext* resource_context, const GURL& current_url,
1171 const GURL& new_url) {
1172 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1173 return extensions::CrossesExtensionProcessBoundary(
1174 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171175 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381176}
1177
[email protected]763ec4ca2011-04-29 15:48:121178std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1179 const std::string& alias_name) {
1180 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1181}
1182
[email protected]b80f68432011-05-02 17:22:301183void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1184 CommandLine* command_line, int child_process_id) {
1185#if defined(USE_LINUX_BREAKPAD)
1186 if (IsCrashReporterEnabled()) {
1187 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1188 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1189 }
1190#elif defined(OS_MACOSX)
1191 if (IsCrashReporterEnabled()) {
1192 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1193 child_process_logging::GetClientId());
1194 }
1195#endif // OS_MACOSX
1196
[email protected]f1933792011-06-14 00:49:341197 if (logging::DialogsAreSuppressed())
1198 command_line->AppendSwitch(switches::kNoErrorDialogs);
1199
[email protected]b80f68432011-05-02 17:22:301200 std::string process_type =
1201 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171202 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321203
1204 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1205 command_line->AppendSwitch(switches::kChromeFrame);
1206
[email protected]718eab62011-10-05 21:16:521207 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451208 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301209 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1210 if (!user_data_dir.empty())
1211 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1212#if defined(OS_CHROMEOS)
1213 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441214 browser_command_line.GetSwitchValueASCII(
1215 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301216 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441217 command_line->AppendSwitchASCII(
1218 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301219#endif
1220
[email protected]f3b1a082011-11-18 00:34:301221 content::RenderProcessHost* process =
1222 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371223 if (process) {
1224 Profile* profile = Profile::FromBrowserContext(
1225 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131226 ExtensionService* extension_service =
1227 extensions::ExtensionSystem::Get(profile)->extension_service();
1228 if (extension_service) {
1229 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001230 if (process_map && process_map->Contains(process->GetID()))
1231 command_line->AppendSwitch(switches::kExtensionProcess);
1232 }
[email protected]b80f68432011-05-02 17:22:301233
[email protected]a8d851f82011-12-21 00:32:371234 PrefService* prefs = profile->GetPrefs();
1235 // Currently this pref is only registered if applied via a policy.
1236 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1237 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1238 // Turn this policy into a command line switch.
1239 command_line->AppendSwitch(switches::kDisable3DAPIs);
1240 }
[email protected]718eab62011-10-05 21:16:521241
[email protected]a8d851f82011-12-21 00:32:371242 // Disable client-side phishing detection in the renderer if it is
1243 // disabled in the Profile preferences or the browser process.
1244 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1245 !g_browser_process->safe_browsing_detection_service()) {
1246 command_line->AppendSwitch(
1247 switches::kDisableClientSidePhishingDetection);
1248 }
[email protected]0045b0f42012-07-26 11:52:081249
1250 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211251 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521252
1253 InstantService* instant_service =
1254 InstantServiceFactory::GetForProfile(profile);
1255 if (instant_service &&
1256 instant_service->IsInstantProcess(process->GetID()))
1257 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301258
[email protected]d5bcd06f2013-04-21 08:07:241259#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301260 SigninManager* signin_manager =
1261 SigninManagerFactory::GetForProfile(profile);
1262 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1263 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241264#endif
[email protected]47c7ec82012-01-18 03:29:211265 }
[email protected]4287a3d2011-06-13 23:56:511266
[email protected]87552982012-11-02 17:21:401267 if (content::IsThreadedCompositingEnabled())
1268 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1269
[email protected]16dc42452013-04-09 04:37:191270 if (message_center::IsRichNotificationEnabled())
1271 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191272
[email protected]47c7ec82012-01-18 03:29:211273 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511274 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171275 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481276 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171277 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511278 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481279 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511280 switches::kAllowScriptingGallery,
1281 switches::kAppsCheckoutURL,
1282 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311283 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511284 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501285 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531286 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111287 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531288 switches::kEnableAdview,
1289 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211290 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511291 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511292 switches::kEnableIPCFuzzing,
1293 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451294 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481295 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051296 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511297 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291298 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511299 switches::kMemoryProfiling,
1300 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371301 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371302 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511303 switches::kPpapiFlashArgs,
1304 switches::kPpapiFlashInProcess,
1305 switches::kPpapiFlashPath,
1306 switches::kPpapiFlashVersion,
1307 switches::kProfilingAtStart,
1308 switches::kProfilingFile,
1309 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371310 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511311 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291312 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381313 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511314 };
1315
1316 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1317 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171318 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381319 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351320 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381321 switches::kEnableExperimentalExtensionApis,
1322 switches::kWhitelistedExtensionID,
1323 };
1324
1325 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1326 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511327 } else if (process_type == switches::kPluginProcess) {
1328 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441329#if defined(OS_CHROMEOS)
1330 chromeos::switches::kLoginProfile,
1331#endif
[email protected]4287a3d2011-06-13 23:56:511332 switches::kMemoryProfiling,
1333 switches::kSilentDumpOnDCHECK,
1334 switches::kUserDataDir,
1335 };
1336
1337 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1338 arraysize(kSwitchNames));
1339 } else if (process_type == switches::kZygoteProcess) {
1340 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511341 switches::kUserDataDir, // Make logs go to the right file.
1342 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501343 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511344 switches::kPpapiFlashInProcess,
1345 switches::kPpapiFlashPath,
1346 switches::kPpapiFlashVersion,
1347 };
1348
1349 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1350 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111351 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001352 base::FilePath user_data_dir =
1353 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1354 if (!user_data_dir.empty())
1355 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111356 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1357 // because GPU is expected to be unreliable.
1358 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1359 !command_line->HasSwitch(switches::kDisableBreakpad))
1360 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301361 }
[email protected]6f08af82011-09-15 01:19:031362
1363 // The command line switch kEnableBenchmarking needs to be specified along
1364 // with the kEnableStatsTable switch to ensure that the stats table global
1365 // is initialized correctly.
1366 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1367 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301368}
1369
1370std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431371 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351372 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301373 return g_browser_process->GetApplicationLocale();
1374}
1375
[email protected]597a867b2011-11-18 18:31:201376std::string ChromeContentBrowserClient::GetAcceptLangs(
1377 content::BrowserContext* context) {
1378 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371379 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081380}
1381
[email protected]9ec0f452012-05-31 15:58:531382gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221383 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531384 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081385}
1386
[email protected]a2176792011-05-08 19:30:491387bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091388 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191389 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201390 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201392 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051393 return io_data->GetCookieSettings()->
1394 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491395}
1396
[email protected]ed24fad2011-05-10 22:44:011397bool ChromeContentBrowserClient::AllowGetCookie(
1398 const GURL& url,
1399 const GURL& first_party,
1400 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201401 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011402 int render_process_id,
1403 int render_view_id) {
1404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201405 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051406 bool allow = io_data->GetCookieSettings()->
1407 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011408
[email protected]8093a542011-05-13 07:29:321409 BrowserThread::PostTask(
1410 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031411 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431412 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011413 return allow;
1414}
1415
1416bool ChromeContentBrowserClient::AllowSetCookie(
1417 const GURL& url,
1418 const GURL& first_party,
1419 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201420 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011421 int render_process_id,
1422 int render_view_id,
1423 net::CookieOptions* options) {
1424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201425 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051426 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1427 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1428
[email protected]8093a542011-05-13 07:29:321429 BrowserThread::PostTask(
1430 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031431 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431432 render_view_id, url, first_party, cookie_line, *options,
1433 !allow));
[email protected]ed24fad2011-05-10 22:44:011434 return allow;
1435}
1436
[email protected]d5a19162011-06-30 18:51:541437bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201438 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201440 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431441 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1442 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261443
[email protected]bf510ed2012-06-05 08:31:431444 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1445 // Could we even support per-origin settings?
1446 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541447}
1448
[email protected]5c5a88e2011-11-12 00:45:351449bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351450 const GURL& url,
1451 const string16& name,
1452 const string16& display_name,
1453 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201454 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481455 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351456 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201457 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351458 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1459 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1460
[email protected]62151052012-02-01 18:40:481461 // Record access to database for potential display in UI.
1462 std::vector<std::pair<int, int> >::const_iterator i;
1463 for (i = render_views.begin(); i != render_views.end(); ++i) {
1464 BrowserThread::PostTask(
1465 BrowserThread::UI, FROM_HERE,
1466 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1467 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351468 }
1469
1470 return allow;
1471}
1472
1473bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351474 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201475 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481476 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201478 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351479 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1480 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1481
[email protected]62151052012-02-01 18:40:481482 // Record access to file system for potential display in UI.
1483 std::vector<std::pair<int, int> >::const_iterator i;
1484 for (i = render_views.begin(); i != render_views.end(); ++i) {
1485 BrowserThread::PostTask(
1486 BrowserThread::UI, FROM_HERE,
1487 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1488 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351489 }
1490
1491 return allow;
1492}
1493
[email protected]7c5ff9a2012-03-02 07:42:491494bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1495 const GURL& url,
1496 const string16& name,
1497 content::ResourceContext* context,
1498 const std::vector<std::pair<int, int> >& render_views) {
1499 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1500 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1501 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1502 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1503
1504 // Record access to IndexedDB for potential display in UI.
1505 std::vector<std::pair<int, int> >::const_iterator i;
1506 for (i = render_views.begin(); i != render_views.end(); ++i) {
1507 BrowserThread::PostTask(
1508 BrowserThread::UI, FROM_HERE,
1509 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1510 i->first, i->second, url, name, !allow));
1511 }
1512
1513 return allow;
1514}
1515
[email protected]6133f922011-07-01 21:34:341516net::URLRequestContext*
1517ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201518 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421520 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201521 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341522 return io_data->extensions_request_context();
1523 }
1524
1525 return NULL;
1526}
1527
[email protected]317f96c92011-05-31 06:53:411528QuotaPermissionContext*
1529ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1530 return new ChromeQuotaPermissionContext();
1531}
1532
[email protected]848dd042011-06-04 18:24:031533void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171534 int render_process_id,
1535 int render_view_id,
1536 int cert_error,
1537 const net::SSLInfo& ssl_info,
1538 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021539 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031540 bool overridable,
[email protected]d9be47702012-05-16 03:41:221541 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171542 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001543 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021544 if (resource_type != ResourceType::MAIN_FRAME) {
1545 // A sub-resource has a certificate error. The user doesn't really
1546 // have a context for making the right decision, so block the
1547 // request hard, without an info bar to allow showing the insecure
1548 // content.
[email protected]8c965c22013-05-23 19:28:001549 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021550 return;
1551 }
1552
[email protected]f9034cf2011-07-21 12:43:411553 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131554 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171555 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411556 if (!tab) {
1557 NOTREACHED();
1558 return;
1559 }
1560 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501561 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301562 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011563 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1564 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411565 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171566 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411567 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001568 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411569 return;
1570 }
1571 }
1572
[email protected]1e87df32012-09-12 04:53:191573#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231574 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1575 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1576 if (captive_portal_tab_helper)
1577 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191578#endif
1579
[email protected]f9034cf2011-07-21 12:43:411580 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221581 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1582 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031583}
1584
[email protected]c99c442e2011-08-24 11:37:301585void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451586 int render_process_id,
1587 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401588 const net::HttpNetworkSession* network_session,
1589 net::SSLCertRequestInfo* cert_request_info,
1590 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131591 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451592 render_process_id, render_view_id);
1593 if (!tab) {
1594 NOTREACHED();
1595 return;
1596 }
1597
[email protected]6786bf402011-12-03 15:19:451598 GURL requesting_url("https://" + cert_request_info->host_and_port);
1599 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1600 << cert_request_info->host_and_port;
1601
[email protected]627e0512011-12-21 22:55:301602 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451603 scoped_ptr<Value> filter(
1604 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1605 requesting_url,
1606 requesting_url,
1607 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1608 std::string(), NULL));
1609
1610 if (filter.get()) {
1611 // Try to automatically select a client certificate.
1612 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1613 DictionaryValue* filter_dict =
1614 static_cast<DictionaryValue*>(filter.get());
1615
1616 const std::vector<scoped_refptr<net::X509Certificate> >&
1617 all_client_certs = cert_request_info->client_certs;
1618 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091619 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451620 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091621 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451622 return;
1623 }
1624 }
1625 } else {
1626 NOTREACHED();
1627 }
1628 }
1629
[email protected]11feec322012-09-18 03:58:521630 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1631 if (!ssl_tab_helper) {
1632 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451633 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141634 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401635 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451636 return;
1637 }
[email protected]11feec322012-09-18 03:58:521638 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401639 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451640}
1641
[email protected]3b455502012-12-11 18:22:581642void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451643 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581644 net::CertificateMimeType cert_type,
1645 const void* cert_data,
1646 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451647 int render_process_id,
1648 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581649 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1650 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451651}
1652
[email protected]dc73a7b2012-03-25 15:27:181653content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561654 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181655}
1656
[email protected]941623e2011-06-07 23:06:041657void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1658 const GURL& source_origin,
1659 int callback_context,
1660 int render_process_id,
1661 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111662#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1664 WebContents* contents =
1665 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1666 if (!contents) {
[email protected]941623e2011-06-07 23:06:041667 NOTREACHED();
1668 return;
1669 }
1670
[email protected]d0d9c3ee2012-06-19 03:07:021671 // Skip showing the infobar if the request comes from an extension, and that
1672 // extension has the 'notify' permission. (If the extension does not have the
1673 // permission, the user will still be prompted.)
1674 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011675 ExtensionInfoMap* extension_info_map =
1676 extensions::ExtensionSystem::Get(profile)->info_map();
1677 DesktopNotificationService* notification_service =
1678 DesktopNotificationServiceFactory::GetForProfile(profile);
1679 const Extension* extension = NULL;
1680 if (extension_info_map) {
1681 ExtensionSet extensions;
1682 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1683 source_origin, render_process_id,
1684 extensions::APIPermission::kNotification, &extensions);
1685 for (ExtensionSet::const_iterator iter = extensions.begin();
1686 iter != extensions.end(); ++iter) {
1687 if (notification_service->IsExtensionEnabled((*iter)->id())) {
1688 extension = *iter;
1689 break;
1690 }
1691 }
1692 }
[email protected]eb4832a2012-12-08 01:57:521693 RenderViewHost* rvh =
1694 RenderViewHost::FromID(render_process_id, render_view_id);
1695 if (IsExtensionWithPermissionOrSuggestInConsole(
1696 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021697 if (rvh)
1698 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1699 return;
1700 }
1701
[email protected]c7cd5942013-04-30 03:31:011702 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021703 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111704#else
1705 NOTIMPLEMENTED();
1706#endif
[email protected]941623e2011-06-07 23:06:041707}
1708
1709WebKit::WebNotificationPresenter::Permission
1710 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021711 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201712 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021713 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111714#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201716 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041717
[email protected]c7cd5942013-04-30 03:31:011718 DesktopNotificationService* notification_service =
1719 io_data->GetNotificationService();
1720 if (notification_service) {
1721 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1722 ExtensionSet extensions;
1723 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1724 source_origin, render_process_id,
1725 extensions::APIPermission::kNotification, &extensions);
1726 for (ExtensionSet::const_iterator iter = extensions.begin();
1727 iter != extensions.end(); ++iter) {
1728 if (notification_service->IsExtensionEnabled((*iter)->id()))
1729 return WebKit::WebNotificationPresenter::PermissionAllowed;
1730 }
1731
1732 return notification_service->HasPermission(source_origin);
1733 }
1734
1735 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111736#else
1737 return WebKit::WebNotificationPresenter::PermissionAllowed;
1738#endif
[email protected]941623e2011-06-07 23:06:041739}
1740
1741void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171742 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041743 int render_process_id,
1744 int render_view_id,
1745 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111746#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041747 RenderViewHost* rvh = RenderViewHost::FromID(
1748 render_process_id, render_view_id);
1749 if (!rvh) {
1750 NOTREACHED();
1751 return;
1752 }
1753
[email protected]9f76c1e2012-03-05 15:15:581754 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301755 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041756 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371757 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041758 service->ShowDesktopNotification(
1759 params, render_process_id, render_view_id,
1760 worker ? DesktopNotificationService::WorkerNotification :
1761 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111762#else
1763 NOTIMPLEMENTED();
1764#endif
[email protected]941623e2011-06-07 23:06:041765}
1766
1767void ChromeContentBrowserClient::CancelDesktopNotification(
1768 int render_process_id,
1769 int render_view_id,
1770 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111771#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041772 RenderViewHost* rvh = RenderViewHost::FromID(
1773 render_process_id, render_view_id);
1774 if (!rvh) {
1775 NOTREACHED();
1776 return;
1777 }
1778
[email protected]9f76c1e2012-03-05 15:15:581779 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301780 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041781 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371782 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041783 service->CancelDesktopNotification(
1784 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111785#else
1786 NOTIMPLEMENTED();
1787#endif
[email protected]941623e2011-06-07 23:06:041788}
1789
[email protected]9f3fba52011-06-08 20:37:191790bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351791 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021792 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191793 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201794 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011795 int render_process_id,
1796 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191797 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011798
1799 *no_javascript_access = false;
1800
[email protected]9f3fba52011-06-08 20:37:191801 // If the opener is trying to create a background window but doesn't have
1802 // the appropriate permission, fail the attempt.
1803 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201804 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531805 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1806
[email protected]03b6d552012-03-29 04:03:011807 if (!map->SecurityOriginHasAPIPermission(
1808 source_origin,
1809 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061810 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011811 return false;
1812 }
1813
[email protected]7b54ca02012-03-02 18:06:531814 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1815 // return a recently installed Extension even if this CanCreateWindow call
1816 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011817 // because the permission check above would have caused an early return
1818 // already. We must use the full URL to find hosted apps, though, and not
1819 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531820 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351821 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291822 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011823 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191824 }
[email protected]056efdc2013-04-06 00:14:531825
1826 // No new browser window (popup or tab) in app mode.
1827 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1828 chrome::IsRunningInForcedAppMode()) {
1829 return false;
1830 }
1831
[email protected]9f3fba52011-06-08 20:37:191832 return true;
1833}
1834
1835std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201836 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191837 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1838 // Check if it's an extension-created worker, in which case we want to use
1839 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201840 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191841 const Extension* extension =
1842 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1843 return extension ? extension->name() : std::string();
1844}
1845
[email protected]99907362012-01-11 05:41:401846void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1847 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171848}
1849
[email protected]7a06d282013-05-03 04:39:331850// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021851content::SpeechRecognitionManagerDelegate*
1852 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]3bd0aab2013-05-30 20:07:491853#if !defined(OS_ANDROID)
[email protected]c52b2892012-03-07 11:01:021854 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321855#else
[email protected]3bd0aab2013-05-30 20:07:491856 // TODO(janx): Implement speech::AndroidSpeechRecognitionManagerDelegate
1857 // (see crbug.com/222352).
[email protected]a03f2d32012-03-14 00:26:321858 return NULL;
1859#endif
[email protected]66cfec62012-02-24 17:57:511860}
1861
[email protected]ae6e9912011-07-27 01:18:281862net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1863 return g_browser_process->net_log();
1864}
1865
[email protected]32538d92011-08-25 00:09:231866AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1867 return new ChromeAccessTokenStore();
1868}
1869
[email protected]dbae6b02011-06-29 23:51:411870bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011871 return true;
[email protected]dbae6b02011-06-29 23:51:411872}
1873
[email protected]64d69de42012-02-06 00:19:541874void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321875 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061876 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581877 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061878 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061879
[email protected]f3986f82012-01-03 20:00:061880 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541881 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061882 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541883 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061884 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541885 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061886 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541887 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061888 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541889 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061890 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541891 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031892 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1893 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061894
[email protected]64d69de42012-02-06 00:19:541895 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401896 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541897 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401898 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541899 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401900 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541901 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401902 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061903
[email protected]ddf72142012-05-22 04:52:401904 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061905
[email protected]64d69de42012-02-06 00:19:541906 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401907 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541908 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061909 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541910 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061911 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1912 const DictionaryValue* inspector_settings =
1913 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1914 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181915 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1916 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061917 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181918 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541919 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181920 std::make_pair(iter.key(), value));
1921 }
[email protected]f3986f82012-01-03 20:00:061922 }
1923 }
[email protected]64d69de42012-02-06 00:19:541924 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061925
[email protected]ddf72142012-05-22 04:52:401926 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541927 web_prefs->javascript_enabled = false;
1928 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1929 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401930 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541931 web_prefs->plugins_enabled = false;
1932 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1933 web_prefs->java_enabled = false;
1934 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401935 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061936
[email protected]64d69de42012-02-06 00:19:541937 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1938 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061939
[email protected]64d69de42012-02-06 00:19:541940 web_prefs->memory_info_enabled =
1941 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1942 web_prefs->allow_displaying_insecure_content =
1943 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1944 web_prefs->allow_running_insecure_content =
1945 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321946#if defined(OS_ANDROID)
1947 web_prefs->font_scale_factor =
1948 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1949 web_prefs->force_enable_zoom =
1950 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451951#if defined(GOOGLE_TV)
1952 web_prefs->user_gesture_required_for_media_playback = false;
1953#endif
[email protected]d3b935f2012-10-19 23:14:321954#endif
[email protected]5c915252013-05-07 13:15:391955
[email protected]af4256d52013-06-04 20:39:071956#if defined(OS_ANDROID)
1957 web_prefs->password_echo_enabled =
1958 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
1959#else
[email protected]9d06d88d2012-02-23 22:37:081960 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:071961#endif
1962
[email protected]5c915252013-05-07 13:15:391963#if defined(OS_CHROMEOS)
1964 // Enable password echo during OOBE when keyboard driven flag is set.
1965 if (chromeos::UserManager::IsInitialized() &&
1966 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
1967 !chromeos::StartupUtils::IsOobeCompleted()) {
1968 bool keyboard_driven_oobe = false;
1969 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]e8f3f9982013-05-10 20:59:531970 chromeos::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:391971 if (keyboard_driven_oobe)
1972 web_prefs->password_echo_enabled = true;
1973 }
1974#endif
[email protected]f3986f82012-01-03 20:00:061975
[email protected]46f8e742013-05-03 18:37:141976#if defined(OS_ANDROID)
1977 web_prefs->user_style_sheet_enabled = false;
1978#else
[email protected]64d69de42012-02-06 00:19:541979 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151980 UserStyleSheetWatcher* user_style_sheet_watcher =
1981 UserStyleSheetWatcherFactory::GetForProfile(profile);
1982 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541983 web_prefs->user_style_sheet_enabled = true;
1984 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151985 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541986 } else {
1987 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061988 }
[email protected]46f8e742013-05-03 18:37:141989#endif
[email protected]f3986f82012-01-03 20:00:061990
[email protected]cfadadd2013-04-03 04:43:021991 web_prefs->asynchronous_spell_checking_enabled = true;
1992 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:571993
[email protected]64d69de42012-02-06 00:19:541994 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061995 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541996 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061997 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541998 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061999 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2000
2001 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542002 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062003 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542004 web_prefs->default_encoding);
2005 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402006 prefs->ClearPref(prefs::kDefaultCharset);
2007 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062008 }
[email protected]64d69de42012-02-06 00:19:542009 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062010
[email protected]88ecf66d2012-12-11 22:53:472011 if (content::IsForceCompositingModeEnabled())
2012 web_prefs->force_compositing_mode = true;
2013
[email protected]299d7f12012-05-23 05:31:152014 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232015 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132016 ExtensionService* service =
2017 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062018 if (service) {
[email protected]1bc28312012-11-08 08:31:532019 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2020 const Extension* extension = service->extensions()->GetByID(url.host());
2021 // Ensure that we are only granting extension preferences to URLs with
2022 // the correct scheme. Without this check, chrome-guest:// schemes used by
2023 // webview tags as well as hosts that happen to match the id of an
2024 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422025 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532026 extension_webkit_preferences::SetPreferences(
2027 extension, view_type, web_prefs);
2028 }
[email protected]f3986f82012-01-03 20:00:062029 }
2030
[email protected]cb2edf22013-04-01 20:25:232031 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542032 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232033 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062034 // Disable all kinds of acceleration for background pages.
2035 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542036 web_prefs->force_compositing_mode = false;
2037 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062038 }
[email protected]2e21fe292012-03-02 22:52:322039
2040#if defined(FILE_MANAGER_EXTENSION)
2041 // Override the default of suppressing HW compositing for WebUI pages for the
2042 // file manager, which is implemented using WebUI but wants HW acceleration
2043 // for video decode & render.
2044 if (url.spec() == chrome::kChromeUIFileManagerURL) {
2045 web_prefs->accelerated_compositing_enabled = true;
2046 web_prefs->accelerated_2d_canvas_enabled = true;
2047 }
2048#endif
[email protected]181a95ee2011-07-12 19:26:362049}
2050
2051void ChromeContentBrowserClient::UpdateInspectorSetting(
2052 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062053 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582054 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062055 DictionaryPrefUpdate update(
2056 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2057 prefs::kWebKitInspectorSettings);
2058 DictionaryValue* inspector_settings = update.Get();
2059 inspector_settings->SetWithoutPathExpansion(key,
2060 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362061}
2062
[email protected]b8148ac2011-07-13 22:03:252063void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2064 BrowserURLHandler* handler) {
2065 // Add the default URL handlers.
2066 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2067 BrowserURLHandler::null_handler());
2068 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2069 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2070
[email protected]b3adbd02011-11-30 22:23:272071 // about: handler. Must come before chrome: handler, since it will
2072 // rewrite about: urls to chrome: URLs and then expect chrome: to
2073 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252074 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2075 BrowserURLHandler::null_handler());
2076 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242077 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252078}
2079
2080void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372081 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582082 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472083 BrowsingDataRemover* remover =
2084 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552085 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2086 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252087 // BrowsingDataRemover takes care of deleting itself when done.
2088}
2089
2090void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372091 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582092 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472093 BrowsingDataRemover* remover =
2094 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232095 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552096 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252097 // BrowsingDataRemover takes care of deleting itself when done.
2098}
2099
[email protected]650b2d52013-02-10 03:41:452100base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322101 return download_util::GetDefaultDownloadDirectory();
2102}
2103
[email protected]c9b6eb62011-10-18 20:49:392104std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2105 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2106}
2107
[email protected]b7631cc2012-09-15 05:08:382108void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2109 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542110#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382111 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2112 scoped_ptr<ppapi::host::HostFactory>(
2113 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542114#endif
[email protected]b7631cc2012-09-15 05:08:382115}
2116
[email protected]0c7193742012-11-07 19:05:032117content::BrowserPpapiHost*
2118 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2119 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132120 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032121 while (!iter.Done()) {
2122 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2123 if (host->process() &&
2124 host->process()->GetData().id == plugin_process_id) {
2125 // Found the plugin.
2126 return host->browser_ppapi_host();
2127 }
2128 ++iter;
2129 }
2130 return NULL;
2131}
2132
[email protected]7b38b192013-03-23 18:39:312133bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2134 content::BrowserContext* browser_context, const GURL& site_url) {
2135 if (CommandLine::ForCurrentProcess()->HasSwitch(
2136 switches::kEnableBrowserPluginForAllViewTypes))
2137 return true;
2138
2139 Profile* profile = Profile::FromBrowserContext(browser_context);
2140 ExtensionService* service =
2141 extensions::ExtensionSystem::Get(profile)->extension_service();
2142 if (!service)
2143 return false;
2144
2145 const Extension* extension = service->extensions()->
2146 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2147 if (!extension)
2148 return false;
2149
[email protected]c2d2f102013-04-29 16:42:582150 return extension->HasAPIPermission(APIPermission::kWebView) ||
2151 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312152}
2153
[email protected]38cd8f7f2012-06-15 22:06:072154bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582155 content::BrowserContext* browser_context,
2156 const GURL& url,
2157 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402158#if defined(ENABLE_PLUGINS)
2159 return IsExtensionOrSharedModuleWhitelisted(
2160 Profile::FromBrowserContext(browser_context),
2161 url,
2162 allowed_socket_origins_,
2163 switches::kAllowNaClSocketAPI);
2164#else
[email protected]a658d452012-03-02 12:45:292165 return false;
[email protected]93f72062013-05-29 20:29:402166#endif
[email protected]e461da2f2012-02-16 19:06:402167}
2168
[email protected]650b2d52013-02-10 03:41:452169base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2170 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142171 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2172 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2173}
2174
[email protected]a28e3302013-02-03 03:50:432175ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2176 WebContents* web_contents) {
2177 return new ChromeSelectFilePolicy(web_contents);
2178}
2179
[email protected]7d9424702013-04-14 13:14:162180void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2181 std::vector<std::string>* additional_allowed_schemes) {
2182 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2183 additional_allowed_schemes);
2184 additional_allowed_schemes->push_back(kChromeUIScheme);
2185 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2186}
2187
[email protected]02250952013-04-24 23:52:532188void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2189 const base::FilePath& storage_partition_path,
2190 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2191#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032192 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]02250952013-04-24 23:52:532193 additional_providers->push_back(new MediaFileSystemMountPointProvider(
[email protected]30a306f42013-06-10 03:09:032194 storage_partition_path,
2195 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
2196 MediaFileSystemMountPointProvider::kMediaTaskRunnerName))));
[email protected]02250952013-04-24 23:52:532197#endif
2198}
2199
[email protected]e60c0232011-11-11 19:56:352200#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182201void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2202 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382203 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082204 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392205#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452206 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392207 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2208 DCHECK(!data_path.empty());
2209
2210 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452211 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392212 base::PlatformFile f =
2213 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2214 DCHECK(f != base::kInvalidPlatformFileValue);
2215 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2216 FileDescriptor(f, true)));
2217
[email protected]650b2d52013-02-10 03:41:452218 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392219 data_path.AppendASCII("chrome_100_percent.pak");
2220 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2221 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372222 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392223 FileDescriptor(f, true)));
2224
2225 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452226 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392227 GetLocaleFilePath(locale, false);
2228 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2229 DCHECK(f != base::kInvalidPlatformFileValue);
2230 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2231 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382232
[email protected]650b2d52013-02-10 03:41:452233 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372234 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2235 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2236 DCHECK(f != base::kInvalidPlatformFileValue);
2237 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2238 FileDescriptor(f, true)));
2239
[email protected]40da3e0c2012-10-24 22:03:382240#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432241 if (IsCrashReporterEnabled()) {
2242 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2243 if (f == base::kInvalidPlatformFileValue) {
2244 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2245 "be disabled for this process.";
2246 } else {
2247 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2248 FileDescriptor(f, true)));
2249 }
[email protected]40da3e0c2012-10-24 22:03:382250 }
2251#endif // defined(USE_LINUX_BREAKPAD)
2252
2253#else
2254 int crash_signal_fd = GetCrashSignalFD(command_line);
2255 if (crash_signal_fd >= 0) {
2256 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2257 FileDescriptor(crash_signal_fd,
2258 false)));
2259 }
[email protected]29699c22012-10-03 23:57:392260#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302261}
[email protected]e60c0232011-11-11 19:56:352262#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302263
[email protected]4a65826d2011-08-25 16:04:012264#if defined(OS_WIN)
2265const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2266 return chrome::kBrowserResourcesDll;
2267}
[email protected]34f48682013-03-20 00:30:182268
2269void ChromeContentBrowserClient::PreSpawnRenderer(
2270 sandbox::TargetPolicy* policy,
2271 bool* success) {
2272 // This code is duplicated in nacl_exe_win_64.cc.
2273 // Allow the server side of a pipe restricted to the "chrome.nacl."
2274 // namespace so that it cannot impersonate other system or other chrome
2275 // service pipes.
2276 sandbox::ResultCode result = policy->AddRule(
2277 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2278 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2279 L"\\\\.\\pipe\\chrome.nacl.*");
2280 if (result != sandbox::SBOX_ALL_OK) {
2281 *success = false;
2282 return;
2283 }
2284
2285 // Renderers need to send named pipe handles and shared memory
2286 // segment handles to NaCl loader processes.
2287 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2288 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2289 L"File");
2290 if (result != sandbox::SBOX_ALL_OK) {
2291 *success = false;
2292 return;
2293 }
2294}
[email protected]4a65826d2011-08-25 16:04:012295#endif
2296
[email protected]37a72af2011-06-13 05:42:012297#if defined(USE_NSS)
2298crypto::CryptoModuleBlockingPasswordDelegate*
2299 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2300 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292301 return chrome::NewCryptoModuleBlockingDialogDelegate(
2302 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012303}
2304#endif
2305
[email protected]d977f9c2011-03-14 16:10:262306} // namespace chrome