blob: 6aba76193caa61446ab79c79a7f55fc8c1d136c9 [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]01e59752013-06-18 00:17:3549#include "chrome/browser/nacl_host/nacl_host_message_filter.h"
[email protected]0c7193742012-11-07 19:05:0350#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2851#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0452#include "chrome/browser/notifications/desktop_notification_service.h"
53#include "chrome/browser/notifications/desktop_notification_service_factory.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]dda54822013-06-15 01:26:3999#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]157cc902012-11-02 06:31:58100#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:34101#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37102#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12103#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38104#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09105#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53106#include "chromeos/chromeos_constants.h"
[email protected]75fee372013-03-06 00:42:44107#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43108#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30109#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38110#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03111#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31112#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03113#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59114#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36115#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30116#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33117#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05118#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33119#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19120#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10121#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43122#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18123#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23124#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42125#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39126#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23127#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53128#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58129#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34130#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06131#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57132#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38133#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39134#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08135#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24136#include "ui/message_center/message_center_util.h"
[email protected]fab55e72013-05-31 07:06:18137#include "webkit/common/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04138#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26139
[email protected]b48c9182011-10-26 18:03:30140#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38141#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18142#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38143#elif defined(OS_MACOSX)
144#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56145#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30146#elif defined(OS_CHROMEOS)
147#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]5c915252013-05-07 13:15:39148#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49149#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]5c915252013-05-07 13:15:39150#include "chrome/browser/chromeos/system/statistics_provider.h"
[email protected]931d1042013-04-05 17:50:44151#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26152#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30153#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09154#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38155#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09156#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39157#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30158#elif defined(OS_POSIX)
159#include "chrome/browser/chrome_browser_main_posix.h"
160#endif
161
[email protected]6653c192012-04-10 22:52:44162#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30163#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12164#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43165#endif
[email protected]b80f68432011-05-02 17:22:30166
[email protected]1e87df32012-09-12 04:53:19167#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
168#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
169#endif
170
[email protected]29699c22012-10-03 23:57:39171#if defined(OS_ANDROID)
172#include "ui/base/ui_base_paths.h"
173#endif
174
[email protected]37a72af2011-06-13 05:42:01175#if defined(USE_NSS)
176#include "chrome/browser/ui/crypto_module_password_dialog.h"
177#endif
178
[email protected]d5bcd06f2013-04-21 08:07:24179#if !defined(OS_CHROMEOS)
180#include "chrome/browser/signin/signin_manager.h"
181#include "chrome/browser/signin/signin_manager_factory.h"
182#endif
183
[email protected]02250952013-04-24 23:52:53184#if !defined(OS_ANDROID)
185#include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h"
186#endif
187
[email protected]6ef98b5a2013-05-31 23:58:31188#if defined(ENABLE_WEBRTC)
189#include "chrome/browser/media/webrtc_logging_handler_host.h"
190#endif
191
[email protected]02a3dc122013-06-13 15:07:53192#if defined(FILE_MANAGER_EXTENSION)
193#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
194#endif
195
[email protected]c7abd422012-09-25 00:20:08196using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47197using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03198using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39199using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31200using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59201using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08202using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00203using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11204using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33205using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13206using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06207using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34208using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40209using extensions::Manifest;
[email protected]631bb742011-11-02 11:29:39210
[email protected]c5dbef02011-05-13 05:06:09211namespace {
212
[email protected]eabbfb12013-04-05 23:28:35213// Cached version of the locale so we can return the locale on the I/O
214// thread.
215base::LazyInstance<std::string> g_io_thread_application_locale;
216
[email protected]93f72062013-05-29 20:29:40217#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40218const char* kPredefinedAllowedSocketOrigins[] = {
219 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18220 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45221 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
222 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
223 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
224 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35225 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54226 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
227 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
228 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
229 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
230 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
231 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38232 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58233 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29234 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
235 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
236 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
237 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
238 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40239};
[email protected]93f72062013-05-29 20:29:40240#endif
[email protected]e461da2f2012-02-16 19:06:40241
[email protected]f8f93eb2012-09-25 03:06:24242// Returns a copy of the given url with its host set to given host and path set
243// to given path. Other parts of the url will be the same.
244GURL ReplaceURLHostAndPath(const GURL& url,
245 const std::string& host,
246 const std::string& path) {
247 url_canon::Replacements<char> replacements;
248 replacements.SetHost(host.c_str(),
249 url_parse::Component(0, host.length()));
250 replacements.SetPath(path.c_str(),
251 url_parse::Component(0, path.length()));
252 return url.ReplaceComponents(replacements);
253}
254
255// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
256GURL AddUberHost(const GURL& url) {
257 const std::string uber_host = chrome::kChromeUIUberHost;
258 const std::string new_path = url.host() + url.path();
259
260 return ReplaceURLHostAndPath(url, uber_host, new_path);
261}
262
[email protected]045bf7c2012-09-28 20:27:36263// If url->host() is "chrome" and url->path() has characters other than the
264// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
265// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24266bool RemoveUberHost(GURL* url) {
267 if (url->host() != chrome::kChromeUIUberHost)
268 return false;
269
[email protected]045bf7c2012-09-28 20:27:36270 if (url->path().empty() || url->path() == "/")
271 return false;
272
[email protected]f8f93eb2012-09-25 03:06:24273 const std::string old_path = url->path();
274
275 const std::string::size_type separator = old_path.find('/', 1);
276 std::string new_host;
277 std::string new_path;
278 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36279 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24280 } else {
281 new_host = old_path.substr(1, separator - 1);
282 new_path = old_path.substr(separator);
283 }
284
[email protected]44e8add2013-06-13 17:29:15285 // Do not allow URLs with paths empty before the first slash since we can't
286 // have an empty host. (e.g "foo://chrome//")
287 if (new_host.empty())
288 return false;
289
[email protected]f8f93eb2012-09-25 03:06:24290 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
291
[email protected]44e8add2013-06-13 17:29:15292 DCHECK(url->is_valid());
293
[email protected]f8f93eb2012-09-25 03:06:24294 return true;
295}
296
[email protected]b8148ac2011-07-13 22:03:25297// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42298bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24299 // Do not handle special URLs such as "about:foo"
300 if (!url->host().empty()) {
301 const GURL chrome_url = AddUberHost(*url);
302
303 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
304 // be called.
305 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
306 browser_context, chrome_url))
307 return true;
308 }
309
[email protected]863f70a2012-01-27 02:05:50310 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
311 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25312 return false;
313
[email protected]fe69558d2012-03-12 11:34:49314#if defined(OS_CHROMEOS)
315 // Special case : in ChromeOS in Guest mode bookmarks and history are
316 // disabled for security reasons. New tab page explains the reasons, so
317 // we redirect user to new tab page.
318 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
319 if (url->SchemeIs(chrome::kChromeUIScheme) &&
320 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
321 url->DomainIs(chrome::kChromeUIHistoryHost))) {
322 // Rewrite with new tab URL
323 *url = GURL(chrome::kChromeUINewTabURL);
324 }
325 }
326#endif
327
[email protected]b8148ac2011-07-13 22:03:25328 // Special case the new tab page. In older versions of Chrome, the new tab
329 // page was hosted at chrome-internal:<blah>. This might be in people's saved
330 // sessions or bookmarks, so we say any URL with that scheme triggers the new
331 // tab page.
332 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
333 // Rewrite it with the proper new tab URL.
334 *url = GURL(chrome::kChromeUINewTabURL);
335 }
336
337 return true;
338}
339
[email protected]f8f93eb2012-09-25 03:06:24340// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
341// "chrome://foo/".
342bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
343 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
344 return false;
345
346 return RemoveUberHost(url);
347}
348
[email protected]8d3132f62011-10-12 07:13:42349// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
350// below. Extension, and isolated apps require different privileges to be
351// granted to their RenderProcessHosts. This classification allows us to make
352// sure URLs are served by hosts with the right set of privileges.
353enum RenderProcessHostPrivilege {
354 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45355 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42356 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45357 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42358};
359
360RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
361 const GURL& url,
362 ExtensionService* service) {
363 // Default to a normal renderer cause it is lower privileged. This should only
364 // occur if the URL on a site instance is either malformed, or uninitialized.
365 // If it is malformed, then there is no need for better privileges anyways.
366 // If it is uninitialized, but eventually settles on being an a scheme other
367 // than normal webrenderer, the navigation logic will correct us out of band
368 // anyways.
369 if (!url.is_valid())
370 return PRIV_NORMAL;
371
[email protected]885c0e92012-11-13 20:27:42372 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44373 const Extension* extension =
374 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43375 if (extension &&
376 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42377 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45378 if (extension && extension->is_hosted_app())
379 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42380
381 return PRIV_EXTENSION;
382 }
383
384 return PRIV_NORMAL;
385}
386
387RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30388 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46389 extensions::ProcessMap* process_map,
390 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46391 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30392 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46393 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21394 return PRIV_NORMAL;
395
[email protected]6f371442011-11-09 06:45:46396 for (std::set<std::string>::iterator iter = extension_ids.begin();
397 iter != extension_ids.end(); ++iter) {
398 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43399 if (extension &&
400 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42401 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45402 if (extension && extension->is_hosted_app())
403 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42404 }
405
[email protected]676f6ab2011-10-19 20:23:21406 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42407}
408
[email protected]6786bf402011-12-03 15:19:45409bool CertMatchesFilter(const net::X509Certificate& cert,
410 const base::DictionaryValue& filter) {
411 // TODO(markusheintz): This is the minimal required filter implementation.
412 // Implement a better matcher.
413
414 // An empty filter matches any client certificate since no requirements are
415 // specified at all.
416 if (filter.empty())
417 return true;
418
419 std::string common_name;
420 if (filter.GetString("ISSUER.CN", &common_name) &&
421 (cert.issuer().common_name == common_name)) {
422 return true;
423 }
424 return false;
425}
426
[email protected]f3986f82012-01-03 20:00:06427// Fills |map| with the per-script font prefs under path |map_name|.
428void FillFontFamilyMap(const PrefService* prefs,
429 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53430 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06431 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
432 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
433 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
434 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23435 if (!font_family.empty())
436 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06437 }
438}
439
[email protected]a1733df2012-06-22 11:24:18440#if defined(OS_POSIX) && !defined(OS_MACOSX)
441int GetCrashSignalFD(const CommandLine& command_line) {
442 if (command_line.HasSwitch(switches::kExtensionProcess)) {
443 ExtensionCrashHandlerHostLinux* crash_handler =
444 ExtensionCrashHandlerHostLinux::GetInstance();
445 return crash_handler->GetDeathSignalSocket();
446 }
447
448 std::string process_type =
449 command_line.GetSwitchValueASCII(switches::kProcessType);
450
451 if (process_type == switches::kRendererProcess)
452 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
453
454 if (process_type == switches::kPluginProcess)
455 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
456
457 if (process_type == switches::kPpapiPluginProcess)
458 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
459
460 if (process_type == switches::kGpuProcess)
461 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
462
463 return -1;
464}
465#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
466
[email protected]d5bcd06f2013-04-21 08:07:24467#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30468GURL GetEffectiveURLForSignin(const GURL& url) {
469 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
470
471 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03472 // Copy the path because the argument to SetPathStr must outlive
473 // the Replacements object.
474 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30475 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03476 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30477 effective_url = effective_url.ReplaceComponents(replacements);
478 return effective_url;
479}
[email protected]d5bcd06f2013-04-21 08:07:24480#endif
[email protected]970c63e2013-03-07 00:25:30481
[email protected]eabbfb12013-04-05 23:28:35482void SetApplicationLocaleOnIOThread(const std::string& locale) {
483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
484 g_io_thread_application_locale.Get() = locale;
485}
486
[email protected]9dbfff12011-07-01 19:37:07487} // namespace
[email protected]c5dbef02011-05-13 05:06:09488
[email protected]d977f9c2011-03-14 16:10:26489namespace chrome {
490
[email protected]e461da2f2012-02-16 19:06:40491ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40492#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40493 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
494 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40495#endif
[email protected]1deace22013-05-22 06:14:46496
497 permissions_policy_delegate_.reset(
498 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40499}
500
501ChromeContentBrowserClient::~ChromeContentBrowserClient() {
502}
503
[email protected]bca18382012-06-25 19:15:23504// static
[email protected]c753f142013-02-10 13:14:04505void ChromeContentBrowserClient::RegisterUserPrefs(
[email protected]443e9312013-05-06 06:17:34506 user_prefs::PrefRegistrySyncable* registry) {
507 registry->RegisterBooleanPref(
508 prefs::kDisable3DAPIs,
509 false,
510 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
511 registry->RegisterBooleanPref(
512 prefs::kEnableHyperlinkAuditing,
513 true,
514 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
515 registry->RegisterBooleanPref(
516 prefs::kEnableMemoryInfo,
517 false,
518 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23519}
520
[email protected]eabbfb12013-04-05 23:28:35521// static
522void ChromeContentBrowserClient::SetApplicationLocale(
523 const std::string& locale) {
524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
525
526 // This object is guaranteed to outlive all threads so we don't have to
527 // worry about the lack of refcounting and can just post as Unretained.
528 //
529 // The common case is that this function is called early in Chrome startup
530 // before any threads are created (it will also be called later if the user
531 // changes the pref). In this case, there will be no threads created and
532 // posting will fail. When there are no threads, we can just set the string
533 // without worrying about threadsafety.
534 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
535 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
536 g_io_thread_application_locale.Get() = locale;
537 }
538}
539
[email protected]50462bf02011-11-21 19:13:31540content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
541 const content::MainFunctionParams& parameters) {
542 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30543 // Construct the Main browser parts based on the OS type.
544#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31545 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04546#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31547 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30548#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22549 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26550#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31551 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14552#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09553 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30554#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31555 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04556#else
[email protected]b48c9182011-10-26 18:03:30557 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31558 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30559#endif
560
[email protected]7e75e4a2013-05-17 17:20:03561 chrome::AddProfilesExtraParts(main_parts);
562
[email protected]c7480942011-11-08 19:18:27563 // Construct additional browser parts. Stages are called in the order in
564 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22565#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41566 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04567#endif
[email protected]c7480942011-11-08 19:18:27568
569#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41570 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27571#endif
572
[email protected]dc04be7c2012-03-15 23:57:49573#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41574 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49575#endif
576
[email protected]e050ef142012-03-21 01:04:24577#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41578 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24579#endif
580
[email protected]95132f52013-04-12 02:19:04581 chrome::AddMetricsExtraParts(main_parts);
582
[email protected]50462bf02011-11-21 19:13:31583 return main_parts;
[email protected]f967b722011-09-07 00:58:04584}
585
[email protected]e94bbcb2012-09-07 05:33:57586std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19587 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57588 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53589 std::string partition_id;
590
591 // The partition ID for webview guest processes is the string value of its
592 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
593 if (site.SchemeIs(chrome::kGuestScheme))
594 partition_id = site.spec();
595
[email protected]056efdc2013-04-06 00:14:53596 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53597 return partition_id;
598}
599
600bool ChromeContentBrowserClient::IsValidStoragePartitionId(
601 content::BrowserContext* browser_context,
602 const std::string& partition_id) {
603 // The default ID is empty and is always valid.
604 if (partition_id.empty())
605 return true;
606
607 return GURL(partition_id).is_valid();
608}
609
610void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
611 content::BrowserContext* browser_context,
612 const GURL& site,
[email protected]14acc642012-11-17 12:20:10613 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53614 std::string* partition_domain,
615 std::string* partition_name,
616 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10617 // Default to the browser-wide storage partition and override based on |site|
618 // below.
619 partition_domain->clear();
620 partition_name->clear();
621 *in_memory = false;
622
[email protected]1bc28312012-11-08 08:31:53623 // For the webview tag, we create special guest processes, which host the
624 // tag content separately from the main application that embeds the tag.
625 // A webview tag can specify both the partition name and whether the storage
626 // for that partition should be persisted. Each tag gets a SiteInstance with
627 // a specially formatted URL, based on the application it is hosted by and
628 // the partition requested by it. The format for that URL is:
629 // chrome-guest://partition_domain/persist?partition_name
630 if (site.SchemeIs(chrome::kGuestScheme)) {
631 // Since guest URLs are only used for packaged apps, there must be an app
632 // id in the URL.
633 CHECK(site.has_host());
634 *partition_domain = site.host();
635 // Since persistence is optional, the path must either be empty or the
636 // literal string.
637 *in_memory = (site.path() != "/persist");
638 // The partition name is user supplied value, which we have encoded when the
639 // URL was created, so it needs to be decoded.
640 *partition_name = net::UnescapeURLComponent(site.query(),
641 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10642 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
643 // If |can_be_default| is false, the caller is stating that the |site|
644 // should be parsed as if it had isolated storage. In particular it is
645 // important to NOT check ExtensionService for the is_storage_isolated()
646 // attribute because this code path is run during Extension uninstall
647 // to do cleanup after the Extension has already been unloaded from the
648 // ExtensionService.
649 bool is_isolated = !can_be_default;
650 if (can_be_default) {
651 const Extension* extension = NULL;
652 Profile* profile = Profile::FromBrowserContext(browser_context);
653 ExtensionService* extension_service =
654 extensions::ExtensionSystem::Get(profile)->extension_service();
655 if (extension_service) {
656 extension = extension_service->extensions()->
657 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43658 if (extension &&
659 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10660 is_isolated = true;
661 }
662 }
663 }
[email protected]1bc28312012-11-08 08:31:53664
[email protected]14acc642012-11-17 12:20:10665 if (is_isolated) {
666 CHECK(site.has_host());
667 // For extensions with isolated storage, the the host of the |site| is
668 // the |partition_domain|. The |in_memory| and |partition_name| are only
669 // used in guest schemes so they are cleared here.
670 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53671 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10672 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53673 }
[email protected]d1198fd2012-08-13 22:50:19674 }
675
[email protected]14acc642012-11-17 12:20:10676 // Assert that if |can_be_default| is false, the code above must have found a
677 // non-default partition. If this fails, the caller has a serious logic
678 // error about which StoragePartition they expect to be in and it is not
679 // safe to continue.
680 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44681}
682
[email protected]38b098f2012-03-14 21:11:57683content::WebContentsViewDelegate*
684 ChromeContentBrowserClient::GetWebContentsViewDelegate(
685 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27686 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32687}
688
[email protected]24665682013-02-25 20:59:38689// Check if the extension activity log is enabled for the profile.
690static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33691 // crbug.com/247908 - This should be IsLogEnabled except for an issue
692 // in chrome_frame_net_tests
693 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38694}
695
[email protected]44295a12013-06-05 08:45:46696void ChromeContentBrowserClient::GuestWebContentsAttached(
697 WebContents* guest_web_contents,
698 WebContents* embedder_web_contents,
699 int browser_plugin_instance_id) {
[email protected]44703cc72013-01-24 04:56:06700 Profile* profile = Profile::FromBrowserContext(
701 embedder_web_contents->GetBrowserContext());
702 ExtensionService* service =
703 extensions::ExtensionSystem::Get(profile)->extension_service();
704 if (!service)
705 return;
706 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
707 const Extension* extension = service->extensions()->
708 GetExtensionOrAppByURL(ExtensionURLInfo(url));
709 if (!extension)
710 return;
711 std::vector<ExtensionMsg_Loaded_Params> extensions;
712 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
713 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
[email protected]44295a12013-06-05 08:45:46714 new WebViewGuest(guest_web_contents,
715 embedder_web_contents,
716 extension->id(),
717 browser_plugin_instance_id);
[email protected]44703cc72013-01-24 04:56:06718}
719
[email protected]f3b1a082011-11-18 00:34:30720void ChromeContentBrowserClient::RenderProcessHostCreated(
721 content::RenderProcessHost* host) {
722 int id = host->GetID();
723 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41724 net::URLRequestContextGetter* context =
725 profile->GetRequestContextForRenderProcess(id);
726
[email protected]f3b1a082011-11-18 00:34:30727 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41728 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55729#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30730 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55731#endif
[email protected]658677f2012-06-09 06:04:02732#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08733 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03734#endif
[email protected]f3b1a082011-11-18 00:34:30735 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02736 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30737 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56738#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21739 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56740#endif
[email protected]43535512013-02-20 20:41:41741 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
742 id, profile, context));
[email protected]2736c032012-05-11 18:06:07743 host->GetChannel()->AddFilter(
744 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27745 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33746 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31747#if defined(ENABLE_WEBRTC)
748 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
749#endif
[email protected]01e59752013-06-18 00:17:35750#if !defined(DISABLE_NACL)
751 host->GetChannel()->AddFilter(new NaClHostMessageFilter(id, profile,
752 context));
753#endif
[email protected]3e69bc82011-05-26 23:22:38754
[email protected]2ccf45c2011-08-19 23:35:50755 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
756 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07757
[email protected]24665682013-02-25 20:59:38758 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
759 IsExtensionActivityLogEnabledForProfile(profile)));
760
[email protected]39a5b532011-10-22 01:47:07761 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56762
763 RendererContentSettingRules rules;
764 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
765 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14766}
767
[email protected]95c95552013-05-03 04:21:22768GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
769 content::BrowserContext* browser_context,
770 const GURL& url,
771 bool is_renderer_initiated,
772 content::SiteInstance* current_instance) {
773 Profile* profile = Profile::FromBrowserContext(browser_context);
774 if (!profile)
775 return url;
776
777 // Only return the privileged instant URL if we are entering from a browser-
778 // initiated navigation or if we are already in the instant process.
779 bool is_instant_process = false;
780 int process_id = current_instance->GetProcess()->GetID();
781 InstantService* instant_service =
782 InstantServiceFactory::GetForProfile(profile);
783 if (instant_service)
784 is_instant_process = instant_service->IsInstantProcess(process_id);
785
786 DCHECK_EQ(is_instant_process,
787 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
788 if (!is_renderer_initiated || is_instant_process) {
789 // If the input |url| should be assigned to the Instant renderer, make its
790 // privileged URL distinct from other URLs on the search provider's domain.
791 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
792 return chrome::GetPrivilegedURLForInstant(url, profile);
793 }
794
795 return url;
796}
797
[email protected]3d7474ff2011-07-27 17:47:37798GURL ChromeContentBrowserClient::GetEffectiveURL(
799 content::BrowserContext* browser_context, const GURL& url) {
800 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52801 if (!profile)
802 return url;
803
[email protected]d5bcd06f2013-04-21 08:07:24804#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30805 // If the input |url| should be assigned to the Signin renderer, make its
806 // effective URL distinct from other URLs on the signin service's domain.
807 // Note that the signin renderer will be allowed to sign the user in to
808 // Chrome.
809 if (SigninManager::IsWebBasedSigninFlowURL(url))
810 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24811#endif
[email protected]970c63e2013-03-07 00:25:30812
[email protected]c5dec6292013-01-25 04:54:52813 // If the input |url| is part of an installed app, the effective URL is an
814 // extension URL with the ID of that extension as the host. This has the
815 // effect of grouping apps together in a common SiteInstance.
816 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13817 extensions::ExtensionSystem::Get(profile)->extension_service();
818 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08819 return url;
820
[email protected]06bdd2b2012-11-30 18:47:13821 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44822 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08823 if (!extension)
824 return url;
825
[email protected]15877ca2011-11-18 22:40:52826 // Bookmark apps do not use the hosted app process model, and should be
827 // treated as normal URLs.
828 if (extension->from_bookmark())
829 return url;
830
[email protected]36fb2c7c2011-04-04 15:49:08831 // If the URL is part of an extension's web extent, convert it to an
832 // extension URL.
833 return extension->GetResourceURL(url.path());
834}
835
[email protected]056ad2a2011-07-12 02:13:55836bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37837 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52838 // Non-extension, non-Instant URLs should generally use
839 // process-per-site-instance. Because we expect to use the effective URL,
840 // URLs for hosted apps (apart from bookmark apps) should have an extension
841 // scheme by now.
842
843 Profile* profile = Profile::FromBrowserContext(browser_context);
844 if (!profile)
845 return false;
846
[email protected]165fe422013-03-27 06:34:03847 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52848 return true;
849
[email protected]d5bcd06f2013-04-21 08:07:24850#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30851 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
852 return true;
[email protected]d5bcd06f2013-04-21 08:07:24853#endif
[email protected]970c63e2013-03-07 00:25:30854
[email protected]885c0e92012-11-13 20:27:42855 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55856 return false;
857
[email protected]c5dec6292013-01-25 04:54:52858 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13859 extensions::ExtensionSystem::Get(profile)->extension_service();
860 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55861 return false;
862
[email protected]06bdd2b2012-11-30 18:47:13863 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44864 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55865 if (!extension)
866 return false;
867
868 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53869 // permission, or that does not allow JavaScript access to the background
870 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55871 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40872 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06873 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29874 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53875 return false;
876 }
877 }
[email protected]056ad2a2011-07-12 02:13:55878
[email protected]7b54ca02012-03-02 18:06:53879 // Hosted apps that have script access to their background page must use
880 // process per site, since all instances can make synchronous calls to the
881 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55882 return true;
883}
884
[email protected]672c8c12013-03-07 12:30:06885// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41886void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
887 std::vector<std::string>* additional_schemes) {
888 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06889}
890
[email protected]6bd30072013-02-08 18:17:11891net::URLRequestContextGetter*
892ChromeContentBrowserClient::CreateRequestContext(
893 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06894 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11895 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06896 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11897}
898
899net::URLRequestContextGetter*
900ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
901 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40902 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11903 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06904 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11905 Profile* profile = Profile::FromBrowserContext(browser_context);
906 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06907 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11908}
909
[email protected]46fb9442011-12-09 17:57:47910bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
911 return ProfileIOData::IsHandledURL(url);
912}
913
[email protected]c4365fa42013-05-14 01:08:24914bool ChromeContentBrowserClient::CanCommitURL(
915 content::RenderProcessHost* process_host,
916 const GURL& url) {
917 // We need to let most extension URLs commit in any process, since this can
918 // be allowed due to web_accessible_resources. Most hosted app URLs may also
919 // load in any process (e.g., in an iframe). However, the Chrome Web Store
920 // cannot be loaded in iframes and should never be requested outside its
921 // process.
922 Profile* profile =
923 Profile::FromBrowserContext(process_host->GetBrowserContext());
924 ExtensionService* service =
925 extensions::ExtensionSystem::Get(profile)->extension_service();
926 if (!service)
927 return true;
928 const Extension* new_extension =
929 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
930 if (new_extension &&
931 new_extension->is_hosted_app() &&
932 new_extension->id() == extension_misc::kWebStoreAppId &&
933 !service->process_map()->Contains(new_extension->id(),
934 process_host->GetID())) {
935 return false;
936 }
937
938 return true;
939}
940
[email protected]2a5221b2011-09-27 23:07:31941bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30942 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31943 const GURL& site_url) {
944 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30945 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52946 // This may be NULL during tests. In that case, just assume any site can
947 // share any host.
948 if (!profile)
949 return true;
950
[email protected]d43f99fe2013-04-03 00:20:14951 // Instant URLs should only be in the instant process and instant process
952 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52953 InstantService* instant_service =
954 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14955 if (instant_service) {
956 bool is_instant_process = instant_service->IsInstantProcess(
957 process_host->GetID());
958 bool should_be_in_instant_process =
959 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
960 if (is_instant_process || should_be_in_instant_process)
961 return is_instant_process && should_be_in_instant_process;
962 }
[email protected]c5dec6292013-01-25 04:54:52963
[email protected]d5bcd06f2013-04-21 08:07:24964#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30965 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
966 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
967 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:24968#endif
[email protected]970c63e2013-03-07 00:25:30969
[email protected]06bdd2b2012-11-30 18:47:13970 ExtensionService* service =
971 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46972 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31973
[email protected]ffa97602011-11-17 17:55:52974 // Don't allow the Task Manager to share a process with anything else.
975 // Otherwise it can affect the renderers it is observing.
976 // Note: we could create another RenderProcessHostPrivilege bucket for
977 // this to allow multiple chrome://tasks instances to share, but that's
978 // a very unlikely case without serious consequences.
979 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
980 return false;
981
[email protected]8d3132f62011-10-12 07:13:42982 // These may be NULL during tests. In that case, just assume any site can
983 // share any host.
[email protected]6f371442011-11-09 06:45:46984 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31985 return true;
986
[email protected]eec0b33c2011-12-05 22:09:45987 // Otherwise, just make sure the process privilege matches the privilege
988 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57989 RenderProcessHostPrivilege privilege_required =
990 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45991 return GetProcessPrivilege(process_host, process_map, service) ==
992 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31993}
994
[email protected]76411f412012-02-22 18:56:06995// This function is trying to limit the amount of processes used by extensions
996// with background pages. It uses a globally set percentage of processes to
997// run such extensions and if the limit is exceeded, it returns true, to
998// indicate to the content module to group extensions together.
999bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1000 content::BrowserContext* browser_context, const GURL& url) {
1001 // It has to be a valid URL for us to check for an extension.
1002 if (!url.is_valid())
1003 return false;
1004
1005 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191006 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131007 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061008 if (!service)
1009 return false;
1010
1011 // We have to have a valid extension with background page to proceed.
1012 const Extension* extension =
1013 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
1014 if (!extension)
1015 return false;
[email protected]9367eabc2013-03-01 01:29:291016 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061017 return false;
1018
1019 std::set<int> process_ids;
1020 size_t max_process_count =
1021 content::RenderProcessHost::GetMaxRendererProcessCount();
1022
1023 // Go through all profiles to ensure we have total count of extension
1024 // processes containing background pages, otherwise one profile can
1025 // starve the other.
1026 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1027 GetLoadedProfiles();
1028 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031029 ExtensionProcessManager* epm =
1030 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321031 for (ExtensionProcessManager::const_iterator iter =
1032 epm->background_hosts().begin();
1033 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131034 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321035 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061036 }
1037 }
1038
1039 if (process_ids.size() >
1040 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1041 return true;
1042 }
1043
1044 return false;
1045}
1046
[email protected]6f371442011-11-09 06:45:461047void ChromeContentBrowserClient::SiteInstanceGotProcess(
1048 SiteInstance* site_instance) {
1049 CHECK(site_instance->HasProcess());
1050
1051 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021052 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521053 if (!profile)
1054 return;
1055
1056 // Remember the ID of the Instant process to signal the renderer process
1057 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031058 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321059 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521060 InstantService* instant_service =
1061 InstantServiceFactory::GetForProfile(profile);
1062 if (instant_service)
1063 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1064 }
1065
[email protected]d5bcd06f2013-04-21 08:07:241066#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301067 // We only expect there to be one signin process as we use process-per-site
1068 // for signin URLs. The signin process will be cleared from SigninManager
1069 // when the renderer is destroyed.
1070 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1071 SigninManager* signin_manager =
1072 SigninManagerFactory::GetForProfile(profile);
1073 if (signin_manager)
1074 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461075 BrowserThread::PostTask(
1076 BrowserThread::IO, FROM_HERE,
1077 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1078 extensions::ExtensionSystem::Get(profile)->info_map(),
1079 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301080 }
[email protected]d5bcd06f2013-04-21 08:07:241081#endif
[email protected]970c63e2013-03-07 00:25:301082
[email protected]06bdd2b2012-11-30 18:47:131083 ExtensionService* service =
1084 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461085 if (!service)
1086 return;
1087
1088 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441089 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591090 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461091 if (!extension)
1092 return;
1093
[email protected]6bc04fd82011-12-04 02:29:351094 service->process_map()->Insert(extension->id(),
1095 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331096 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461097 BrowserThread::PostTask(
1098 BrowserThread::IO, FROM_HERE,
1099 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591100 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461101 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351102 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331103 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461104}
1105
1106void ChromeContentBrowserClient::SiteInstanceDeleting(
1107 SiteInstance* site_instance) {
1108 if (!site_instance->HasProcess())
1109 return;
1110
1111 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021112 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131113 ExtensionService* service =
1114 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461115 if (!service)
1116 return;
1117
1118 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441119 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591120 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461121 if (!extension)
1122 return;
1123
[email protected]6bc04fd82011-12-04 02:29:351124 service->process_map()->Remove(extension->id(),
1125 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331126 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461127 BrowserThread::PostTask(
1128 BrowserThread::IO, FROM_HERE,
1129 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591130 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461131 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351132 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331133 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461134}
1135
[email protected]f05763972012-06-06 18:17:261136bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141137 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081138 const GURL& current_url,
1139 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261140 if (current_url.is_empty()) {
1141 // Always choose a new process when navigating to extension URLs. The
1142 // process grouping logic will combine all of a given extension's pages
1143 // into the same process.
[email protected]885c0e92012-11-13 20:27:421144 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261145 return true;
[email protected]e3daf3c2011-10-05 21:17:081146
[email protected]f05763972012-06-06 18:17:261147 return false;
1148 }
1149
1150 // Also, we must switch if one is an extension and the other is not the exact
1151 // same extension.
[email protected]885c0e92012-11-13 20:27:421152 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1153 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261154 if (current_url.GetOrigin() != new_url.GetOrigin())
1155 return true;
1156 }
1157
[email protected]e9841fbd2013-02-22 23:12:141158 // The checks below only matter if we can retrieve which extensions are
1159 // installed.
1160 Profile* profile =
1161 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1162 ExtensionService* service =
1163 extensions::ExtensionSystem::Get(profile)->extension_service();
1164 if (!service)
1165 return false;
1166
1167 // We must swap if the URL is for an extension and we are not using an
1168 // extension process.
1169 const Extension* new_extension =
1170 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1171 // Ignore all hosted apps except the Chrome Web Store, since they do not
1172 // require their own BrowsingInstance (e.g., postMessage is ok).
1173 if (new_extension &&
1174 new_extension->is_hosted_app() &&
1175 new_extension->id() != extension_misc::kWebStoreAppId)
1176 new_extension = NULL;
1177 if (new_extension &&
1178 site_instance->HasProcess() &&
1179 !service->process_map()->Contains(new_extension->id(),
1180 site_instance->GetProcess()->GetID()))
1181 return true;
1182
[email protected]f05763972012-06-06 18:17:261183 return false;
[email protected]e3daf3c2011-10-05 21:17:081184}
1185
[email protected]395045c2012-05-22 15:04:381186bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1187 content::ResourceContext* resource_context, const GURL& current_url,
1188 const GURL& new_url) {
1189 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1190 return extensions::CrossesExtensionProcessBoundary(
1191 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171192 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381193}
1194
[email protected]763ec4ca2011-04-29 15:48:121195std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1196 const std::string& alias_name) {
1197 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1198}
1199
[email protected]b80f68432011-05-02 17:22:301200void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1201 CommandLine* command_line, int child_process_id) {
1202#if defined(USE_LINUX_BREAKPAD)
1203 if (IsCrashReporterEnabled()) {
1204 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1205 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1206 }
1207#elif defined(OS_MACOSX)
1208 if (IsCrashReporterEnabled()) {
1209 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1210 child_process_logging::GetClientId());
1211 }
1212#endif // OS_MACOSX
1213
[email protected]f1933792011-06-14 00:49:341214 if (logging::DialogsAreSuppressed())
1215 command_line->AppendSwitch(switches::kNoErrorDialogs);
1216
[email protected]b80f68432011-05-02 17:22:301217 std::string process_type =
1218 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171219 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321220
1221 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1222 command_line->AppendSwitch(switches::kChromeFrame);
1223
[email protected]718eab62011-10-05 21:16:521224 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451225 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301226 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1227 if (!user_data_dir.empty())
1228 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1229#if defined(OS_CHROMEOS)
1230 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441231 browser_command_line.GetSwitchValueASCII(
1232 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301233 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441234 command_line->AppendSwitchASCII(
1235 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301236#endif
1237
[email protected]f3b1a082011-11-18 00:34:301238 content::RenderProcessHost* process =
1239 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371240 if (process) {
1241 Profile* profile = Profile::FromBrowserContext(
1242 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131243 ExtensionService* extension_service =
1244 extensions::ExtensionSystem::Get(profile)->extension_service();
1245 if (extension_service) {
1246 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001247 if (process_map && process_map->Contains(process->GetID()))
1248 command_line->AppendSwitch(switches::kExtensionProcess);
1249 }
[email protected]b80f68432011-05-02 17:22:301250
[email protected]a8d851f82011-12-21 00:32:371251 PrefService* prefs = profile->GetPrefs();
1252 // Currently this pref is only registered if applied via a policy.
1253 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1254 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1255 // Turn this policy into a command line switch.
1256 command_line->AppendSwitch(switches::kDisable3DAPIs);
1257 }
[email protected]718eab62011-10-05 21:16:521258
[email protected]a8d851f82011-12-21 00:32:371259 // Disable client-side phishing detection in the renderer if it is
1260 // disabled in the Profile preferences or the browser process.
1261 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1262 !g_browser_process->safe_browsing_detection_service()) {
1263 command_line->AppendSwitch(
1264 switches::kDisableClientSidePhishingDetection);
1265 }
[email protected]0045b0f42012-07-26 11:52:081266
1267 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211268 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521269
1270 InstantService* instant_service =
1271 InstantServiceFactory::GetForProfile(profile);
1272 if (instant_service &&
1273 instant_service->IsInstantProcess(process->GetID()))
1274 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301275
[email protected]d5bcd06f2013-04-21 08:07:241276#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301277 SigninManager* signin_manager =
1278 SigninManagerFactory::GetForProfile(profile);
1279 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1280 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241281#endif
[email protected]47c7ec82012-01-18 03:29:211282 }
[email protected]4287a3d2011-06-13 23:56:511283
[email protected]87552982012-11-02 17:21:401284 if (content::IsThreadedCompositingEnabled())
1285 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1286
[email protected]16dc42452013-04-09 04:37:191287 if (message_center::IsRichNotificationEnabled())
1288 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191289
[email protected]47c7ec82012-01-18 03:29:211290 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511291 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171292 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481293 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171294 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511295 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481296 switches::kAllowLegacyExtensionManifests,
[email protected]9d450492013-06-13 23:08:371297 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1298 // to browser.
1299 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511300 switches::kAllowScriptingGallery,
1301 switches::kAppsCheckoutURL,
1302 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311303 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511304 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501305 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531306 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111307 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531308 switches::kEnableAdview,
1309 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211310 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511311 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511312 switches::kEnableIPCFuzzing,
1313 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451314 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481315 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051316 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511317 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291318 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511319 switches::kMemoryProfiling,
1320 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371321 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371322 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511323 switches::kPpapiFlashArgs,
1324 switches::kPpapiFlashInProcess,
1325 switches::kPpapiFlashPath,
1326 switches::kPpapiFlashVersion,
1327 switches::kProfilingAtStart,
1328 switches::kProfilingFile,
1329 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371330 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511331 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291332 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381333 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511334 };
1335
1336 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1337 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171338 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381339 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351340 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381341 switches::kEnableExperimentalExtensionApis,
1342 switches::kWhitelistedExtensionID,
1343 };
1344
1345 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1346 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511347 } else if (process_type == switches::kPluginProcess) {
1348 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441349#if defined(OS_CHROMEOS)
1350 chromeos::switches::kLoginProfile,
1351#endif
[email protected]4287a3d2011-06-13 23:56:511352 switches::kMemoryProfiling,
1353 switches::kSilentDumpOnDCHECK,
1354 switches::kUserDataDir,
1355 };
1356
1357 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1358 arraysize(kSwitchNames));
1359 } else if (process_type == switches::kZygoteProcess) {
1360 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511361 switches::kUserDataDir, // Make logs go to the right file.
1362 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501363 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511364 switches::kPpapiFlashInProcess,
1365 switches::kPpapiFlashPath,
1366 switches::kPpapiFlashVersion,
1367 };
1368
1369 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1370 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111371 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001372 base::FilePath user_data_dir =
1373 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1374 if (!user_data_dir.empty())
1375 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111376 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1377 // because GPU is expected to be unreliable.
1378 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1379 !command_line->HasSwitch(switches::kDisableBreakpad))
1380 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301381 }
[email protected]6f08af82011-09-15 01:19:031382
1383 // The command line switch kEnableBenchmarking needs to be specified along
1384 // with the kEnableStatsTable switch to ensure that the stats table global
1385 // is initialized correctly.
1386 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1387 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301388}
1389
1390std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431391 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351392 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301393 return g_browser_process->GetApplicationLocale();
1394}
1395
[email protected]597a867b2011-11-18 18:31:201396std::string ChromeContentBrowserClient::GetAcceptLangs(
1397 content::BrowserContext* context) {
1398 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371399 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081400}
1401
[email protected]9ec0f452012-05-31 15:58:531402gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221403 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531404 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081405}
1406
[email protected]a2176792011-05-08 19:30:491407bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091408 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191409 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201410 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201412 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051413 return io_data->GetCookieSettings()->
1414 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491415}
1416
[email protected]ed24fad2011-05-10 22:44:011417bool ChromeContentBrowserClient::AllowGetCookie(
1418 const GURL& url,
1419 const GURL& first_party,
1420 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201421 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011422 int render_process_id,
1423 int render_view_id) {
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 bool allow = io_data->GetCookieSettings()->
1427 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011428
[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::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431432 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011433 return allow;
1434}
1435
1436bool ChromeContentBrowserClient::AllowSetCookie(
1437 const GURL& url,
1438 const GURL& first_party,
1439 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201440 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011441 int render_process_id,
1442 int render_view_id,
1443 net::CookieOptions* options) {
1444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201445 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051446 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1447 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1448
[email protected]8093a542011-05-13 07:29:321449 BrowserThread::PostTask(
1450 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031451 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431452 render_view_id, url, first_party, cookie_line, *options,
1453 !allow));
[email protected]ed24fad2011-05-10 22:44:011454 return allow;
1455}
1456
[email protected]d5a19162011-06-30 18:51:541457bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201458 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201460 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431461 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1462 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261463
[email protected]bf510ed2012-06-05 08:31:431464 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1465 // Could we even support per-origin settings?
1466 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541467}
1468
[email protected]5c5a88e2011-11-12 00:45:351469bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351470 const GURL& url,
1471 const string16& name,
1472 const string16& display_name,
1473 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201474 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481475 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201477 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351478 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1479 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1480
[email protected]62151052012-02-01 18:40:481481 // Record access to database for potential display in UI.
1482 std::vector<std::pair<int, int> >::const_iterator i;
1483 for (i = render_views.begin(); i != render_views.end(); ++i) {
1484 BrowserThread::PostTask(
1485 BrowserThread::UI, FROM_HERE,
1486 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1487 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351488 }
1489
1490 return allow;
1491}
1492
1493bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351494 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201495 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481496 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201498 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351499 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1500 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1501
[email protected]62151052012-02-01 18:40:481502 // Record access to file system for potential display in UI.
1503 std::vector<std::pair<int, int> >::const_iterator i;
1504 for (i = render_views.begin(); i != render_views.end(); ++i) {
1505 BrowserThread::PostTask(
1506 BrowserThread::UI, FROM_HERE,
1507 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1508 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351509 }
1510
1511 return allow;
1512}
1513
[email protected]7c5ff9a2012-03-02 07:42:491514bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1515 const GURL& url,
1516 const string16& name,
1517 content::ResourceContext* context,
1518 const std::vector<std::pair<int, int> >& render_views) {
1519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1520 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1521 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1522 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1523
1524 // Record access to IndexedDB for potential display in UI.
1525 std::vector<std::pair<int, int> >::const_iterator i;
1526 for (i = render_views.begin(); i != render_views.end(); ++i) {
1527 BrowserThread::PostTask(
1528 BrowserThread::UI, FROM_HERE,
1529 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1530 i->first, i->second, url, name, !allow));
1531 }
1532
1533 return allow;
1534}
1535
[email protected]6133f922011-07-01 21:34:341536net::URLRequestContext*
1537ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201538 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341539 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421540 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201541 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341542 return io_data->extensions_request_context();
1543 }
1544
1545 return NULL;
1546}
1547
[email protected]317f96c92011-05-31 06:53:411548QuotaPermissionContext*
1549ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1550 return new ChromeQuotaPermissionContext();
1551}
1552
[email protected]848dd042011-06-04 18:24:031553void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171554 int render_process_id,
1555 int render_view_id,
1556 int cert_error,
1557 const net::SSLInfo& ssl_info,
1558 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021559 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031560 bool overridable,
[email protected]d9be47702012-05-16 03:41:221561 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171562 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001563 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021564 if (resource_type != ResourceType::MAIN_FRAME) {
1565 // A sub-resource has a certificate error. The user doesn't really
1566 // have a context for making the right decision, so block the
1567 // request hard, without an info bar to allow showing the insecure
1568 // content.
[email protected]8c965c22013-05-23 19:28:001569 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021570 return;
1571 }
1572
[email protected]f9034cf2011-07-21 12:43:411573 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131574 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171575 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411576 if (!tab) {
1577 NOTREACHED();
1578 return;
1579 }
1580 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501581 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301582 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011583 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1584 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411585 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171586 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411587 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001588 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411589 return;
1590 }
1591 }
1592
[email protected]1e87df32012-09-12 04:53:191593#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231594 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1595 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1596 if (captive_portal_tab_helper)
1597 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191598#endif
1599
[email protected]f9034cf2011-07-21 12:43:411600 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221601 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1602 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031603}
1604
[email protected]c99c442e2011-08-24 11:37:301605void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451606 int render_process_id,
1607 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401608 const net::HttpNetworkSession* network_session,
1609 net::SSLCertRequestInfo* cert_request_info,
1610 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131611 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451612 render_process_id, render_view_id);
1613 if (!tab) {
1614 NOTREACHED();
1615 return;
1616 }
1617
[email protected]6786bf402011-12-03 15:19:451618 GURL requesting_url("https://" + cert_request_info->host_and_port);
1619 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1620 << cert_request_info->host_and_port;
1621
[email protected]627e0512011-12-21 22:55:301622 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451623 scoped_ptr<Value> filter(
1624 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1625 requesting_url,
1626 requesting_url,
1627 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1628 std::string(), NULL));
1629
1630 if (filter.get()) {
1631 // Try to automatically select a client certificate.
1632 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1633 DictionaryValue* filter_dict =
1634 static_cast<DictionaryValue*>(filter.get());
1635
1636 const std::vector<scoped_refptr<net::X509Certificate> >&
1637 all_client_certs = cert_request_info->client_certs;
1638 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091639 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451640 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091641 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451642 return;
1643 }
1644 }
1645 } else {
1646 NOTREACHED();
1647 }
1648 }
1649
[email protected]11feec322012-09-18 03:58:521650 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1651 if (!ssl_tab_helper) {
1652 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451653 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141654 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401655 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451656 return;
1657 }
[email protected]11feec322012-09-18 03:58:521658 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401659 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451660}
1661
[email protected]3b455502012-12-11 18:22:581662void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451663 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581664 net::CertificateMimeType cert_type,
1665 const void* cert_data,
1666 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451667 int render_process_id,
1668 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581669 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1670 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451671}
1672
[email protected]dc73a7b2012-03-25 15:27:181673content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561674 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181675}
1676
[email protected]941623e2011-06-07 23:06:041677void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1678 const GURL& source_origin,
1679 int callback_context,
1680 int render_process_id,
1681 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111682#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1684 WebContents* contents =
1685 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1686 if (!contents) {
[email protected]941623e2011-06-07 23:06:041687 NOTREACHED();
1688 return;
1689 }
1690
[email protected]d0d9c3ee2012-06-19 03:07:021691 // Skip showing the infobar if the request comes from an extension, and that
1692 // extension has the 'notify' permission. (If the extension does not have the
1693 // permission, the user will still be prompted.)
1694 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011695 ExtensionInfoMap* extension_info_map =
1696 extensions::ExtensionSystem::Get(profile)->info_map();
1697 DesktopNotificationService* notification_service =
1698 DesktopNotificationServiceFactory::GetForProfile(profile);
1699 const Extension* extension = NULL;
1700 if (extension_info_map) {
1701 ExtensionSet extensions;
1702 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1703 source_origin, render_process_id,
1704 extensions::APIPermission::kNotification, &extensions);
1705 for (ExtensionSet::const_iterator iter = extensions.begin();
1706 iter != extensions.end(); ++iter) {
1707 if (notification_service->IsExtensionEnabled((*iter)->id())) {
[email protected]cadac622013-06-11 16:46:361708 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011709 break;
1710 }
1711 }
1712 }
[email protected]eb4832a2012-12-08 01:57:521713 RenderViewHost* rvh =
1714 RenderViewHost::FromID(render_process_id, render_view_id);
1715 if (IsExtensionWithPermissionOrSuggestInConsole(
1716 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021717 if (rvh)
1718 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1719 return;
1720 }
1721
[email protected]c7cd5942013-04-30 03:31:011722 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021723 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111724#else
1725 NOTIMPLEMENTED();
1726#endif
[email protected]941623e2011-06-07 23:06:041727}
1728
1729WebKit::WebNotificationPresenter::Permission
1730 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021731 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201732 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021733 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111734#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201736 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041737
[email protected]c7cd5942013-04-30 03:31:011738 DesktopNotificationService* notification_service =
1739 io_data->GetNotificationService();
1740 if (notification_service) {
1741 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1742 ExtensionSet extensions;
1743 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1744 source_origin, render_process_id,
1745 extensions::APIPermission::kNotification, &extensions);
1746 for (ExtensionSet::const_iterator iter = extensions.begin();
1747 iter != extensions.end(); ++iter) {
1748 if (notification_service->IsExtensionEnabled((*iter)->id()))
1749 return WebKit::WebNotificationPresenter::PermissionAllowed;
1750 }
1751
1752 return notification_service->HasPermission(source_origin);
1753 }
1754
1755 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111756#else
1757 return WebKit::WebNotificationPresenter::PermissionAllowed;
1758#endif
[email protected]941623e2011-06-07 23:06:041759}
1760
1761void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171762 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041763 int render_process_id,
1764 int render_view_id,
1765 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111766#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041767 RenderViewHost* rvh = RenderViewHost::FromID(
1768 render_process_id, render_view_id);
1769 if (!rvh) {
1770 NOTREACHED();
1771 return;
1772 }
1773
[email protected]9f76c1e2012-03-05 15:15:581774 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301775 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041776 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371777 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041778 service->ShowDesktopNotification(
1779 params, render_process_id, render_view_id,
1780 worker ? DesktopNotificationService::WorkerNotification :
1781 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111782#else
1783 NOTIMPLEMENTED();
1784#endif
[email protected]941623e2011-06-07 23:06:041785}
1786
1787void ChromeContentBrowserClient::CancelDesktopNotification(
1788 int render_process_id,
1789 int render_view_id,
1790 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111791#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041792 RenderViewHost* rvh = RenderViewHost::FromID(
1793 render_process_id, render_view_id);
1794 if (!rvh) {
1795 NOTREACHED();
1796 return;
1797 }
1798
[email protected]9f76c1e2012-03-05 15:15:581799 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301800 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041801 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371802 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041803 service->CancelDesktopNotification(
1804 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111805#else
1806 NOTIMPLEMENTED();
1807#endif
[email protected]941623e2011-06-07 23:06:041808}
1809
[email protected]9f3fba52011-06-08 20:37:191810bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351811 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021812 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191813 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201814 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011815 int render_process_id,
1816 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191817 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011818
1819 *no_javascript_access = false;
1820
[email protected]9f3fba52011-06-08 20:37:191821 // If the opener is trying to create a background window but doesn't have
1822 // the appropriate permission, fail the attempt.
1823 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201824 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531825 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1826
[email protected]03b6d552012-03-29 04:03:011827 if (!map->SecurityOriginHasAPIPermission(
1828 source_origin,
1829 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061830 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011831 return false;
1832 }
1833
[email protected]7b54ca02012-03-02 18:06:531834 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1835 // return a recently installed Extension even if this CanCreateWindow call
1836 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011837 // because the permission check above would have caused an early return
1838 // already. We must use the full URL to find hosted apps, though, and not
1839 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531840 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351841 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291842 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011843 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191844 }
[email protected]056efdc2013-04-06 00:14:531845
1846 // No new browser window (popup or tab) in app mode.
1847 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1848 chrome::IsRunningInForcedAppMode()) {
1849 return false;
1850 }
1851
[email protected]9f3fba52011-06-08 20:37:191852 return true;
1853}
1854
1855std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201856 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1858 // Check if it's an extension-created worker, in which case we want to use
1859 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201860 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191861 const Extension* extension =
1862 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1863 return extension ? extension->name() : std::string();
1864}
1865
[email protected]99907362012-01-11 05:41:401866void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1867 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171868}
1869
[email protected]7a06d282013-05-03 04:39:331870// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021871content::SpeechRecognitionManagerDelegate*
1872 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]3bd0aab2013-05-30 20:07:491873#if !defined(OS_ANDROID)
[email protected]c52b2892012-03-07 11:01:021874 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321875#else
[email protected]3bd0aab2013-05-30 20:07:491876 // TODO(janx): Implement speech::AndroidSpeechRecognitionManagerDelegate
1877 // (see crbug.com/222352).
[email protected]a03f2d32012-03-14 00:26:321878 return NULL;
1879#endif
[email protected]66cfec62012-02-24 17:57:511880}
1881
[email protected]ae6e9912011-07-27 01:18:281882net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1883 return g_browser_process->net_log();
1884}
1885
[email protected]32538d92011-08-25 00:09:231886AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1887 return new ChromeAccessTokenStore();
1888}
1889
[email protected]dbae6b02011-06-29 23:51:411890bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011891 return true;
[email protected]dbae6b02011-06-29 23:51:411892}
1893
[email protected]64d69de42012-02-06 00:19:541894void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321895 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061896 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581897 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061898 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061899
[email protected]f3986f82012-01-03 20:00:061900 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541901 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061902 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541903 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061904 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541905 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061906 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541907 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061908 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541909 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061910 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541911 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031912 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1913 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061914
[email protected]64d69de42012-02-06 00:19:541915 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401916 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541917 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401918 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541919 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401920 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541921 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401922 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061923
[email protected]ddf72142012-05-22 04:52:401924 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061925
[email protected]64d69de42012-02-06 00:19:541926 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401927 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541928 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061929 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541930 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061931 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1932 const DictionaryValue* inspector_settings =
1933 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1934 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181935 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1936 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061937 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181938 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541939 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181940 std::make_pair(iter.key(), value));
1941 }
[email protected]f3986f82012-01-03 20:00:061942 }
1943 }
[email protected]64d69de42012-02-06 00:19:541944 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061945
[email protected]ddf72142012-05-22 04:52:401946 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541947 web_prefs->javascript_enabled = false;
1948 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1949 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401950 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541951 web_prefs->plugins_enabled = false;
1952 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1953 web_prefs->java_enabled = false;
1954 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401955 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061956
[email protected]64d69de42012-02-06 00:19:541957 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1958 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061959
[email protected]64d69de42012-02-06 00:19:541960 web_prefs->memory_info_enabled =
1961 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1962 web_prefs->allow_displaying_insecure_content =
1963 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1964 web_prefs->allow_running_insecure_content =
1965 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321966#if defined(OS_ANDROID)
1967 web_prefs->font_scale_factor =
1968 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1969 web_prefs->force_enable_zoom =
1970 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451971#if defined(GOOGLE_TV)
1972 web_prefs->user_gesture_required_for_media_playback = false;
1973#endif
[email protected]d3b935f2012-10-19 23:14:321974#endif
[email protected]5c915252013-05-07 13:15:391975
[email protected]af4256d52013-06-04 20:39:071976#if defined(OS_ANDROID)
1977 web_prefs->password_echo_enabled =
1978 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
1979#else
[email protected]9d06d88d2012-02-23 22:37:081980 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:071981#endif
1982
[email protected]5c915252013-05-07 13:15:391983#if defined(OS_CHROMEOS)
1984 // Enable password echo during OOBE when keyboard driven flag is set.
1985 if (chromeos::UserManager::IsInitialized() &&
1986 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
1987 !chromeos::StartupUtils::IsOobeCompleted()) {
1988 bool keyboard_driven_oobe = false;
1989 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]e8f3f9982013-05-10 20:59:531990 chromeos::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:391991 if (keyboard_driven_oobe)
1992 web_prefs->password_echo_enabled = true;
1993 }
1994#endif
[email protected]f3986f82012-01-03 20:00:061995
[email protected]46f8e742013-05-03 18:37:141996#if defined(OS_ANDROID)
1997 web_prefs->user_style_sheet_enabled = false;
1998#else
[email protected]64d69de42012-02-06 00:19:541999 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152000 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362001 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152002 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542003 web_prefs->user_style_sheet_enabled = true;
2004 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152005 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542006 } else {
2007 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062008 }
[email protected]46f8e742013-05-03 18:37:142009#endif
[email protected]f3986f82012-01-03 20:00:062010
[email protected]cfadadd2013-04-03 04:43:022011 web_prefs->asynchronous_spell_checking_enabled = true;
2012 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572013
[email protected]64d69de42012-02-06 00:19:542014 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062015 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542016 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062017 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542018 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062019 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2020
2021 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542022 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062023 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542024 web_prefs->default_encoding);
2025 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402026 prefs->ClearPref(prefs::kDefaultCharset);
2027 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062028 }
[email protected]64d69de42012-02-06 00:19:542029 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062030
[email protected]88ecf66d2012-12-11 22:53:472031 if (content::IsForceCompositingModeEnabled())
2032 web_prefs->force_compositing_mode = true;
2033
[email protected]299d7f12012-05-23 05:31:152034 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232035 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132036 ExtensionService* service =
2037 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062038 if (service) {
[email protected]1bc28312012-11-08 08:31:532039 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2040 const Extension* extension = service->extensions()->GetByID(url.host());
2041 // Ensure that we are only granting extension preferences to URLs with
2042 // the correct scheme. Without this check, chrome-guest:// schemes used by
2043 // webview tags as well as hosts that happen to match the id of an
2044 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422045 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532046 extension_webkit_preferences::SetPreferences(
2047 extension, view_type, web_prefs);
2048 }
[email protected]f3986f82012-01-03 20:00:062049 }
2050
[email protected]cb2edf22013-04-01 20:25:232051 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542052 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232053 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062054 // Disable all kinds of acceleration for background pages.
2055 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542056 web_prefs->force_compositing_mode = false;
2057 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062058 }
[email protected]2e21fe292012-03-02 22:52:322059
2060#if defined(FILE_MANAGER_EXTENSION)
2061 // Override the default of suppressing HW compositing for WebUI pages for the
2062 // file manager, which is implemented using WebUI but wants HW acceleration
2063 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532064 if (url.SchemeIs(extensions::kExtensionScheme) &&
2065 url.host() == kFileBrowserDomain) {
[email protected]2e21fe292012-03-02 22:52:322066 web_prefs->accelerated_compositing_enabled = true;
2067 web_prefs->accelerated_2d_canvas_enabled = true;
2068 }
2069#endif
[email protected]181a95ee2011-07-12 19:26:362070}
2071
2072void ChromeContentBrowserClient::UpdateInspectorSetting(
2073 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062074 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582075 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062076 DictionaryPrefUpdate update(
2077 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2078 prefs::kWebKitInspectorSettings);
2079 DictionaryValue* inspector_settings = update.Get();
2080 inspector_settings->SetWithoutPathExpansion(key,
2081 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362082}
2083
[email protected]b8148ac2011-07-13 22:03:252084void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2085 BrowserURLHandler* handler) {
2086 // Add the default URL handlers.
2087 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2088 BrowserURLHandler::null_handler());
2089 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2090 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2091
[email protected]b3adbd02011-11-30 22:23:272092 // about: handler. Must come before chrome: handler, since it will
2093 // rewrite about: urls to chrome: URLs and then expect chrome: to
2094 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252095 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2096 BrowserURLHandler::null_handler());
2097 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242098 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252099}
2100
2101void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372102 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582103 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472104 BrowsingDataRemover* remover =
2105 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552106 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2107 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252108 // BrowsingDataRemover takes care of deleting itself when done.
2109}
2110
2111void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372112 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582113 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472114 BrowsingDataRemover* remover =
2115 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232116 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552117 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252118 // BrowsingDataRemover takes care of deleting itself when done.
2119}
2120
[email protected]650b2d52013-02-10 03:41:452121base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322122 return download_util::GetDefaultDownloadDirectory();
2123}
2124
[email protected]c9b6eb62011-10-18 20:49:392125std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2126 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2127}
2128
[email protected]b7631cc2012-09-15 05:08:382129void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2130 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542131#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382132 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2133 scoped_ptr<ppapi::host::HostFactory>(
2134 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542135#endif
[email protected]b7631cc2012-09-15 05:08:382136}
2137
[email protected]0c7193742012-11-07 19:05:032138content::BrowserPpapiHost*
2139 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2140 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132141 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032142 while (!iter.Done()) {
2143 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2144 if (host->process() &&
2145 host->process()->GetData().id == plugin_process_id) {
2146 // Found the plugin.
2147 return host->browser_ppapi_host();
2148 }
2149 ++iter;
2150 }
2151 return NULL;
2152}
2153
[email protected]7b38b192013-03-23 18:39:312154bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2155 content::BrowserContext* browser_context, const GURL& site_url) {
2156 if (CommandLine::ForCurrentProcess()->HasSwitch(
2157 switches::kEnableBrowserPluginForAllViewTypes))
2158 return true;
2159
2160 Profile* profile = Profile::FromBrowserContext(browser_context);
2161 ExtensionService* service =
2162 extensions::ExtensionSystem::Get(profile)->extension_service();
2163 if (!service)
2164 return false;
2165
2166 const Extension* extension = service->extensions()->
2167 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2168 if (!extension)
2169 return false;
2170
[email protected]c2d2f102013-04-29 16:42:582171 return extension->HasAPIPermission(APIPermission::kWebView) ||
2172 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312173}
2174
[email protected]38cd8f7f2012-06-15 22:06:072175bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582176 content::BrowserContext* browser_context,
2177 const GURL& url,
[email protected]dda54822013-06-15 01:26:392178 bool private_api,
[email protected]157cc902012-11-02 06:31:582179 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402180#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372181 Profile* profile = Profile::FromBrowserContext(browser_context);
2182 const ExtensionSet* extension_set = NULL;
2183 if (profile) {
2184 extension_set = extensions::ExtensionSystem::Get(profile)->
2185 extension_service()->extensions();
2186 }
[email protected]dda54822013-06-15 01:26:392187
2188 if (private_api) {
2189 // Access to private socket APIs is controlled by the whitelist.
2190 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2191 allowed_socket_origins_)) {
2192 return true;
2193 }
2194 } else {
2195 // Access to public socket APIs is controlled by extension permissions.
2196 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2197 extension_set) {
2198 const Extension* extension = extension_set->GetByID(url.host());
2199 if (extension) {
2200 extensions::SocketPermission::CheckParam check_params(
2201 params.type, params.host, params.port);
2202 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2203 extension, extensions::APIPermission::kSocket, &check_params)) {
2204 return true;
2205 }
2206 }
2207 }
2208 }
2209
2210 // Allow both public and private APIs if the command line says so.
2211 return IsHostAllowedByCommandLine(url, extension_set,
2212 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402213#else
[email protected]a658d452012-03-02 12:45:292214 return false;
[email protected]93f72062013-05-29 20:29:402215#endif
[email protected]e461da2f2012-02-16 19:06:402216}
2217
[email protected]650b2d52013-02-10 03:41:452218base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2219 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142220 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2221 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2222}
2223
[email protected]a28e3302013-02-03 03:50:432224ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2225 WebContents* web_contents) {
2226 return new ChromeSelectFilePolicy(web_contents);
2227}
2228
[email protected]7d9424702013-04-14 13:14:162229void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2230 std::vector<std::string>* additional_allowed_schemes) {
2231 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2232 additional_allowed_schemes);
2233 additional_allowed_schemes->push_back(kChromeUIScheme);
2234 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2235}
2236
[email protected]02250952013-04-24 23:52:532237void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2238 const base::FilePath& storage_partition_path,
2239 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2240#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032241 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]02250952013-04-24 23:52:532242 additional_providers->push_back(new MediaFileSystemMountPointProvider(
[email protected]30a306f42013-06-10 03:09:032243 storage_partition_path,
2244 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]e66f02632013-06-13 22:51:502245 MediaFileSystemMountPointProvider::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532246#endif
2247}
2248
[email protected]e60c0232011-11-11 19:56:352249#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182250void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2251 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382252 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082253 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392254#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452255 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392256 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2257 DCHECK(!data_path.empty());
2258
2259 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452260 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392261 base::PlatformFile f =
2262 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2263 DCHECK(f != base::kInvalidPlatformFileValue);
2264 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2265 FileDescriptor(f, true)));
2266
[email protected]650b2d52013-02-10 03:41:452267 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392268 data_path.AppendASCII("chrome_100_percent.pak");
2269 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2270 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372271 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392272 FileDescriptor(f, true)));
2273
2274 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452275 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392276 GetLocaleFilePath(locale, false);
2277 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2278 DCHECK(f != base::kInvalidPlatformFileValue);
2279 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2280 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382281
[email protected]650b2d52013-02-10 03:41:452282 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372283 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2284 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2285 DCHECK(f != base::kInvalidPlatformFileValue);
2286 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2287 FileDescriptor(f, true)));
2288
[email protected]40da3e0c2012-10-24 22:03:382289#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432290 if (IsCrashReporterEnabled()) {
2291 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2292 if (f == base::kInvalidPlatformFileValue) {
2293 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2294 "be disabled for this process.";
2295 } else {
2296 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2297 FileDescriptor(f, true)));
2298 }
[email protected]40da3e0c2012-10-24 22:03:382299 }
2300#endif // defined(USE_LINUX_BREAKPAD)
2301
2302#else
2303 int crash_signal_fd = GetCrashSignalFD(command_line);
2304 if (crash_signal_fd >= 0) {
2305 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2306 FileDescriptor(crash_signal_fd,
2307 false)));
2308 }
[email protected]29699c22012-10-03 23:57:392309#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302310}
[email protected]e60c0232011-11-11 19:56:352311#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302312
[email protected]4a65826d2011-08-25 16:04:012313#if defined(OS_WIN)
2314const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2315 return chrome::kBrowserResourcesDll;
2316}
[email protected]34f48682013-03-20 00:30:182317
2318void ChromeContentBrowserClient::PreSpawnRenderer(
2319 sandbox::TargetPolicy* policy,
2320 bool* success) {
2321 // This code is duplicated in nacl_exe_win_64.cc.
2322 // Allow the server side of a pipe restricted to the "chrome.nacl."
2323 // namespace so that it cannot impersonate other system or other chrome
2324 // service pipes.
2325 sandbox::ResultCode result = policy->AddRule(
2326 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2327 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2328 L"\\\\.\\pipe\\chrome.nacl.*");
2329 if (result != sandbox::SBOX_ALL_OK) {
2330 *success = false;
2331 return;
2332 }
2333
2334 // Renderers need to send named pipe handles and shared memory
2335 // segment handles to NaCl loader processes.
2336 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2337 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2338 L"File");
2339 if (result != sandbox::SBOX_ALL_OK) {
2340 *success = false;
2341 return;
2342 }
2343}
[email protected]4a65826d2011-08-25 16:04:012344#endif
2345
[email protected]37a72af2011-06-13 05:42:012346#if defined(USE_NSS)
2347crypto::CryptoModuleBlockingPasswordDelegate*
2348 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2349 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292350 return chrome::NewCryptoModuleBlockingDialogDelegate(
2351 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012352}
2353#endif
2354
[email protected]d977f9c2011-03-14 16:10:262355} // namespace chrome