blob: f6c95e4b033ac80c97b509baa084e5108c01d13f [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]eabbfb12013-04-05 23:28:3513#include "base/lazy_instance.h"
[email protected]29699c22012-10-03 23:57:3914#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5715#include "base/prefs/pref_service.h"
[email protected]e7463412013-06-10 22:53:4616#include "base/strings/string_number_conversions.h"
[email protected]135cb802013-06-09 16:44:2017#include "base/strings/utf_string_conversions.h"
[email protected]30a306f42013-06-10 03:09:0318#include "base/threading/sequenced_worker_pool.h"
[email protected]b80f68432011-05-02 17:22:3019#include "chrome/app/breakpad_mac.h"
[email protected]056efdc2013-04-06 00:14:5320#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]b8148ac2011-07-13 22:03:2521#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3022#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4723#include "chrome/browser/browsing_data/browsing_data_helper.h"
24#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1225#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4126#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4127#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5628#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0529#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4530#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3231#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0832#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3233#include "chrome/browser/download/download_util.h"
[email protected]17263b22013-05-16 03:29:2234#include "chrome/browser/extensions/activity_log/activity_log.h"
[email protected]2b33dcd02012-03-18 01:34:1635#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]1deace22013-05-22 06:14:4636#include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
[email protected]76411f412012-02-22 18:56:0637#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0438#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3339#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2640#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0841#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2542#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0643#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5244#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2345#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1246#include "chrome/browser/google/google_util.h"
[email protected]11158e2d2013-02-01 02:31:5647#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0448#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]0c7193742012-11-07 19:05:0349#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2850#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0451#include "chrome/browser/notifications/desktop_notification_service.h"
52#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]93f72062013-05-29 20:29:4053#include "chrome/browser/pepper_permission_util.h"
[email protected]0609b17f2011-05-31 20:13:4254#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5655#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0656#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4157#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5058#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0759#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4160#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1461#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0362#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1463#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3264#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0665#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1466#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3867#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4368#include "chrome/browser/search/instant_service.h"
69#include "chrome/browser/search/instant_service_factory.h"
70#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1471#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0272#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3373#include "chrome/browser/speech/tts_message_filter.h"
[email protected]8ec71262011-07-28 08:12:4674#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5875#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0376#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5277#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4578#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5479#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4380#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]b5d73422012-06-02 23:46:4481#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5082#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]970c63e2013-03-07 00:25:3083#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
[email protected]f3986f82012-01-03 20:00:0684#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1585#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2786#include "chrome/browser/validation_message_message_filter.h"
[email protected]db9f2142013-05-27 22:56:1687#include "chrome/browser/webview/webview_guest.h"
[email protected]b80f68432011-05-02 17:22:3088#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0189#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1490#include "chrome/common/chrome_paths.h"
[email protected]f3b357692013-03-22 05:16:1391#include "chrome/common/chrome_process_type.h"
[email protected]b80f68432011-05-02 17:22:3092#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2993#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0494#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3895#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4496#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4397#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:2998#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]157cc902012-11-02 06:31:5899#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:34100#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:12101#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38102#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09103#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53104#include "chromeos/chromeos_constants.h"
[email protected]75fee372013-03-06 00:42:44105#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43106#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30107#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38108#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03109#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31110#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03111#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59112#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36113#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30114#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33115#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05116#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33117#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19118#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10119#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43120#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18121#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23122#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42123#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39124#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23125#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53126#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58127#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34128#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06129#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57130#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38131#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39132#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08133#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24134#include "ui/message_center/message_center_util.h"
[email protected]fab55e72013-05-31 07:06:18135#include "webkit/common/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04136#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26137
[email protected]b48c9182011-10-26 18:03:30138#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38139#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18140#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38141#elif defined(OS_MACOSX)
142#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56143#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30144#elif defined(OS_CHROMEOS)
145#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]5c915252013-05-07 13:15:39146#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49147#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]5c915252013-05-07 13:15:39148#include "chrome/browser/chromeos/system/statistics_provider.h"
[email protected]931d1042013-04-05 17:50:44149#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26150#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30151#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09152#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38153#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09154#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39155#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30156#elif defined(OS_POSIX)
157#include "chrome/browser/chrome_browser_main_posix.h"
158#endif
159
[email protected]6653c192012-04-10 22:52:44160#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30161#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12162#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43163#endif
[email protected]b80f68432011-05-02 17:22:30164
[email protected]1e87df32012-09-12 04:53:19165#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
166#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
167#endif
168
[email protected]29699c22012-10-03 23:57:39169#if defined(OS_ANDROID)
170#include "ui/base/ui_base_paths.h"
171#endif
172
[email protected]37a72af2011-06-13 05:42:01173#if defined(USE_NSS)
174#include "chrome/browser/ui/crypto_module_password_dialog.h"
175#endif
176
[email protected]d5bcd06f2013-04-21 08:07:24177#if !defined(OS_CHROMEOS)
178#include "chrome/browser/signin/signin_manager.h"
179#include "chrome/browser/signin/signin_manager_factory.h"
180#endif
181
[email protected]02250952013-04-24 23:52:53182#if !defined(OS_ANDROID)
183#include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h"
184#endif
185
[email protected]6ef98b5a2013-05-31 23:58:31186#if defined(ENABLE_WEBRTC)
187#include "chrome/browser/media/webrtc_logging_handler_host.h"
188#endif
189
[email protected]02a3dc122013-06-13 15:07:53190#if defined(FILE_MANAGER_EXTENSION)
191#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
192#endif
193
[email protected]c7abd422012-09-25 00:20:08194using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47195using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03196using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39197using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31198using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59199using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08200using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00201using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11202using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33203using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13204using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06205using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34206using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40207using extensions::Manifest;
[email protected]631bb742011-11-02 11:29:39208
[email protected]c5dbef02011-05-13 05:06:09209namespace {
210
[email protected]eabbfb12013-04-05 23:28:35211// Cached version of the locale so we can return the locale on the I/O
212// thread.
213base::LazyInstance<std::string> g_io_thread_application_locale;
214
[email protected]93f72062013-05-29 20:29:40215#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40216const char* kPredefinedAllowedSocketOrigins[] = {
217 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18218 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45219 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
220 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
221 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
222 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35223 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54224 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
225 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
226 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
227 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
228 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
229 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38230 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58231 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29232 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
233 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
234 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
235 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
236 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40237};
[email protected]93f72062013-05-29 20:29:40238#endif
[email protected]e461da2f2012-02-16 19:06:40239
[email protected]f8f93eb2012-09-25 03:06:24240// Returns a copy of the given url with its host set to given host and path set
241// to given path. Other parts of the url will be the same.
242GURL ReplaceURLHostAndPath(const GURL& url,
243 const std::string& host,
244 const std::string& path) {
245 url_canon::Replacements<char> replacements;
246 replacements.SetHost(host.c_str(),
247 url_parse::Component(0, host.length()));
248 replacements.SetPath(path.c_str(),
249 url_parse::Component(0, path.length()));
250 return url.ReplaceComponents(replacements);
251}
252
253// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
254GURL AddUberHost(const GURL& url) {
255 const std::string uber_host = chrome::kChromeUIUberHost;
256 const std::string new_path = url.host() + url.path();
257
258 return ReplaceURLHostAndPath(url, uber_host, new_path);
259}
260
[email protected]045bf7c2012-09-28 20:27:36261// If url->host() is "chrome" and url->path() has characters other than the
262// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
263// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24264bool RemoveUberHost(GURL* url) {
265 if (url->host() != chrome::kChromeUIUberHost)
266 return false;
267
[email protected]045bf7c2012-09-28 20:27:36268 if (url->path().empty() || url->path() == "/")
269 return false;
270
[email protected]f8f93eb2012-09-25 03:06:24271 const std::string old_path = url->path();
272
273 const std::string::size_type separator = old_path.find('/', 1);
274 std::string new_host;
275 std::string new_path;
276 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36277 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24278 } else {
279 new_host = old_path.substr(1, separator - 1);
280 new_path = old_path.substr(separator);
281 }
282
[email protected]44e8add2013-06-13 17:29:15283 // Do not allow URLs with paths empty before the first slash since we can't
284 // have an empty host. (e.g "foo://chrome//")
285 if (new_host.empty())
286 return false;
287
[email protected]f8f93eb2012-09-25 03:06:24288 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
289
[email protected]44e8add2013-06-13 17:29:15290 DCHECK(url->is_valid());
291
[email protected]f8f93eb2012-09-25 03:06:24292 return true;
293}
294
[email protected]b8148ac2011-07-13 22:03:25295// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42296bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24297 // Do not handle special URLs such as "about:foo"
298 if (!url->host().empty()) {
299 const GURL chrome_url = AddUberHost(*url);
300
301 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
302 // be called.
303 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
304 browser_context, chrome_url))
305 return true;
306 }
307
[email protected]863f70a2012-01-27 02:05:50308 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
309 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25310 return false;
311
[email protected]fe69558d2012-03-12 11:34:49312#if defined(OS_CHROMEOS)
313 // Special case : in ChromeOS in Guest mode bookmarks and history are
314 // disabled for security reasons. New tab page explains the reasons, so
315 // we redirect user to new tab page.
316 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
317 if (url->SchemeIs(chrome::kChromeUIScheme) &&
318 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
319 url->DomainIs(chrome::kChromeUIHistoryHost))) {
320 // Rewrite with new tab URL
321 *url = GURL(chrome::kChromeUINewTabURL);
322 }
323 }
324#endif
325
[email protected]b8148ac2011-07-13 22:03:25326 // Special case the new tab page. In older versions of Chrome, the new tab
327 // page was hosted at chrome-internal:<blah>. This might be in people's saved
328 // sessions or bookmarks, so we say any URL with that scheme triggers the new
329 // tab page.
330 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
331 // Rewrite it with the proper new tab URL.
332 *url = GURL(chrome::kChromeUINewTabURL);
333 }
334
335 return true;
336}
337
[email protected]f8f93eb2012-09-25 03:06:24338// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
339// "chrome://foo/".
340bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
341 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
342 return false;
343
344 return RemoveUberHost(url);
345}
346
[email protected]8d3132f62011-10-12 07:13:42347// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
348// below. Extension, and isolated apps require different privileges to be
349// granted to their RenderProcessHosts. This classification allows us to make
350// sure URLs are served by hosts with the right set of privileges.
351enum RenderProcessHostPrivilege {
352 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45353 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42354 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45355 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42356};
357
358RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
359 const GURL& url,
360 ExtensionService* service) {
361 // Default to a normal renderer cause it is lower privileged. This should only
362 // occur if the URL on a site instance is either malformed, or uninitialized.
363 // If it is malformed, then there is no need for better privileges anyways.
364 // If it is uninitialized, but eventually settles on being an a scheme other
365 // than normal webrenderer, the navigation logic will correct us out of band
366 // anyways.
367 if (!url.is_valid())
368 return PRIV_NORMAL;
369
[email protected]885c0e92012-11-13 20:27:42370 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44371 const Extension* extension =
372 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43373 if (extension &&
374 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42375 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45376 if (extension && extension->is_hosted_app())
377 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42378
379 return PRIV_EXTENSION;
380 }
381
382 return PRIV_NORMAL;
383}
384
385RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30386 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46387 extensions::ProcessMap* process_map,
388 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46389 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30390 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46391 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21392 return PRIV_NORMAL;
393
[email protected]6f371442011-11-09 06:45:46394 for (std::set<std::string>::iterator iter = extension_ids.begin();
395 iter != extension_ids.end(); ++iter) {
396 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43397 if (extension &&
398 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42399 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45400 if (extension && extension->is_hosted_app())
401 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42402 }
403
[email protected]676f6ab2011-10-19 20:23:21404 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42405}
406
[email protected]6786bf402011-12-03 15:19:45407bool CertMatchesFilter(const net::X509Certificate& cert,
408 const base::DictionaryValue& filter) {
409 // TODO(markusheintz): This is the minimal required filter implementation.
410 // Implement a better matcher.
411
412 // An empty filter matches any client certificate since no requirements are
413 // specified at all.
414 if (filter.empty())
415 return true;
416
417 std::string common_name;
418 if (filter.GetString("ISSUER.CN", &common_name) &&
419 (cert.issuer().common_name == common_name)) {
420 return true;
421 }
422 return false;
423}
424
[email protected]f3986f82012-01-03 20:00:06425// Fills |map| with the per-script font prefs under path |map_name|.
426void FillFontFamilyMap(const PrefService* prefs,
427 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53428 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06429 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
430 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
431 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
432 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23433 if (!font_family.empty())
434 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06435 }
436}
437
[email protected]a1733df2012-06-22 11:24:18438#if defined(OS_POSIX) && !defined(OS_MACOSX)
439int GetCrashSignalFD(const CommandLine& command_line) {
440 if (command_line.HasSwitch(switches::kExtensionProcess)) {
441 ExtensionCrashHandlerHostLinux* crash_handler =
442 ExtensionCrashHandlerHostLinux::GetInstance();
443 return crash_handler->GetDeathSignalSocket();
444 }
445
446 std::string process_type =
447 command_line.GetSwitchValueASCII(switches::kProcessType);
448
449 if (process_type == switches::kRendererProcess)
450 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
451
452 if (process_type == switches::kPluginProcess)
453 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
454
455 if (process_type == switches::kPpapiPluginProcess)
456 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
457
458 if (process_type == switches::kGpuProcess)
459 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
460
461 return -1;
462}
463#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
464
[email protected]d5bcd06f2013-04-21 08:07:24465#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30466GURL GetEffectiveURLForSignin(const GURL& url) {
467 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
468
469 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03470 // Copy the path because the argument to SetPathStr must outlive
471 // the Replacements object.
472 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30473 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03474 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30475 effective_url = effective_url.ReplaceComponents(replacements);
476 return effective_url;
477}
[email protected]d5bcd06f2013-04-21 08:07:24478#endif
[email protected]970c63e2013-03-07 00:25:30479
[email protected]eabbfb12013-04-05 23:28:35480void SetApplicationLocaleOnIOThread(const std::string& locale) {
481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
482 g_io_thread_application_locale.Get() = locale;
483}
484
[email protected]9dbfff12011-07-01 19:37:07485} // namespace
[email protected]c5dbef02011-05-13 05:06:09486
[email protected]d977f9c2011-03-14 16:10:26487namespace chrome {
488
[email protected]e461da2f2012-02-16 19:06:40489ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40490#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40491 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
492 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40493#endif
[email protected]1deace22013-05-22 06:14:46494
495 permissions_policy_delegate_.reset(
496 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40497}
498
499ChromeContentBrowserClient::~ChromeContentBrowserClient() {
500}
501
[email protected]bca18382012-06-25 19:15:23502// static
[email protected]c753f142013-02-10 13:14:04503void ChromeContentBrowserClient::RegisterUserPrefs(
[email protected]443e9312013-05-06 06:17:34504 user_prefs::PrefRegistrySyncable* registry) {
505 registry->RegisterBooleanPref(
506 prefs::kDisable3DAPIs,
507 false,
508 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
509 registry->RegisterBooleanPref(
510 prefs::kEnableHyperlinkAuditing,
511 true,
512 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
513 registry->RegisterBooleanPref(
514 prefs::kEnableMemoryInfo,
515 false,
516 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23517}
518
[email protected]eabbfb12013-04-05 23:28:35519// static
520void ChromeContentBrowserClient::SetApplicationLocale(
521 const std::string& locale) {
522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
523
524 // This object is guaranteed to outlive all threads so we don't have to
525 // worry about the lack of refcounting and can just post as Unretained.
526 //
527 // The common case is that this function is called early in Chrome startup
528 // before any threads are created (it will also be called later if the user
529 // changes the pref). In this case, there will be no threads created and
530 // posting will fail. When there are no threads, we can just set the string
531 // without worrying about threadsafety.
532 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
533 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
534 g_io_thread_application_locale.Get() = locale;
535 }
536}
537
[email protected]50462bf02011-11-21 19:13:31538content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
539 const content::MainFunctionParams& parameters) {
540 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30541 // Construct the Main browser parts based on the OS type.
542#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31543 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04544#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31545 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30546#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22547 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26548#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31549 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14550#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09551 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30552#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31553 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04554#else
[email protected]b48c9182011-10-26 18:03:30555 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31556 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30557#endif
558
[email protected]7e75e4a2013-05-17 17:20:03559 chrome::AddProfilesExtraParts(main_parts);
560
[email protected]c7480942011-11-08 19:18:27561 // Construct additional browser parts. Stages are called in the order in
562 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22563#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41564 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04565#endif
[email protected]c7480942011-11-08 19:18:27566
567#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41568 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27569#endif
570
[email protected]dc04be7c2012-03-15 23:57:49571#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41572 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49573#endif
574
[email protected]e050ef142012-03-21 01:04:24575#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41576 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24577#endif
578
[email protected]95132f52013-04-12 02:19:04579 chrome::AddMetricsExtraParts(main_parts);
580
[email protected]50462bf02011-11-21 19:13:31581 return main_parts;
[email protected]f967b722011-09-07 00:58:04582}
583
[email protected]e94bbcb2012-09-07 05:33:57584std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19585 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57586 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53587 std::string partition_id;
588
589 // The partition ID for webview guest processes is the string value of its
590 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
591 if (site.SchemeIs(chrome::kGuestScheme))
592 partition_id = site.spec();
593
[email protected]056efdc2013-04-06 00:14:53594 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53595 return partition_id;
596}
597
598bool ChromeContentBrowserClient::IsValidStoragePartitionId(
599 content::BrowserContext* browser_context,
600 const std::string& partition_id) {
601 // The default ID is empty and is always valid.
602 if (partition_id.empty())
603 return true;
604
605 return GURL(partition_id).is_valid();
606}
607
608void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
609 content::BrowserContext* browser_context,
610 const GURL& site,
[email protected]14acc642012-11-17 12:20:10611 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53612 std::string* partition_domain,
613 std::string* partition_name,
614 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10615 // Default to the browser-wide storage partition and override based on |site|
616 // below.
617 partition_domain->clear();
618 partition_name->clear();
619 *in_memory = false;
620
[email protected]1bc28312012-11-08 08:31:53621 // For the webview tag, we create special guest processes, which host the
622 // tag content separately from the main application that embeds the tag.
623 // A webview tag can specify both the partition name and whether the storage
624 // for that partition should be persisted. Each tag gets a SiteInstance with
625 // a specially formatted URL, based on the application it is hosted by and
626 // the partition requested by it. The format for that URL is:
627 // chrome-guest://partition_domain/persist?partition_name
628 if (site.SchemeIs(chrome::kGuestScheme)) {
629 // Since guest URLs are only used for packaged apps, there must be an app
630 // id in the URL.
631 CHECK(site.has_host());
632 *partition_domain = site.host();
633 // Since persistence is optional, the path must either be empty or the
634 // literal string.
635 *in_memory = (site.path() != "/persist");
636 // The partition name is user supplied value, which we have encoded when the
637 // URL was created, so it needs to be decoded.
638 *partition_name = net::UnescapeURLComponent(site.query(),
639 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10640 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
641 // If |can_be_default| is false, the caller is stating that the |site|
642 // should be parsed as if it had isolated storage. In particular it is
643 // important to NOT check ExtensionService for the is_storage_isolated()
644 // attribute because this code path is run during Extension uninstall
645 // to do cleanup after the Extension has already been unloaded from the
646 // ExtensionService.
647 bool is_isolated = !can_be_default;
648 if (can_be_default) {
649 const Extension* extension = NULL;
650 Profile* profile = Profile::FromBrowserContext(browser_context);
651 ExtensionService* extension_service =
652 extensions::ExtensionSystem::Get(profile)->extension_service();
653 if (extension_service) {
654 extension = extension_service->extensions()->
655 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43656 if (extension &&
657 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10658 is_isolated = true;
659 }
660 }
661 }
[email protected]1bc28312012-11-08 08:31:53662
[email protected]14acc642012-11-17 12:20:10663 if (is_isolated) {
664 CHECK(site.has_host());
665 // For extensions with isolated storage, the the host of the |site| is
666 // the |partition_domain|. The |in_memory| and |partition_name| are only
667 // used in guest schemes so they are cleared here.
668 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53669 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10670 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53671 }
[email protected]d1198fd2012-08-13 22:50:19672 }
673
[email protected]14acc642012-11-17 12:20:10674 // Assert that if |can_be_default| is false, the code above must have found a
675 // non-default partition. If this fails, the caller has a serious logic
676 // error about which StoragePartition they expect to be in and it is not
677 // safe to continue.
678 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44679}
680
[email protected]38b098f2012-03-14 21:11:57681content::WebContentsViewDelegate*
682 ChromeContentBrowserClient::GetWebContentsViewDelegate(
683 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27684 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32685}
686
[email protected]24665682013-02-25 20:59:38687// Check if the extension activity log is enabled for the profile.
688static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33689 // crbug.com/247908 - This should be IsLogEnabled except for an issue
690 // in chrome_frame_net_tests
691 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38692}
693
[email protected]44295a12013-06-05 08:45:46694void ChromeContentBrowserClient::GuestWebContentsAttached(
695 WebContents* guest_web_contents,
696 WebContents* embedder_web_contents,
697 int browser_plugin_instance_id) {
[email protected]44703cc72013-01-24 04:56:06698 Profile* profile = Profile::FromBrowserContext(
699 embedder_web_contents->GetBrowserContext());
700 ExtensionService* service =
701 extensions::ExtensionSystem::Get(profile)->extension_service();
702 if (!service)
703 return;
704 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
705 const Extension* extension = service->extensions()->
706 GetExtensionOrAppByURL(ExtensionURLInfo(url));
707 if (!extension)
708 return;
709 std::vector<ExtensionMsg_Loaded_Params> extensions;
710 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
711 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
[email protected]44295a12013-06-05 08:45:46712 new WebViewGuest(guest_web_contents,
713 embedder_web_contents,
714 extension->id(),
715 browser_plugin_instance_id);
[email protected]44703cc72013-01-24 04:56:06716}
717
[email protected]f3b1a082011-11-18 00:34:30718void ChromeContentBrowserClient::RenderProcessHostCreated(
719 content::RenderProcessHost* host) {
720 int id = host->GetID();
721 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41722 net::URLRequestContextGetter* context =
723 profile->GetRequestContextForRenderProcess(id);
724
[email protected]f3b1a082011-11-18 00:34:30725 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41726 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55727#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30728 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55729#endif
[email protected]658677f2012-06-09 06:04:02730#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08731 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03732#endif
[email protected]f3b1a082011-11-18 00:34:30733 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02734 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30735 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56736#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21737 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56738#endif
[email protected]43535512013-02-20 20:41:41739 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
740 id, profile, context));
[email protected]2736c032012-05-11 18:06:07741 host->GetChannel()->AddFilter(
742 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27743 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33744 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31745#if defined(ENABLE_WEBRTC)
746 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
747#endif
[email protected]3e69bc82011-05-26 23:22:38748
[email protected]2ccf45c2011-08-19 23:35:50749 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
750 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07751
[email protected]24665682013-02-25 20:59:38752 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
753 IsExtensionActivityLogEnabledForProfile(profile)));
754
[email protected]39a5b532011-10-22 01:47:07755 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56756
757 RendererContentSettingRules rules;
758 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
759 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14760}
761
[email protected]95c95552013-05-03 04:21:22762GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
763 content::BrowserContext* browser_context,
764 const GURL& url,
765 bool is_renderer_initiated,
766 content::SiteInstance* current_instance) {
767 Profile* profile = Profile::FromBrowserContext(browser_context);
768 if (!profile)
769 return url;
770
771 // Only return the privileged instant URL if we are entering from a browser-
772 // initiated navigation or if we are already in the instant process.
773 bool is_instant_process = false;
774 int process_id = current_instance->GetProcess()->GetID();
775 InstantService* instant_service =
776 InstantServiceFactory::GetForProfile(profile);
777 if (instant_service)
778 is_instant_process = instant_service->IsInstantProcess(process_id);
779
780 DCHECK_EQ(is_instant_process,
781 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
782 if (!is_renderer_initiated || is_instant_process) {
783 // If the input |url| should be assigned to the Instant renderer, make its
784 // privileged URL distinct from other URLs on the search provider's domain.
785 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
786 return chrome::GetPrivilegedURLForInstant(url, profile);
787 }
788
789 return url;
790}
791
[email protected]3d7474ff2011-07-27 17:47:37792GURL ChromeContentBrowserClient::GetEffectiveURL(
793 content::BrowserContext* browser_context, const GURL& url) {
794 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52795 if (!profile)
796 return url;
797
[email protected]d5bcd06f2013-04-21 08:07:24798#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30799 // If the input |url| should be assigned to the Signin renderer, make its
800 // effective URL distinct from other URLs on the signin service's domain.
801 // Note that the signin renderer will be allowed to sign the user in to
802 // Chrome.
803 if (SigninManager::IsWebBasedSigninFlowURL(url))
804 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24805#endif
[email protected]970c63e2013-03-07 00:25:30806
[email protected]c5dec6292013-01-25 04:54:52807 // If the input |url| is part of an installed app, the effective URL is an
808 // extension URL with the ID of that extension as the host. This has the
809 // effect of grouping apps together in a common SiteInstance.
810 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13811 extensions::ExtensionSystem::Get(profile)->extension_service();
812 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08813 return url;
814
[email protected]06bdd2b2012-11-30 18:47:13815 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44816 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08817 if (!extension)
818 return url;
819
[email protected]15877ca2011-11-18 22:40:52820 // Bookmark apps do not use the hosted app process model, and should be
821 // treated as normal URLs.
822 if (extension->from_bookmark())
823 return url;
824
[email protected]36fb2c7c2011-04-04 15:49:08825 // If the URL is part of an extension's web extent, convert it to an
826 // extension URL.
827 return extension->GetResourceURL(url.path());
828}
829
[email protected]056ad2a2011-07-12 02:13:55830bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37831 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52832 // Non-extension, non-Instant URLs should generally use
833 // process-per-site-instance. Because we expect to use the effective URL,
834 // URLs for hosted apps (apart from bookmark apps) should have an extension
835 // scheme by now.
836
837 Profile* profile = Profile::FromBrowserContext(browser_context);
838 if (!profile)
839 return false;
840
[email protected]165fe422013-03-27 06:34:03841 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52842 return true;
843
[email protected]d5bcd06f2013-04-21 08:07:24844#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30845 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
846 return true;
[email protected]d5bcd06f2013-04-21 08:07:24847#endif
[email protected]970c63e2013-03-07 00:25:30848
[email protected]885c0e92012-11-13 20:27:42849 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55850 return false;
851
[email protected]c5dec6292013-01-25 04:54:52852 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13853 extensions::ExtensionSystem::Get(profile)->extension_service();
854 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55855 return false;
856
[email protected]06bdd2b2012-11-30 18:47:13857 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44858 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55859 if (!extension)
860 return false;
861
862 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53863 // permission, or that does not allow JavaScript access to the background
864 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55865 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40866 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06867 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29868 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53869 return false;
870 }
871 }
[email protected]056ad2a2011-07-12 02:13:55872
[email protected]7b54ca02012-03-02 18:06:53873 // Hosted apps that have script access to their background page must use
874 // process per site, since all instances can make synchronous calls to the
875 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55876 return true;
877}
878
[email protected]672c8c12013-03-07 12:30:06879// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41880void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
881 std::vector<std::string>* additional_schemes) {
882 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06883}
884
[email protected]6bd30072013-02-08 18:17:11885net::URLRequestContextGetter*
886ChromeContentBrowserClient::CreateRequestContext(
887 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06888 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11889 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06890 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11891}
892
893net::URLRequestContextGetter*
894ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
895 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40896 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11897 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06898 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11899 Profile* profile = Profile::FromBrowserContext(browser_context);
900 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06901 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11902}
903
[email protected]46fb9442011-12-09 17:57:47904bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
905 return ProfileIOData::IsHandledURL(url);
906}
907
[email protected]c4365fa42013-05-14 01:08:24908bool ChromeContentBrowserClient::CanCommitURL(
909 content::RenderProcessHost* process_host,
910 const GURL& url) {
911 // We need to let most extension URLs commit in any process, since this can
912 // be allowed due to web_accessible_resources. Most hosted app URLs may also
913 // load in any process (e.g., in an iframe). However, the Chrome Web Store
914 // cannot be loaded in iframes and should never be requested outside its
915 // process.
916 Profile* profile =
917 Profile::FromBrowserContext(process_host->GetBrowserContext());
918 ExtensionService* service =
919 extensions::ExtensionSystem::Get(profile)->extension_service();
920 if (!service)
921 return true;
922 const Extension* new_extension =
923 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
924 if (new_extension &&
925 new_extension->is_hosted_app() &&
926 new_extension->id() == extension_misc::kWebStoreAppId &&
927 !service->process_map()->Contains(new_extension->id(),
928 process_host->GetID())) {
929 return false;
930 }
931
932 return true;
933}
934
[email protected]2a5221b2011-09-27 23:07:31935bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30936 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31937 const GURL& site_url) {
938 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30939 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52940 // This may be NULL during tests. In that case, just assume any site can
941 // share any host.
942 if (!profile)
943 return true;
944
[email protected]d43f99fe2013-04-03 00:20:14945 // Instant URLs should only be in the instant process and instant process
946 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52947 InstantService* instant_service =
948 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14949 if (instant_service) {
950 bool is_instant_process = instant_service->IsInstantProcess(
951 process_host->GetID());
952 bool should_be_in_instant_process =
953 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
954 if (is_instant_process || should_be_in_instant_process)
955 return is_instant_process && should_be_in_instant_process;
956 }
[email protected]c5dec6292013-01-25 04:54:52957
[email protected]d5bcd06f2013-04-21 08:07:24958#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30959 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
960 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
961 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:24962#endif
[email protected]970c63e2013-03-07 00:25:30963
[email protected]06bdd2b2012-11-30 18:47:13964 ExtensionService* service =
965 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46966 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31967
[email protected]ffa97602011-11-17 17:55:52968 // Don't allow the Task Manager to share a process with anything else.
969 // Otherwise it can affect the renderers it is observing.
970 // Note: we could create another RenderProcessHostPrivilege bucket for
971 // this to allow multiple chrome://tasks instances to share, but that's
972 // a very unlikely case without serious consequences.
973 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
974 return false;
975
[email protected]8d3132f62011-10-12 07:13:42976 // These may be NULL during tests. In that case, just assume any site can
977 // share any host.
[email protected]6f371442011-11-09 06:45:46978 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31979 return true;
980
[email protected]eec0b33c2011-12-05 22:09:45981 // Otherwise, just make sure the process privilege matches the privilege
982 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57983 RenderProcessHostPrivilege privilege_required =
984 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45985 return GetProcessPrivilege(process_host, process_map, service) ==
986 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31987}
988
[email protected]76411f412012-02-22 18:56:06989// This function is trying to limit the amount of processes used by extensions
990// with background pages. It uses a globally set percentage of processes to
991// run such extensions and if the limit is exceeded, it returns true, to
992// indicate to the content module to group extensions together.
993bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
994 content::BrowserContext* browser_context, const GURL& url) {
995 // It has to be a valid URL for us to check for an extension.
996 if (!url.is_valid())
997 return false;
998
999 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191000 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131001 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061002 if (!service)
1003 return false;
1004
1005 // We have to have a valid extension with background page to proceed.
1006 const Extension* extension =
1007 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
1008 if (!extension)
1009 return false;
[email protected]9367eabc2013-03-01 01:29:291010 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061011 return false;
1012
1013 std::set<int> process_ids;
1014 size_t max_process_count =
1015 content::RenderProcessHost::GetMaxRendererProcessCount();
1016
1017 // Go through all profiles to ensure we have total count of extension
1018 // processes containing background pages, otherwise one profile can
1019 // starve the other.
1020 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1021 GetLoadedProfiles();
1022 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031023 ExtensionProcessManager* epm =
1024 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321025 for (ExtensionProcessManager::const_iterator iter =
1026 epm->background_hosts().begin();
1027 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131028 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321029 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061030 }
1031 }
1032
1033 if (process_ids.size() >
1034 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1035 return true;
1036 }
1037
1038 return false;
1039}
1040
[email protected]6f371442011-11-09 06:45:461041void ChromeContentBrowserClient::SiteInstanceGotProcess(
1042 SiteInstance* site_instance) {
1043 CHECK(site_instance->HasProcess());
1044
1045 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021046 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521047 if (!profile)
1048 return;
1049
1050 // Remember the ID of the Instant process to signal the renderer process
1051 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031052 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321053 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521054 InstantService* instant_service =
1055 InstantServiceFactory::GetForProfile(profile);
1056 if (instant_service)
1057 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1058 }
1059
[email protected]d5bcd06f2013-04-21 08:07:241060#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301061 // We only expect there to be one signin process as we use process-per-site
1062 // for signin URLs. The signin process will be cleared from SigninManager
1063 // when the renderer is destroyed.
1064 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1065 SigninManager* signin_manager =
1066 SigninManagerFactory::GetForProfile(profile);
1067 if (signin_manager)
1068 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461069 BrowserThread::PostTask(
1070 BrowserThread::IO, FROM_HERE,
1071 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1072 extensions::ExtensionSystem::Get(profile)->info_map(),
1073 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301074 }
[email protected]d5bcd06f2013-04-21 08:07:241075#endif
[email protected]970c63e2013-03-07 00:25:301076
[email protected]06bdd2b2012-11-30 18:47:131077 ExtensionService* service =
1078 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461079 if (!service)
1080 return;
1081
1082 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441083 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591084 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461085 if (!extension)
1086 return;
1087
[email protected]6bc04fd82011-12-04 02:29:351088 service->process_map()->Insert(extension->id(),
1089 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331090 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461091 BrowserThread::PostTask(
1092 BrowserThread::IO, FROM_HERE,
1093 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591094 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461095 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351096 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331097 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461098}
1099
1100void ChromeContentBrowserClient::SiteInstanceDeleting(
1101 SiteInstance* site_instance) {
1102 if (!site_instance->HasProcess())
1103 return;
1104
1105 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021106 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131107 ExtensionService* service =
1108 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461109 if (!service)
1110 return;
1111
1112 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441113 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591114 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461115 if (!extension)
1116 return;
1117
[email protected]6bc04fd82011-12-04 02:29:351118 service->process_map()->Remove(extension->id(),
1119 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331120 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461121 BrowserThread::PostTask(
1122 BrowserThread::IO, FROM_HERE,
1123 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591124 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461125 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351126 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331127 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461128}
1129
[email protected]f05763972012-06-06 18:17:261130bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141131 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081132 const GURL& current_url,
1133 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261134 if (current_url.is_empty()) {
1135 // Always choose a new process when navigating to extension URLs. The
1136 // process grouping logic will combine all of a given extension's pages
1137 // into the same process.
[email protected]885c0e92012-11-13 20:27:421138 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261139 return true;
[email protected]e3daf3c2011-10-05 21:17:081140
[email protected]f05763972012-06-06 18:17:261141 return false;
1142 }
1143
1144 // Also, we must switch if one is an extension and the other is not the exact
1145 // same extension.
[email protected]885c0e92012-11-13 20:27:421146 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1147 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261148 if (current_url.GetOrigin() != new_url.GetOrigin())
1149 return true;
1150 }
1151
[email protected]e9841fbd2013-02-22 23:12:141152 // The checks below only matter if we can retrieve which extensions are
1153 // installed.
1154 Profile* profile =
1155 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1156 ExtensionService* service =
1157 extensions::ExtensionSystem::Get(profile)->extension_service();
1158 if (!service)
1159 return false;
1160
1161 // We must swap if the URL is for an extension and we are not using an
1162 // extension process.
1163 const Extension* new_extension =
1164 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1165 // Ignore all hosted apps except the Chrome Web Store, since they do not
1166 // require their own BrowsingInstance (e.g., postMessage is ok).
1167 if (new_extension &&
1168 new_extension->is_hosted_app() &&
1169 new_extension->id() != extension_misc::kWebStoreAppId)
1170 new_extension = NULL;
1171 if (new_extension &&
1172 site_instance->HasProcess() &&
1173 !service->process_map()->Contains(new_extension->id(),
1174 site_instance->GetProcess()->GetID()))
1175 return true;
1176
[email protected]f05763972012-06-06 18:17:261177 return false;
[email protected]e3daf3c2011-10-05 21:17:081178}
1179
[email protected]395045c2012-05-22 15:04:381180bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1181 content::ResourceContext* resource_context, const GURL& current_url,
1182 const GURL& new_url) {
1183 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1184 return extensions::CrossesExtensionProcessBoundary(
1185 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171186 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381187}
1188
[email protected]763ec4ca2011-04-29 15:48:121189std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1190 const std::string& alias_name) {
1191 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1192}
1193
[email protected]b80f68432011-05-02 17:22:301194void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1195 CommandLine* command_line, int child_process_id) {
1196#if defined(USE_LINUX_BREAKPAD)
1197 if (IsCrashReporterEnabled()) {
1198 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1199 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1200 }
1201#elif defined(OS_MACOSX)
1202 if (IsCrashReporterEnabled()) {
1203 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1204 child_process_logging::GetClientId());
1205 }
1206#endif // OS_MACOSX
1207
[email protected]f1933792011-06-14 00:49:341208 if (logging::DialogsAreSuppressed())
1209 command_line->AppendSwitch(switches::kNoErrorDialogs);
1210
[email protected]b80f68432011-05-02 17:22:301211 std::string process_type =
1212 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171213 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321214
1215 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1216 command_line->AppendSwitch(switches::kChromeFrame);
1217
[email protected]718eab62011-10-05 21:16:521218 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451219 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301220 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1221 if (!user_data_dir.empty())
1222 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1223#if defined(OS_CHROMEOS)
1224 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441225 browser_command_line.GetSwitchValueASCII(
1226 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301227 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441228 command_line->AppendSwitchASCII(
1229 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301230#endif
1231
[email protected]f3b1a082011-11-18 00:34:301232 content::RenderProcessHost* process =
1233 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371234 if (process) {
1235 Profile* profile = Profile::FromBrowserContext(
1236 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131237 ExtensionService* extension_service =
1238 extensions::ExtensionSystem::Get(profile)->extension_service();
1239 if (extension_service) {
1240 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001241 if (process_map && process_map->Contains(process->GetID()))
1242 command_line->AppendSwitch(switches::kExtensionProcess);
1243 }
[email protected]b80f68432011-05-02 17:22:301244
[email protected]a8d851f82011-12-21 00:32:371245 PrefService* prefs = profile->GetPrefs();
1246 // Currently this pref is only registered if applied via a policy.
1247 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1248 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1249 // Turn this policy into a command line switch.
1250 command_line->AppendSwitch(switches::kDisable3DAPIs);
1251 }
[email protected]718eab62011-10-05 21:16:521252
[email protected]a8d851f82011-12-21 00:32:371253 // Disable client-side phishing detection in the renderer if it is
1254 // disabled in the Profile preferences or the browser process.
1255 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1256 !g_browser_process->safe_browsing_detection_service()) {
1257 command_line->AppendSwitch(
1258 switches::kDisableClientSidePhishingDetection);
1259 }
[email protected]0045b0f42012-07-26 11:52:081260
1261 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211262 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521263
1264 InstantService* instant_service =
1265 InstantServiceFactory::GetForProfile(profile);
1266 if (instant_service &&
1267 instant_service->IsInstantProcess(process->GetID()))
1268 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301269
[email protected]d5bcd06f2013-04-21 08:07:241270#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301271 SigninManager* signin_manager =
1272 SigninManagerFactory::GetForProfile(profile);
1273 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1274 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241275#endif
[email protected]47c7ec82012-01-18 03:29:211276 }
[email protected]4287a3d2011-06-13 23:56:511277
[email protected]87552982012-11-02 17:21:401278 if (content::IsThreadedCompositingEnabled())
1279 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1280
[email protected]16dc42452013-04-09 04:37:191281 if (message_center::IsRichNotificationEnabled())
1282 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191283
[email protected]47c7ec82012-01-18 03:29:211284 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511285 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171286 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481287 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171288 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511289 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481290 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511291 switches::kAllowScriptingGallery,
1292 switches::kAppsCheckoutURL,
1293 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311294 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511295 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501296 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531297 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111298 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531299 switches::kEnableAdview,
1300 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211301 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511302 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511303 switches::kEnableIPCFuzzing,
1304 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451305 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481306 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051307 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511308 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291309 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511310 switches::kMemoryProfiling,
1311 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371312 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371313 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511314 switches::kPpapiFlashArgs,
1315 switches::kPpapiFlashInProcess,
1316 switches::kPpapiFlashPath,
1317 switches::kPpapiFlashVersion,
1318 switches::kProfilingAtStart,
1319 switches::kProfilingFile,
1320 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371321 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511322 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291323 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381324 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511325 };
1326
1327 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1328 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171329 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381330 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351331 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381332 switches::kEnableExperimentalExtensionApis,
1333 switches::kWhitelistedExtensionID,
1334 };
1335
1336 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1337 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511338 } else if (process_type == switches::kPluginProcess) {
1339 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441340#if defined(OS_CHROMEOS)
1341 chromeos::switches::kLoginProfile,
1342#endif
[email protected]4287a3d2011-06-13 23:56:511343 switches::kMemoryProfiling,
1344 switches::kSilentDumpOnDCHECK,
1345 switches::kUserDataDir,
1346 };
1347
1348 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1349 arraysize(kSwitchNames));
1350 } else if (process_type == switches::kZygoteProcess) {
1351 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511352 switches::kUserDataDir, // Make logs go to the right file.
1353 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501354 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511355 switches::kPpapiFlashInProcess,
1356 switches::kPpapiFlashPath,
1357 switches::kPpapiFlashVersion,
1358 };
1359
1360 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1361 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111362 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001363 base::FilePath user_data_dir =
1364 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1365 if (!user_data_dir.empty())
1366 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111367 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1368 // because GPU is expected to be unreliable.
1369 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1370 !command_line->HasSwitch(switches::kDisableBreakpad))
1371 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301372 }
[email protected]6f08af82011-09-15 01:19:031373
1374 // The command line switch kEnableBenchmarking needs to be specified along
1375 // with the kEnableStatsTable switch to ensure that the stats table global
1376 // is initialized correctly.
1377 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1378 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301379}
1380
1381std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431382 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351383 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301384 return g_browser_process->GetApplicationLocale();
1385}
1386
[email protected]597a867b2011-11-18 18:31:201387std::string ChromeContentBrowserClient::GetAcceptLangs(
1388 content::BrowserContext* context) {
1389 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371390 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081391}
1392
[email protected]9ec0f452012-05-31 15:58:531393gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221394 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531395 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081396}
1397
[email protected]a2176792011-05-08 19:30:491398bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091399 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191400 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201401 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201403 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051404 return io_data->GetCookieSettings()->
1405 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491406}
1407
[email protected]ed24fad2011-05-10 22:44:011408bool ChromeContentBrowserClient::AllowGetCookie(
1409 const GURL& url,
1410 const GURL& first_party,
1411 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201412 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011413 int render_process_id,
1414 int render_view_id) {
1415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201416 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051417 bool allow = io_data->GetCookieSettings()->
1418 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011419
[email protected]8093a542011-05-13 07:29:321420 BrowserThread::PostTask(
1421 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031422 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431423 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011424 return allow;
1425}
1426
1427bool ChromeContentBrowserClient::AllowSetCookie(
1428 const GURL& url,
1429 const GURL& first_party,
1430 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201431 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011432 int render_process_id,
1433 int render_view_id,
1434 net::CookieOptions* options) {
1435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201436 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051437 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1438 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1439
[email protected]8093a542011-05-13 07:29:321440 BrowserThread::PostTask(
1441 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031442 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431443 render_view_id, url, first_party, cookie_line, *options,
1444 !allow));
[email protected]ed24fad2011-05-10 22:44:011445 return allow;
1446}
1447
[email protected]d5a19162011-06-30 18:51:541448bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201449 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201451 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431452 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1453 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261454
[email protected]bf510ed2012-06-05 08:31:431455 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1456 // Could we even support per-origin settings?
1457 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541458}
1459
[email protected]5c5a88e2011-11-12 00:45:351460bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351461 const GURL& url,
1462 const string16& name,
1463 const string16& display_name,
1464 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201465 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481466 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201468 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351469 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1470 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1471
[email protected]62151052012-02-01 18:40:481472 // Record access to database for potential display in UI.
1473 std::vector<std::pair<int, int> >::const_iterator i;
1474 for (i = render_views.begin(); i != render_views.end(); ++i) {
1475 BrowserThread::PostTask(
1476 BrowserThread::UI, FROM_HERE,
1477 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1478 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351479 }
1480
1481 return allow;
1482}
1483
1484bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351485 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201486 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481487 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201489 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351490 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1491 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1492
[email protected]62151052012-02-01 18:40:481493 // Record access to file system for potential display in UI.
1494 std::vector<std::pair<int, int> >::const_iterator i;
1495 for (i = render_views.begin(); i != render_views.end(); ++i) {
1496 BrowserThread::PostTask(
1497 BrowserThread::UI, FROM_HERE,
1498 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1499 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351500 }
1501
1502 return allow;
1503}
1504
[email protected]7c5ff9a2012-03-02 07:42:491505bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1506 const GURL& url,
1507 const string16& name,
1508 content::ResourceContext* context,
1509 const std::vector<std::pair<int, int> >& render_views) {
1510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1511 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1512 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1513 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1514
1515 // Record access to IndexedDB for potential display in UI.
1516 std::vector<std::pair<int, int> >::const_iterator i;
1517 for (i = render_views.begin(); i != render_views.end(); ++i) {
1518 BrowserThread::PostTask(
1519 BrowserThread::UI, FROM_HERE,
1520 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1521 i->first, i->second, url, name, !allow));
1522 }
1523
1524 return allow;
1525}
1526
[email protected]6133f922011-07-01 21:34:341527net::URLRequestContext*
1528ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201529 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341530 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421531 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201532 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341533 return io_data->extensions_request_context();
1534 }
1535
1536 return NULL;
1537}
1538
[email protected]317f96c92011-05-31 06:53:411539QuotaPermissionContext*
1540ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1541 return new ChromeQuotaPermissionContext();
1542}
1543
[email protected]848dd042011-06-04 18:24:031544void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171545 int render_process_id,
1546 int render_view_id,
1547 int cert_error,
1548 const net::SSLInfo& ssl_info,
1549 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021550 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031551 bool overridable,
[email protected]d9be47702012-05-16 03:41:221552 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171553 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001554 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021555 if (resource_type != ResourceType::MAIN_FRAME) {
1556 // A sub-resource has a certificate error. The user doesn't really
1557 // have a context for making the right decision, so block the
1558 // request hard, without an info bar to allow showing the insecure
1559 // content.
[email protected]8c965c22013-05-23 19:28:001560 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021561 return;
1562 }
1563
[email protected]f9034cf2011-07-21 12:43:411564 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131565 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171566 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411567 if (!tab) {
1568 NOTREACHED();
1569 return;
1570 }
1571 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501572 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301573 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011574 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1575 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411576 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171577 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411578 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001579 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411580 return;
1581 }
1582 }
1583
[email protected]1e87df32012-09-12 04:53:191584#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231585 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1586 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1587 if (captive_portal_tab_helper)
1588 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191589#endif
1590
[email protected]f9034cf2011-07-21 12:43:411591 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221592 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1593 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031594}
1595
[email protected]c99c442e2011-08-24 11:37:301596void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451597 int render_process_id,
1598 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401599 const net::HttpNetworkSession* network_session,
1600 net::SSLCertRequestInfo* cert_request_info,
1601 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131602 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451603 render_process_id, render_view_id);
1604 if (!tab) {
1605 NOTREACHED();
1606 return;
1607 }
1608
[email protected]6786bf402011-12-03 15:19:451609 GURL requesting_url("https://" + cert_request_info->host_and_port);
1610 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1611 << cert_request_info->host_and_port;
1612
[email protected]627e0512011-12-21 22:55:301613 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451614 scoped_ptr<Value> filter(
1615 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1616 requesting_url,
1617 requesting_url,
1618 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1619 std::string(), NULL));
1620
1621 if (filter.get()) {
1622 // Try to automatically select a client certificate.
1623 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1624 DictionaryValue* filter_dict =
1625 static_cast<DictionaryValue*>(filter.get());
1626
1627 const std::vector<scoped_refptr<net::X509Certificate> >&
1628 all_client_certs = cert_request_info->client_certs;
1629 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091630 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451631 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091632 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451633 return;
1634 }
1635 }
1636 } else {
1637 NOTREACHED();
1638 }
1639 }
1640
[email protected]11feec322012-09-18 03:58:521641 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1642 if (!ssl_tab_helper) {
1643 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451644 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141645 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401646 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451647 return;
1648 }
[email protected]11feec322012-09-18 03:58:521649 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401650 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451651}
1652
[email protected]3b455502012-12-11 18:22:581653void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451654 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581655 net::CertificateMimeType cert_type,
1656 const void* cert_data,
1657 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451658 int render_process_id,
1659 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581660 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1661 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451662}
1663
[email protected]dc73a7b2012-03-25 15:27:181664content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561665 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181666}
1667
[email protected]941623e2011-06-07 23:06:041668void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1669 const GURL& source_origin,
1670 int callback_context,
1671 int render_process_id,
1672 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111673#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021674 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1675 WebContents* contents =
1676 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1677 if (!contents) {
[email protected]941623e2011-06-07 23:06:041678 NOTREACHED();
1679 return;
1680 }
1681
[email protected]d0d9c3ee2012-06-19 03:07:021682 // Skip showing the infobar if the request comes from an extension, and that
1683 // extension has the 'notify' permission. (If the extension does not have the
1684 // permission, the user will still be prompted.)
1685 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011686 ExtensionInfoMap* extension_info_map =
1687 extensions::ExtensionSystem::Get(profile)->info_map();
1688 DesktopNotificationService* notification_service =
1689 DesktopNotificationServiceFactory::GetForProfile(profile);
1690 const Extension* extension = NULL;
1691 if (extension_info_map) {
1692 ExtensionSet extensions;
1693 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1694 source_origin, render_process_id,
1695 extensions::APIPermission::kNotification, &extensions);
1696 for (ExtensionSet::const_iterator iter = extensions.begin();
1697 iter != extensions.end(); ++iter) {
1698 if (notification_service->IsExtensionEnabled((*iter)->id())) {
[email protected]cadac622013-06-11 16:46:361699 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011700 break;
1701 }
1702 }
1703 }
[email protected]eb4832a2012-12-08 01:57:521704 RenderViewHost* rvh =
1705 RenderViewHost::FromID(render_process_id, render_view_id);
1706 if (IsExtensionWithPermissionOrSuggestInConsole(
1707 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021708 if (rvh)
1709 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1710 return;
1711 }
1712
[email protected]c7cd5942013-04-30 03:31:011713 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021714 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111715#else
1716 NOTIMPLEMENTED();
1717#endif
[email protected]941623e2011-06-07 23:06:041718}
1719
1720WebKit::WebNotificationPresenter::Permission
1721 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021722 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201723 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021724 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111725#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201727 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041728
[email protected]c7cd5942013-04-30 03:31:011729 DesktopNotificationService* notification_service =
1730 io_data->GetNotificationService();
1731 if (notification_service) {
1732 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1733 ExtensionSet extensions;
1734 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1735 source_origin, render_process_id,
1736 extensions::APIPermission::kNotification, &extensions);
1737 for (ExtensionSet::const_iterator iter = extensions.begin();
1738 iter != extensions.end(); ++iter) {
1739 if (notification_service->IsExtensionEnabled((*iter)->id()))
1740 return WebKit::WebNotificationPresenter::PermissionAllowed;
1741 }
1742
1743 return notification_service->HasPermission(source_origin);
1744 }
1745
1746 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111747#else
1748 return WebKit::WebNotificationPresenter::PermissionAllowed;
1749#endif
[email protected]941623e2011-06-07 23:06:041750}
1751
1752void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171753 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041754 int render_process_id,
1755 int render_view_id,
1756 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111757#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041758 RenderViewHost* rvh = RenderViewHost::FromID(
1759 render_process_id, render_view_id);
1760 if (!rvh) {
1761 NOTREACHED();
1762 return;
1763 }
1764
[email protected]9f76c1e2012-03-05 15:15:581765 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301766 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041767 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371768 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041769 service->ShowDesktopNotification(
1770 params, render_process_id, render_view_id,
1771 worker ? DesktopNotificationService::WorkerNotification :
1772 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111773#else
1774 NOTIMPLEMENTED();
1775#endif
[email protected]941623e2011-06-07 23:06:041776}
1777
1778void ChromeContentBrowserClient::CancelDesktopNotification(
1779 int render_process_id,
1780 int render_view_id,
1781 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111782#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041783 RenderViewHost* rvh = RenderViewHost::FromID(
1784 render_process_id, render_view_id);
1785 if (!rvh) {
1786 NOTREACHED();
1787 return;
1788 }
1789
[email protected]9f76c1e2012-03-05 15:15:581790 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301791 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041792 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371793 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041794 service->CancelDesktopNotification(
1795 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111796#else
1797 NOTIMPLEMENTED();
1798#endif
[email protected]941623e2011-06-07 23:06:041799}
1800
[email protected]9f3fba52011-06-08 20:37:191801bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351802 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021803 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191804 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201805 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011806 int render_process_id,
1807 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191808 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011809
1810 *no_javascript_access = false;
1811
[email protected]9f3fba52011-06-08 20:37:191812 // If the opener is trying to create a background window but doesn't have
1813 // the appropriate permission, fail the attempt.
1814 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201815 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531816 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1817
[email protected]03b6d552012-03-29 04:03:011818 if (!map->SecurityOriginHasAPIPermission(
1819 source_origin,
1820 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061821 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011822 return false;
1823 }
1824
[email protected]7b54ca02012-03-02 18:06:531825 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1826 // return a recently installed Extension even if this CanCreateWindow call
1827 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011828 // because the permission check above would have caused an early return
1829 // already. We must use the full URL to find hosted apps, though, and not
1830 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531831 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351832 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291833 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011834 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191835 }
[email protected]056efdc2013-04-06 00:14:531836
1837 // No new browser window (popup or tab) in app mode.
1838 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1839 chrome::IsRunningInForcedAppMode()) {
1840 return false;
1841 }
1842
[email protected]9f3fba52011-06-08 20:37:191843 return true;
1844}
1845
1846std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201847 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191848 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1849 // Check if it's an extension-created worker, in which case we want to use
1850 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201851 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191852 const Extension* extension =
1853 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1854 return extension ? extension->name() : std::string();
1855}
1856
[email protected]99907362012-01-11 05:41:401857void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1858 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171859}
1860
[email protected]7a06d282013-05-03 04:39:331861// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021862content::SpeechRecognitionManagerDelegate*
1863 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]3bd0aab2013-05-30 20:07:491864#if !defined(OS_ANDROID)
[email protected]c52b2892012-03-07 11:01:021865 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321866#else
[email protected]3bd0aab2013-05-30 20:07:491867 // TODO(janx): Implement speech::AndroidSpeechRecognitionManagerDelegate
1868 // (see crbug.com/222352).
[email protected]a03f2d32012-03-14 00:26:321869 return NULL;
1870#endif
[email protected]66cfec62012-02-24 17:57:511871}
1872
[email protected]ae6e9912011-07-27 01:18:281873net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1874 return g_browser_process->net_log();
1875}
1876
[email protected]32538d92011-08-25 00:09:231877AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1878 return new ChromeAccessTokenStore();
1879}
1880
[email protected]dbae6b02011-06-29 23:51:411881bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011882 return true;
[email protected]dbae6b02011-06-29 23:51:411883}
1884
[email protected]64d69de42012-02-06 00:19:541885void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321886 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061887 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581888 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061889 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061890
[email protected]f3986f82012-01-03 20:00:061891 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541892 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061893 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541894 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061895 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541896 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061897 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541898 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061899 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541900 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061901 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541902 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031903 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1904 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061905
[email protected]64d69de42012-02-06 00:19:541906 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401907 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541908 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401909 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541910 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401911 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541912 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401913 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061914
[email protected]ddf72142012-05-22 04:52:401915 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061916
[email protected]64d69de42012-02-06 00:19:541917 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401918 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541919 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061920 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541921 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061922 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1923 const DictionaryValue* inspector_settings =
1924 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1925 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181926 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1927 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061928 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181929 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541930 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181931 std::make_pair(iter.key(), value));
1932 }
[email protected]f3986f82012-01-03 20:00:061933 }
1934 }
[email protected]64d69de42012-02-06 00:19:541935 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061936
[email protected]ddf72142012-05-22 04:52:401937 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541938 web_prefs->javascript_enabled = false;
1939 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1940 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401941 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541942 web_prefs->plugins_enabled = false;
1943 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1944 web_prefs->java_enabled = false;
1945 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401946 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061947
[email protected]64d69de42012-02-06 00:19:541948 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1949 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061950
[email protected]64d69de42012-02-06 00:19:541951 web_prefs->memory_info_enabled =
1952 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1953 web_prefs->allow_displaying_insecure_content =
1954 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1955 web_prefs->allow_running_insecure_content =
1956 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321957#if defined(OS_ANDROID)
1958 web_prefs->font_scale_factor =
1959 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1960 web_prefs->force_enable_zoom =
1961 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451962#if defined(GOOGLE_TV)
1963 web_prefs->user_gesture_required_for_media_playback = false;
1964#endif
[email protected]d3b935f2012-10-19 23:14:321965#endif
[email protected]5c915252013-05-07 13:15:391966
[email protected]af4256d52013-06-04 20:39:071967#if defined(OS_ANDROID)
1968 web_prefs->password_echo_enabled =
1969 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
1970#else
[email protected]9d06d88d2012-02-23 22:37:081971 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:071972#endif
1973
[email protected]5c915252013-05-07 13:15:391974#if defined(OS_CHROMEOS)
1975 // Enable password echo during OOBE when keyboard driven flag is set.
1976 if (chromeos::UserManager::IsInitialized() &&
1977 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
1978 !chromeos::StartupUtils::IsOobeCompleted()) {
1979 bool keyboard_driven_oobe = false;
1980 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]e8f3f9982013-05-10 20:59:531981 chromeos::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:391982 if (keyboard_driven_oobe)
1983 web_prefs->password_echo_enabled = true;
1984 }
1985#endif
[email protected]f3986f82012-01-03 20:00:061986
[email protected]46f8e742013-05-03 18:37:141987#if defined(OS_ANDROID)
1988 web_prefs->user_style_sheet_enabled = false;
1989#else
[email protected]64d69de42012-02-06 00:19:541990 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151991 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:361992 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:151993 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541994 web_prefs->user_style_sheet_enabled = true;
1995 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151996 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541997 } else {
1998 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061999 }
[email protected]46f8e742013-05-03 18:37:142000#endif
[email protected]f3986f82012-01-03 20:00:062001
[email protected]cfadadd2013-04-03 04:43:022002 web_prefs->asynchronous_spell_checking_enabled = true;
2003 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572004
[email protected]64d69de42012-02-06 00:19:542005 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062006 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542007 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062008 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542009 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062010 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2011
2012 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542013 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062014 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542015 web_prefs->default_encoding);
2016 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402017 prefs->ClearPref(prefs::kDefaultCharset);
2018 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062019 }
[email protected]64d69de42012-02-06 00:19:542020 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062021
[email protected]88ecf66d2012-12-11 22:53:472022 if (content::IsForceCompositingModeEnabled())
2023 web_prefs->force_compositing_mode = true;
2024
[email protected]299d7f12012-05-23 05:31:152025 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232026 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132027 ExtensionService* service =
2028 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062029 if (service) {
[email protected]1bc28312012-11-08 08:31:532030 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2031 const Extension* extension = service->extensions()->GetByID(url.host());
2032 // Ensure that we are only granting extension preferences to URLs with
2033 // the correct scheme. Without this check, chrome-guest:// schemes used by
2034 // webview tags as well as hosts that happen to match the id of an
2035 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422036 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532037 extension_webkit_preferences::SetPreferences(
2038 extension, view_type, web_prefs);
2039 }
[email protected]f3986f82012-01-03 20:00:062040 }
2041
[email protected]cb2edf22013-04-01 20:25:232042 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542043 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232044 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062045 // Disable all kinds of acceleration for background pages.
2046 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542047 web_prefs->force_compositing_mode = false;
2048 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062049 }
[email protected]2e21fe292012-03-02 22:52:322050
2051#if defined(FILE_MANAGER_EXTENSION)
2052 // Override the default of suppressing HW compositing for WebUI pages for the
2053 // file manager, which is implemented using WebUI but wants HW acceleration
2054 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532055 if (url.SchemeIs(extensions::kExtensionScheme) &&
2056 url.host() == kFileBrowserDomain) {
[email protected]2e21fe292012-03-02 22:52:322057 web_prefs->accelerated_compositing_enabled = true;
2058 web_prefs->accelerated_2d_canvas_enabled = true;
2059 }
2060#endif
[email protected]181a95ee2011-07-12 19:26:362061}
2062
2063void ChromeContentBrowserClient::UpdateInspectorSetting(
2064 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062065 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582066 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062067 DictionaryPrefUpdate update(
2068 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2069 prefs::kWebKitInspectorSettings);
2070 DictionaryValue* inspector_settings = update.Get();
2071 inspector_settings->SetWithoutPathExpansion(key,
2072 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362073}
2074
[email protected]b8148ac2011-07-13 22:03:252075void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2076 BrowserURLHandler* handler) {
2077 // Add the default URL handlers.
2078 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2079 BrowserURLHandler::null_handler());
2080 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2081 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2082
[email protected]b3adbd02011-11-30 22:23:272083 // about: handler. Must come before chrome: handler, since it will
2084 // rewrite about: urls to chrome: URLs and then expect chrome: to
2085 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252086 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2087 BrowserURLHandler::null_handler());
2088 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242089 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252090}
2091
2092void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372093 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582094 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472095 BrowsingDataRemover* remover =
2096 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552097 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2098 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252099 // BrowsingDataRemover takes care of deleting itself when done.
2100}
2101
2102void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372103 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582104 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472105 BrowsingDataRemover* remover =
2106 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232107 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552108 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252109 // BrowsingDataRemover takes care of deleting itself when done.
2110}
2111
[email protected]650b2d52013-02-10 03:41:452112base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322113 return download_util::GetDefaultDownloadDirectory();
2114}
2115
[email protected]c9b6eb62011-10-18 20:49:392116std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2117 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2118}
2119
[email protected]b7631cc2012-09-15 05:08:382120void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2121 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542122#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382123 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2124 scoped_ptr<ppapi::host::HostFactory>(
2125 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542126#endif
[email protected]b7631cc2012-09-15 05:08:382127}
2128
[email protected]0c7193742012-11-07 19:05:032129content::BrowserPpapiHost*
2130 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2131 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132132 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032133 while (!iter.Done()) {
2134 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2135 if (host->process() &&
2136 host->process()->GetData().id == plugin_process_id) {
2137 // Found the plugin.
2138 return host->browser_ppapi_host();
2139 }
2140 ++iter;
2141 }
2142 return NULL;
2143}
2144
[email protected]7b38b192013-03-23 18:39:312145bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2146 content::BrowserContext* browser_context, const GURL& site_url) {
2147 if (CommandLine::ForCurrentProcess()->HasSwitch(
2148 switches::kEnableBrowserPluginForAllViewTypes))
2149 return true;
2150
2151 Profile* profile = Profile::FromBrowserContext(browser_context);
2152 ExtensionService* service =
2153 extensions::ExtensionSystem::Get(profile)->extension_service();
2154 if (!service)
2155 return false;
2156
2157 const Extension* extension = service->extensions()->
2158 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2159 if (!extension)
2160 return false;
2161
[email protected]c2d2f102013-04-29 16:42:582162 return extension->HasAPIPermission(APIPermission::kWebView) ||
2163 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312164}
2165
[email protected]38cd8f7f2012-06-15 22:06:072166bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582167 content::BrowserContext* browser_context,
2168 const GURL& url,
2169 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402170#if defined(ENABLE_PLUGINS)
2171 return IsExtensionOrSharedModuleWhitelisted(
2172 Profile::FromBrowserContext(browser_context),
2173 url,
2174 allowed_socket_origins_,
2175 switches::kAllowNaClSocketAPI);
2176#else
[email protected]a658d452012-03-02 12:45:292177 return false;
[email protected]93f72062013-05-29 20:29:402178#endif
[email protected]e461da2f2012-02-16 19:06:402179}
2180
[email protected]650b2d52013-02-10 03:41:452181base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2182 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142183 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2184 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2185}
2186
[email protected]a28e3302013-02-03 03:50:432187ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2188 WebContents* web_contents) {
2189 return new ChromeSelectFilePolicy(web_contents);
2190}
2191
[email protected]7d9424702013-04-14 13:14:162192void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2193 std::vector<std::string>* additional_allowed_schemes) {
2194 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2195 additional_allowed_schemes);
2196 additional_allowed_schemes->push_back(kChromeUIScheme);
2197 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2198}
2199
[email protected]02250952013-04-24 23:52:532200void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2201 const base::FilePath& storage_partition_path,
2202 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2203#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032204 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]02250952013-04-24 23:52:532205 additional_providers->push_back(new MediaFileSystemMountPointProvider(
[email protected]30a306f42013-06-10 03:09:032206 storage_partition_path,
2207 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
2208 MediaFileSystemMountPointProvider::kMediaTaskRunnerName))));
[email protected]02250952013-04-24 23:52:532209#endif
2210}
2211
[email protected]e60c0232011-11-11 19:56:352212#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182213void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2214 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382215 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082216 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392217#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452218 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392219 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2220 DCHECK(!data_path.empty());
2221
2222 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452223 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392224 base::PlatformFile f =
2225 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2226 DCHECK(f != base::kInvalidPlatformFileValue);
2227 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2228 FileDescriptor(f, true)));
2229
[email protected]650b2d52013-02-10 03:41:452230 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392231 data_path.AppendASCII("chrome_100_percent.pak");
2232 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2233 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372234 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392235 FileDescriptor(f, true)));
2236
2237 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452238 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392239 GetLocaleFilePath(locale, false);
2240 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2241 DCHECK(f != base::kInvalidPlatformFileValue);
2242 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2243 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382244
[email protected]650b2d52013-02-10 03:41:452245 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372246 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2247 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2248 DCHECK(f != base::kInvalidPlatformFileValue);
2249 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2250 FileDescriptor(f, true)));
2251
[email protected]40da3e0c2012-10-24 22:03:382252#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432253 if (IsCrashReporterEnabled()) {
2254 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2255 if (f == base::kInvalidPlatformFileValue) {
2256 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2257 "be disabled for this process.";
2258 } else {
2259 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2260 FileDescriptor(f, true)));
2261 }
[email protected]40da3e0c2012-10-24 22:03:382262 }
2263#endif // defined(USE_LINUX_BREAKPAD)
2264
2265#else
2266 int crash_signal_fd = GetCrashSignalFD(command_line);
2267 if (crash_signal_fd >= 0) {
2268 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2269 FileDescriptor(crash_signal_fd,
2270 false)));
2271 }
[email protected]29699c22012-10-03 23:57:392272#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302273}
[email protected]e60c0232011-11-11 19:56:352274#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302275
[email protected]4a65826d2011-08-25 16:04:012276#if defined(OS_WIN)
2277const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2278 return chrome::kBrowserResourcesDll;
2279}
[email protected]34f48682013-03-20 00:30:182280
2281void ChromeContentBrowserClient::PreSpawnRenderer(
2282 sandbox::TargetPolicy* policy,
2283 bool* success) {
2284 // This code is duplicated in nacl_exe_win_64.cc.
2285 // Allow the server side of a pipe restricted to the "chrome.nacl."
2286 // namespace so that it cannot impersonate other system or other chrome
2287 // service pipes.
2288 sandbox::ResultCode result = policy->AddRule(
2289 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2290 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2291 L"\\\\.\\pipe\\chrome.nacl.*");
2292 if (result != sandbox::SBOX_ALL_OK) {
2293 *success = false;
2294 return;
2295 }
2296
2297 // Renderers need to send named pipe handles and shared memory
2298 // segment handles to NaCl loader processes.
2299 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2300 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2301 L"File");
2302 if (result != sandbox::SBOX_ALL_OK) {
2303 *success = false;
2304 return;
2305 }
2306}
[email protected]4a65826d2011-08-25 16:04:012307#endif
2308
[email protected]37a72af2011-06-13 05:42:012309#if defined(USE_NSS)
2310crypto::CryptoModuleBlockingPasswordDelegate*
2311 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2312 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292313 return chrome::NewCryptoModuleBlockingDialogDelegate(
2314 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012315}
2316#endif
2317
[email protected]d977f9c2011-03-14 16:10:262318} // namespace chrome