blob: b1802c1a97dd0529a0288d077a141c9afb1323c2 [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]0609b17f2011-05-31 20:13:4253#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5654#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0655#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4156#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5057#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0758#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4159#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1460#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0361#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1462#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3263#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0664#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1465#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3866#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4367#include "chrome/browser/search/instant_service.h"
68#include "chrome/browser/search/instant_service_factory.h"
69#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1470#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0271#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3372#include "chrome/browser/speech/tts_message_filter.h"
[email protected]8ec71262011-07-28 08:12:4673#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5874#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0375#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5276#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4577#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5478#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4379#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]b5d73422012-06-02 23:46:4480#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5081#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]970c63e2013-03-07 00:25:3082#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
[email protected]f3986f82012-01-03 20:00:0683#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1584#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2785#include "chrome/browser/validation_message_message_filter.h"
[email protected]db9f2142013-05-27 22:56:1686#include "chrome/browser/webview/webview_guest.h"
[email protected]b80f68432011-05-02 17:22:3087#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0188#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1489#include "chrome/common/chrome_paths.h"
[email protected]f3b357692013-03-22 05:16:1390#include "chrome/common/chrome_process_type.h"
[email protected]b80f68432011-05-02 17:22:3091#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2992#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0493#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3894#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4495#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4396#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:2997#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]dda54822013-06-15 01:26:3998#include "chrome/common/extensions/permissions/permissions_data.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]9d450492013-06-13 23:08:37101#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12102#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38103#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09104#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53105#include "chromeos/chromeos_constants.h"
[email protected]75fee372013-03-06 00:42:44106#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43107#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30108#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38109#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03110#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31111#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03112#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59113#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36114#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30115#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33116#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05117#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33118#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19119#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10120#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43121#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18122#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23123#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42124#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39125#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23126#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53127#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58128#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34129#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06130#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57131#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38132#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39133#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08134#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24135#include "ui/message_center/message_center_util.h"
[email protected]fab55e72013-05-31 07:06:18136#include "webkit/common/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04137#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26138
[email protected]b48c9182011-10-26 18:03:30139#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38140#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18141#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38142#elif defined(OS_MACOSX)
143#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56144#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30145#elif defined(OS_CHROMEOS)
146#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]5c915252013-05-07 13:15:39147#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49148#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]5c915252013-05-07 13:15:39149#include "chrome/browser/chromeos/system/statistics_provider.h"
[email protected]931d1042013-04-05 17:50:44150#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26151#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30152#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09153#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38154#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09155#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39156#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30157#elif defined(OS_POSIX)
158#include "chrome/browser/chrome_browser_main_posix.h"
159#endif
160
[email protected]6653c192012-04-10 22:52:44161#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30162#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12163#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43164#endif
[email protected]b80f68432011-05-02 17:22:30165
[email protected]1e87df32012-09-12 04:53:19166#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
167#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
168#endif
169
[email protected]29699c22012-10-03 23:57:39170#if defined(OS_ANDROID)
171#include "ui/base/ui_base_paths.h"
172#endif
173
[email protected]37a72af2011-06-13 05:42:01174#if defined(USE_NSS)
175#include "chrome/browser/ui/crypto_module_password_dialog.h"
176#endif
177
[email protected]d5bcd06f2013-04-21 08:07:24178#if !defined(OS_CHROMEOS)
179#include "chrome/browser/signin/signin_manager.h"
180#include "chrome/browser/signin/signin_manager_factory.h"
181#endif
182
[email protected]02250952013-04-24 23:52:53183#if !defined(OS_ANDROID)
184#include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h"
185#endif
186
[email protected]6ef98b5a2013-05-31 23:58:31187#if defined(ENABLE_WEBRTC)
188#include "chrome/browser/media/webrtc_logging_handler_host.h"
189#endif
190
[email protected]02a3dc122013-06-13 15:07:53191#if defined(FILE_MANAGER_EXTENSION)
192#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
193#endif
194
[email protected]c7abd422012-09-25 00:20:08195using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47196using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03197using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39198using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31199using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59200using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08201using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00202using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11203using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33204using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13205using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06206using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34207using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40208using extensions::Manifest;
[email protected]631bb742011-11-02 11:29:39209
[email protected]c5dbef02011-05-13 05:06:09210namespace {
211
[email protected]eabbfb12013-04-05 23:28:35212// Cached version of the locale so we can return the locale on the I/O
213// thread.
214base::LazyInstance<std::string> g_io_thread_application_locale;
215
[email protected]93f72062013-05-29 20:29:40216#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40217const char* kPredefinedAllowedSocketOrigins[] = {
218 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18219 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45220 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
221 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
222 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
223 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35224 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54225 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
226 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
227 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
228 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
229 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
230 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38231 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58232 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29233 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
234 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
235 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
236 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
237 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40238};
[email protected]93f72062013-05-29 20:29:40239#endif
[email protected]e461da2f2012-02-16 19:06:40240
[email protected]f8f93eb2012-09-25 03:06:24241// Returns a copy of the given url with its host set to given host and path set
242// to given path. Other parts of the url will be the same.
243GURL ReplaceURLHostAndPath(const GURL& url,
244 const std::string& host,
245 const std::string& path) {
246 url_canon::Replacements<char> replacements;
247 replacements.SetHost(host.c_str(),
248 url_parse::Component(0, host.length()));
249 replacements.SetPath(path.c_str(),
250 url_parse::Component(0, path.length()));
251 return url.ReplaceComponents(replacements);
252}
253
254// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
255GURL AddUberHost(const GURL& url) {
256 const std::string uber_host = chrome::kChromeUIUberHost;
257 const std::string new_path = url.host() + url.path();
258
259 return ReplaceURLHostAndPath(url, uber_host, new_path);
260}
261
[email protected]045bf7c2012-09-28 20:27:36262// If url->host() is "chrome" and url->path() has characters other than the
263// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
264// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24265bool RemoveUberHost(GURL* url) {
266 if (url->host() != chrome::kChromeUIUberHost)
267 return false;
268
[email protected]045bf7c2012-09-28 20:27:36269 if (url->path().empty() || url->path() == "/")
270 return false;
271
[email protected]f8f93eb2012-09-25 03:06:24272 const std::string old_path = url->path();
273
274 const std::string::size_type separator = old_path.find('/', 1);
275 std::string new_host;
276 std::string new_path;
277 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36278 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24279 } else {
280 new_host = old_path.substr(1, separator - 1);
281 new_path = old_path.substr(separator);
282 }
283
[email protected]44e8add2013-06-13 17:29:15284 // Do not allow URLs with paths empty before the first slash since we can't
285 // have an empty host. (e.g "foo://chrome//")
286 if (new_host.empty())
287 return false;
288
[email protected]f8f93eb2012-09-25 03:06:24289 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
290
[email protected]44e8add2013-06-13 17:29:15291 DCHECK(url->is_valid());
292
[email protected]f8f93eb2012-09-25 03:06:24293 return true;
294}
295
[email protected]b8148ac2011-07-13 22:03:25296// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42297bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24298 // Do not handle special URLs such as "about:foo"
299 if (!url->host().empty()) {
300 const GURL chrome_url = AddUberHost(*url);
301
302 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
303 // be called.
304 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
305 browser_context, chrome_url))
306 return true;
307 }
308
[email protected]863f70a2012-01-27 02:05:50309 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
310 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25311 return false;
312
[email protected]fe69558d2012-03-12 11:34:49313#if defined(OS_CHROMEOS)
314 // Special case : in ChromeOS in Guest mode bookmarks and history are
315 // disabled for security reasons. New tab page explains the reasons, so
316 // we redirect user to new tab page.
317 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
318 if (url->SchemeIs(chrome::kChromeUIScheme) &&
319 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
320 url->DomainIs(chrome::kChromeUIHistoryHost))) {
321 // Rewrite with new tab URL
322 *url = GURL(chrome::kChromeUINewTabURL);
323 }
324 }
325#endif
326
[email protected]b8148ac2011-07-13 22:03:25327 // Special case the new tab page. In older versions of Chrome, the new tab
328 // page was hosted at chrome-internal:<blah>. This might be in people's saved
329 // sessions or bookmarks, so we say any URL with that scheme triggers the new
330 // tab page.
331 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
332 // Rewrite it with the proper new tab URL.
333 *url = GURL(chrome::kChromeUINewTabURL);
334 }
335
336 return true;
337}
338
[email protected]f8f93eb2012-09-25 03:06:24339// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
340// "chrome://foo/".
341bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
342 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
343 return false;
344
345 return RemoveUberHost(url);
346}
347
[email protected]8d3132f62011-10-12 07:13:42348// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
349// below. Extension, and isolated apps require different privileges to be
350// granted to their RenderProcessHosts. This classification allows us to make
351// sure URLs are served by hosts with the right set of privileges.
352enum RenderProcessHostPrivilege {
353 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45354 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42355 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45356 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42357};
358
359RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
360 const GURL& url,
361 ExtensionService* service) {
362 // Default to a normal renderer cause it is lower privileged. This should only
363 // occur if the URL on a site instance is either malformed, or uninitialized.
364 // If it is malformed, then there is no need for better privileges anyways.
365 // If it is uninitialized, but eventually settles on being an a scheme other
366 // than normal webrenderer, the navigation logic will correct us out of band
367 // anyways.
368 if (!url.is_valid())
369 return PRIV_NORMAL;
370
[email protected]885c0e92012-11-13 20:27:42371 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44372 const Extension* extension =
373 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43374 if (extension &&
375 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42376 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45377 if (extension && extension->is_hosted_app())
378 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42379
380 return PRIV_EXTENSION;
381 }
382
383 return PRIV_NORMAL;
384}
385
386RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30387 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46388 extensions::ProcessMap* process_map,
389 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46390 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30391 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46392 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21393 return PRIV_NORMAL;
394
[email protected]6f371442011-11-09 06:45:46395 for (std::set<std::string>::iterator iter = extension_ids.begin();
396 iter != extension_ids.end(); ++iter) {
397 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43398 if (extension &&
399 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42400 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45401 if (extension && extension->is_hosted_app())
402 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42403 }
404
[email protected]676f6ab2011-10-19 20:23:21405 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42406}
407
[email protected]6786bf402011-12-03 15:19:45408bool CertMatchesFilter(const net::X509Certificate& cert,
409 const base::DictionaryValue& filter) {
410 // TODO(markusheintz): This is the minimal required filter implementation.
411 // Implement a better matcher.
412
413 // An empty filter matches any client certificate since no requirements are
414 // specified at all.
415 if (filter.empty())
416 return true;
417
418 std::string common_name;
419 if (filter.GetString("ISSUER.CN", &common_name) &&
420 (cert.issuer().common_name == common_name)) {
421 return true;
422 }
423 return false;
424}
425
[email protected]f3986f82012-01-03 20:00:06426// Fills |map| with the per-script font prefs under path |map_name|.
427void FillFontFamilyMap(const PrefService* prefs,
428 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53429 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06430 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
431 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
432 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
433 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23434 if (!font_family.empty())
435 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06436 }
437}
438
[email protected]a1733df2012-06-22 11:24:18439#if defined(OS_POSIX) && !defined(OS_MACOSX)
440int GetCrashSignalFD(const CommandLine& command_line) {
441 if (command_line.HasSwitch(switches::kExtensionProcess)) {
442 ExtensionCrashHandlerHostLinux* crash_handler =
443 ExtensionCrashHandlerHostLinux::GetInstance();
444 return crash_handler->GetDeathSignalSocket();
445 }
446
447 std::string process_type =
448 command_line.GetSwitchValueASCII(switches::kProcessType);
449
450 if (process_type == switches::kRendererProcess)
451 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
452
453 if (process_type == switches::kPluginProcess)
454 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
455
456 if (process_type == switches::kPpapiPluginProcess)
457 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
458
459 if (process_type == switches::kGpuProcess)
460 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
461
462 return -1;
463}
464#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
465
[email protected]d5bcd06f2013-04-21 08:07:24466#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30467GURL GetEffectiveURLForSignin(const GURL& url) {
468 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
469
470 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03471 // Copy the path because the argument to SetPathStr must outlive
472 // the Replacements object.
473 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30474 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03475 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30476 effective_url = effective_url.ReplaceComponents(replacements);
477 return effective_url;
478}
[email protected]d5bcd06f2013-04-21 08:07:24479#endif
[email protected]970c63e2013-03-07 00:25:30480
[email protected]eabbfb12013-04-05 23:28:35481void SetApplicationLocaleOnIOThread(const std::string& locale) {
482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
483 g_io_thread_application_locale.Get() = locale;
484}
485
[email protected]9dbfff12011-07-01 19:37:07486} // namespace
[email protected]c5dbef02011-05-13 05:06:09487
[email protected]d977f9c2011-03-14 16:10:26488namespace chrome {
489
[email protected]e461da2f2012-02-16 19:06:40490ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40491#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40492 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
493 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40494#endif
[email protected]1deace22013-05-22 06:14:46495
496 permissions_policy_delegate_.reset(
497 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40498}
499
500ChromeContentBrowserClient::~ChromeContentBrowserClient() {
501}
502
[email protected]bca18382012-06-25 19:15:23503// static
[email protected]c753f142013-02-10 13:14:04504void ChromeContentBrowserClient::RegisterUserPrefs(
[email protected]443e9312013-05-06 06:17:34505 user_prefs::PrefRegistrySyncable* registry) {
506 registry->RegisterBooleanPref(
507 prefs::kDisable3DAPIs,
508 false,
509 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
510 registry->RegisterBooleanPref(
511 prefs::kEnableHyperlinkAuditing,
512 true,
513 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
514 registry->RegisterBooleanPref(
515 prefs::kEnableMemoryInfo,
516 false,
517 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23518}
519
[email protected]eabbfb12013-04-05 23:28:35520// static
521void ChromeContentBrowserClient::SetApplicationLocale(
522 const std::string& locale) {
523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
524
525 // This object is guaranteed to outlive all threads so we don't have to
526 // worry about the lack of refcounting and can just post as Unretained.
527 //
528 // The common case is that this function is called early in Chrome startup
529 // before any threads are created (it will also be called later if the user
530 // changes the pref). In this case, there will be no threads created and
531 // posting will fail. When there are no threads, we can just set the string
532 // without worrying about threadsafety.
533 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
534 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
535 g_io_thread_application_locale.Get() = locale;
536 }
537}
538
[email protected]50462bf02011-11-21 19:13:31539content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
540 const content::MainFunctionParams& parameters) {
541 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30542 // Construct the Main browser parts based on the OS type.
543#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31544 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04545#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31546 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30547#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22548 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26549#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31550 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14551#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09552 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30553#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31554 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04555#else
[email protected]b48c9182011-10-26 18:03:30556 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31557 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30558#endif
559
[email protected]7e75e4a2013-05-17 17:20:03560 chrome::AddProfilesExtraParts(main_parts);
561
[email protected]c7480942011-11-08 19:18:27562 // Construct additional browser parts. Stages are called in the order in
563 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22564#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41565 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04566#endif
[email protected]c7480942011-11-08 19:18:27567
568#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41569 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27570#endif
571
[email protected]dc04be7c2012-03-15 23:57:49572#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41573 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49574#endif
575
[email protected]e050ef142012-03-21 01:04:24576#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41577 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24578#endif
579
[email protected]95132f52013-04-12 02:19:04580 chrome::AddMetricsExtraParts(main_parts);
581
[email protected]50462bf02011-11-21 19:13:31582 return main_parts;
[email protected]f967b722011-09-07 00:58:04583}
584
[email protected]e94bbcb2012-09-07 05:33:57585std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19586 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57587 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53588 std::string partition_id;
589
590 // The partition ID for webview guest processes is the string value of its
591 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
592 if (site.SchemeIs(chrome::kGuestScheme))
593 partition_id = site.spec();
594
[email protected]056efdc2013-04-06 00:14:53595 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53596 return partition_id;
597}
598
599bool ChromeContentBrowserClient::IsValidStoragePartitionId(
600 content::BrowserContext* browser_context,
601 const std::string& partition_id) {
602 // The default ID is empty and is always valid.
603 if (partition_id.empty())
604 return true;
605
606 return GURL(partition_id).is_valid();
607}
608
609void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
610 content::BrowserContext* browser_context,
611 const GURL& site,
[email protected]14acc642012-11-17 12:20:10612 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53613 std::string* partition_domain,
614 std::string* partition_name,
615 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10616 // Default to the browser-wide storage partition and override based on |site|
617 // below.
618 partition_domain->clear();
619 partition_name->clear();
620 *in_memory = false;
621
[email protected]1bc28312012-11-08 08:31:53622 // For the webview tag, we create special guest processes, which host the
623 // tag content separately from the main application that embeds the tag.
624 // A webview tag can specify both the partition name and whether the storage
625 // for that partition should be persisted. Each tag gets a SiteInstance with
626 // a specially formatted URL, based on the application it is hosted by and
627 // the partition requested by it. The format for that URL is:
628 // chrome-guest://partition_domain/persist?partition_name
629 if (site.SchemeIs(chrome::kGuestScheme)) {
630 // Since guest URLs are only used for packaged apps, there must be an app
631 // id in the URL.
632 CHECK(site.has_host());
633 *partition_domain = site.host();
634 // Since persistence is optional, the path must either be empty or the
635 // literal string.
636 *in_memory = (site.path() != "/persist");
637 // The partition name is user supplied value, which we have encoded when the
638 // URL was created, so it needs to be decoded.
639 *partition_name = net::UnescapeURLComponent(site.query(),
640 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10641 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
642 // If |can_be_default| is false, the caller is stating that the |site|
643 // should be parsed as if it had isolated storage. In particular it is
644 // important to NOT check ExtensionService for the is_storage_isolated()
645 // attribute because this code path is run during Extension uninstall
646 // to do cleanup after the Extension has already been unloaded from the
647 // ExtensionService.
648 bool is_isolated = !can_be_default;
649 if (can_be_default) {
650 const Extension* extension = NULL;
651 Profile* profile = Profile::FromBrowserContext(browser_context);
652 ExtensionService* extension_service =
653 extensions::ExtensionSystem::Get(profile)->extension_service();
654 if (extension_service) {
655 extension = extension_service->extensions()->
656 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43657 if (extension &&
658 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10659 is_isolated = true;
660 }
661 }
662 }
[email protected]1bc28312012-11-08 08:31:53663
[email protected]14acc642012-11-17 12:20:10664 if (is_isolated) {
665 CHECK(site.has_host());
666 // For extensions with isolated storage, the the host of the |site| is
667 // the |partition_domain|. The |in_memory| and |partition_name| are only
668 // used in guest schemes so they are cleared here.
669 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53670 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10671 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53672 }
[email protected]d1198fd2012-08-13 22:50:19673 }
674
[email protected]14acc642012-11-17 12:20:10675 // Assert that if |can_be_default| is false, the code above must have found a
676 // non-default partition. If this fails, the caller has a serious logic
677 // error about which StoragePartition they expect to be in and it is not
678 // safe to continue.
679 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44680}
681
[email protected]38b098f2012-03-14 21:11:57682content::WebContentsViewDelegate*
683 ChromeContentBrowserClient::GetWebContentsViewDelegate(
684 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27685 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32686}
687
[email protected]24665682013-02-25 20:59:38688// Check if the extension activity log is enabled for the profile.
689static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33690 // crbug.com/247908 - This should be IsLogEnabled except for an issue
691 // in chrome_frame_net_tests
692 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38693}
694
[email protected]44295a12013-06-05 08:45:46695void ChromeContentBrowserClient::GuestWebContentsAttached(
696 WebContents* guest_web_contents,
697 WebContents* embedder_web_contents,
698 int browser_plugin_instance_id) {
[email protected]44703cc72013-01-24 04:56:06699 Profile* profile = Profile::FromBrowserContext(
700 embedder_web_contents->GetBrowserContext());
701 ExtensionService* service =
702 extensions::ExtensionSystem::Get(profile)->extension_service();
703 if (!service)
704 return;
705 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
706 const Extension* extension = service->extensions()->
707 GetExtensionOrAppByURL(ExtensionURLInfo(url));
708 if (!extension)
709 return;
710 std::vector<ExtensionMsg_Loaded_Params> extensions;
711 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
712 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
[email protected]44295a12013-06-05 08:45:46713 new WebViewGuest(guest_web_contents,
714 embedder_web_contents,
715 extension->id(),
716 browser_plugin_instance_id);
[email protected]44703cc72013-01-24 04:56:06717}
718
[email protected]f3b1a082011-11-18 00:34:30719void ChromeContentBrowserClient::RenderProcessHostCreated(
720 content::RenderProcessHost* host) {
721 int id = host->GetID();
722 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41723 net::URLRequestContextGetter* context =
724 profile->GetRequestContextForRenderProcess(id);
725
[email protected]f3b1a082011-11-18 00:34:30726 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41727 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55728#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30729 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55730#endif
[email protected]658677f2012-06-09 06:04:02731#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08732 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03733#endif
[email protected]f3b1a082011-11-18 00:34:30734 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02735 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30736 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56737#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21738 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56739#endif
[email protected]43535512013-02-20 20:41:41740 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
741 id, profile, context));
[email protected]2736c032012-05-11 18:06:07742 host->GetChannel()->AddFilter(
743 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27744 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33745 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31746#if defined(ENABLE_WEBRTC)
747 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
748#endif
[email protected]3e69bc82011-05-26 23:22:38749
[email protected]2ccf45c2011-08-19 23:35:50750 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
751 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07752
[email protected]24665682013-02-25 20:59:38753 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
754 IsExtensionActivityLogEnabledForProfile(profile)));
755
[email protected]39a5b532011-10-22 01:47:07756 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56757
758 RendererContentSettingRules rules;
759 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
760 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14761}
762
[email protected]95c95552013-05-03 04:21:22763GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
764 content::BrowserContext* browser_context,
765 const GURL& url,
766 bool is_renderer_initiated,
767 content::SiteInstance* current_instance) {
768 Profile* profile = Profile::FromBrowserContext(browser_context);
769 if (!profile)
770 return url;
771
772 // Only return the privileged instant URL if we are entering from a browser-
773 // initiated navigation or if we are already in the instant process.
774 bool is_instant_process = false;
775 int process_id = current_instance->GetProcess()->GetID();
776 InstantService* instant_service =
777 InstantServiceFactory::GetForProfile(profile);
778 if (instant_service)
779 is_instant_process = instant_service->IsInstantProcess(process_id);
780
781 DCHECK_EQ(is_instant_process,
782 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
783 if (!is_renderer_initiated || is_instant_process) {
784 // If the input |url| should be assigned to the Instant renderer, make its
785 // privileged URL distinct from other URLs on the search provider's domain.
786 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
787 return chrome::GetPrivilegedURLForInstant(url, profile);
788 }
789
790 return url;
791}
792
[email protected]3d7474ff2011-07-27 17:47:37793GURL ChromeContentBrowserClient::GetEffectiveURL(
794 content::BrowserContext* browser_context, const GURL& url) {
795 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52796 if (!profile)
797 return url;
798
[email protected]d5bcd06f2013-04-21 08:07:24799#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30800 // If the input |url| should be assigned to the Signin renderer, make its
801 // effective URL distinct from other URLs on the signin service's domain.
802 // Note that the signin renderer will be allowed to sign the user in to
803 // Chrome.
804 if (SigninManager::IsWebBasedSigninFlowURL(url))
805 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24806#endif
[email protected]970c63e2013-03-07 00:25:30807
[email protected]c5dec6292013-01-25 04:54:52808 // If the input |url| is part of an installed app, the effective URL is an
809 // extension URL with the ID of that extension as the host. This has the
810 // effect of grouping apps together in a common SiteInstance.
811 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13812 extensions::ExtensionSystem::Get(profile)->extension_service();
813 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08814 return url;
815
[email protected]06bdd2b2012-11-30 18:47:13816 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44817 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08818 if (!extension)
819 return url;
820
[email protected]15877ca2011-11-18 22:40:52821 // Bookmark apps do not use the hosted app process model, and should be
822 // treated as normal URLs.
823 if (extension->from_bookmark())
824 return url;
825
[email protected]36fb2c7c2011-04-04 15:49:08826 // If the URL is part of an extension's web extent, convert it to an
827 // extension URL.
828 return extension->GetResourceURL(url.path());
829}
830
[email protected]056ad2a2011-07-12 02:13:55831bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37832 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52833 // Non-extension, non-Instant URLs should generally use
834 // process-per-site-instance. Because we expect to use the effective URL,
835 // URLs for hosted apps (apart from bookmark apps) should have an extension
836 // scheme by now.
837
838 Profile* profile = Profile::FromBrowserContext(browser_context);
839 if (!profile)
840 return false;
841
[email protected]165fe422013-03-27 06:34:03842 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52843 return true;
844
[email protected]d5bcd06f2013-04-21 08:07:24845#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30846 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
847 return true;
[email protected]d5bcd06f2013-04-21 08:07:24848#endif
[email protected]970c63e2013-03-07 00:25:30849
[email protected]885c0e92012-11-13 20:27:42850 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55851 return false;
852
[email protected]c5dec6292013-01-25 04:54:52853 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13854 extensions::ExtensionSystem::Get(profile)->extension_service();
855 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55856 return false;
857
[email protected]06bdd2b2012-11-30 18:47:13858 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44859 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55860 if (!extension)
861 return false;
862
863 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53864 // permission, or that does not allow JavaScript access to the background
865 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55866 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40867 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06868 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29869 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53870 return false;
871 }
872 }
[email protected]056ad2a2011-07-12 02:13:55873
[email protected]7b54ca02012-03-02 18:06:53874 // Hosted apps that have script access to their background page must use
875 // process per site, since all instances can make synchronous calls to the
876 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55877 return true;
878}
879
[email protected]672c8c12013-03-07 12:30:06880// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41881void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
882 std::vector<std::string>* additional_schemes) {
883 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06884}
885
[email protected]6bd30072013-02-08 18:17:11886net::URLRequestContextGetter*
887ChromeContentBrowserClient::CreateRequestContext(
888 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06889 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11890 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06891 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11892}
893
894net::URLRequestContextGetter*
895ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
896 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40897 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11898 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06899 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11900 Profile* profile = Profile::FromBrowserContext(browser_context);
901 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06902 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11903}
904
[email protected]46fb9442011-12-09 17:57:47905bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
906 return ProfileIOData::IsHandledURL(url);
907}
908
[email protected]c4365fa42013-05-14 01:08:24909bool ChromeContentBrowserClient::CanCommitURL(
910 content::RenderProcessHost* process_host,
911 const GURL& url) {
912 // We need to let most extension URLs commit in any process, since this can
913 // be allowed due to web_accessible_resources. Most hosted app URLs may also
914 // load in any process (e.g., in an iframe). However, the Chrome Web Store
915 // cannot be loaded in iframes and should never be requested outside its
916 // process.
917 Profile* profile =
918 Profile::FromBrowserContext(process_host->GetBrowserContext());
919 ExtensionService* service =
920 extensions::ExtensionSystem::Get(profile)->extension_service();
921 if (!service)
922 return true;
923 const Extension* new_extension =
924 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
925 if (new_extension &&
926 new_extension->is_hosted_app() &&
927 new_extension->id() == extension_misc::kWebStoreAppId &&
928 !service->process_map()->Contains(new_extension->id(),
929 process_host->GetID())) {
930 return false;
931 }
932
933 return true;
934}
935
[email protected]2a5221b2011-09-27 23:07:31936bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30937 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31938 const GURL& site_url) {
939 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30940 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52941 // This may be NULL during tests. In that case, just assume any site can
942 // share any host.
943 if (!profile)
944 return true;
945
[email protected]d43f99fe2013-04-03 00:20:14946 // Instant URLs should only be in the instant process and instant process
947 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52948 InstantService* instant_service =
949 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14950 if (instant_service) {
951 bool is_instant_process = instant_service->IsInstantProcess(
952 process_host->GetID());
953 bool should_be_in_instant_process =
954 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
955 if (is_instant_process || should_be_in_instant_process)
956 return is_instant_process && should_be_in_instant_process;
957 }
[email protected]c5dec6292013-01-25 04:54:52958
[email protected]d5bcd06f2013-04-21 08:07:24959#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30960 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
961 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
962 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:24963#endif
[email protected]970c63e2013-03-07 00:25:30964
[email protected]06bdd2b2012-11-30 18:47:13965 ExtensionService* service =
966 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46967 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31968
[email protected]ffa97602011-11-17 17:55:52969 // Don't allow the Task Manager to share a process with anything else.
970 // Otherwise it can affect the renderers it is observing.
971 // Note: we could create another RenderProcessHostPrivilege bucket for
972 // this to allow multiple chrome://tasks instances to share, but that's
973 // a very unlikely case without serious consequences.
974 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
975 return false;
976
[email protected]8d3132f62011-10-12 07:13:42977 // These may be NULL during tests. In that case, just assume any site can
978 // share any host.
[email protected]6f371442011-11-09 06:45:46979 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31980 return true;
981
[email protected]eec0b33c2011-12-05 22:09:45982 // Otherwise, just make sure the process privilege matches the privilege
983 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57984 RenderProcessHostPrivilege privilege_required =
985 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45986 return GetProcessPrivilege(process_host, process_map, service) ==
987 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31988}
989
[email protected]76411f412012-02-22 18:56:06990// This function is trying to limit the amount of processes used by extensions
991// with background pages. It uses a globally set percentage of processes to
992// run such extensions and if the limit is exceeded, it returns true, to
993// indicate to the content module to group extensions together.
994bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
995 content::BrowserContext* browser_context, const GURL& url) {
996 // It has to be a valid URL for us to check for an extension.
997 if (!url.is_valid())
998 return false;
999
1000 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191001 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131002 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061003 if (!service)
1004 return false;
1005
1006 // We have to have a valid extension with background page to proceed.
1007 const Extension* extension =
1008 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
1009 if (!extension)
1010 return false;
[email protected]9367eabc2013-03-01 01:29:291011 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061012 return false;
1013
1014 std::set<int> process_ids;
1015 size_t max_process_count =
1016 content::RenderProcessHost::GetMaxRendererProcessCount();
1017
1018 // Go through all profiles to ensure we have total count of extension
1019 // processes containing background pages, otherwise one profile can
1020 // starve the other.
1021 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1022 GetLoadedProfiles();
1023 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031024 ExtensionProcessManager* epm =
1025 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321026 for (ExtensionProcessManager::const_iterator iter =
1027 epm->background_hosts().begin();
1028 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131029 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321030 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061031 }
1032 }
1033
1034 if (process_ids.size() >
1035 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1036 return true;
1037 }
1038
1039 return false;
1040}
1041
[email protected]6f371442011-11-09 06:45:461042void ChromeContentBrowserClient::SiteInstanceGotProcess(
1043 SiteInstance* site_instance) {
1044 CHECK(site_instance->HasProcess());
1045
1046 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021047 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521048 if (!profile)
1049 return;
1050
1051 // Remember the ID of the Instant process to signal the renderer process
1052 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031053 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321054 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521055 InstantService* instant_service =
1056 InstantServiceFactory::GetForProfile(profile);
1057 if (instant_service)
1058 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1059 }
1060
[email protected]d5bcd06f2013-04-21 08:07:241061#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301062 // We only expect there to be one signin process as we use process-per-site
1063 // for signin URLs. The signin process will be cleared from SigninManager
1064 // when the renderer is destroyed.
1065 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1066 SigninManager* signin_manager =
1067 SigninManagerFactory::GetForProfile(profile);
1068 if (signin_manager)
1069 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461070 BrowserThread::PostTask(
1071 BrowserThread::IO, FROM_HERE,
1072 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1073 extensions::ExtensionSystem::Get(profile)->info_map(),
1074 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301075 }
[email protected]d5bcd06f2013-04-21 08:07:241076#endif
[email protected]970c63e2013-03-07 00:25:301077
[email protected]06bdd2b2012-11-30 18:47:131078 ExtensionService* service =
1079 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461080 if (!service)
1081 return;
1082
1083 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441084 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591085 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461086 if (!extension)
1087 return;
1088
[email protected]6bc04fd82011-12-04 02:29:351089 service->process_map()->Insert(extension->id(),
1090 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331091 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461092 BrowserThread::PostTask(
1093 BrowserThread::IO, FROM_HERE,
1094 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591095 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461096 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351097 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331098 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461099}
1100
1101void ChromeContentBrowserClient::SiteInstanceDeleting(
1102 SiteInstance* site_instance) {
1103 if (!site_instance->HasProcess())
1104 return;
1105
1106 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021107 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131108 ExtensionService* service =
1109 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461110 if (!service)
1111 return;
1112
1113 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441114 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591115 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461116 if (!extension)
1117 return;
1118
[email protected]6bc04fd82011-12-04 02:29:351119 service->process_map()->Remove(extension->id(),
1120 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331121 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461122 BrowserThread::PostTask(
1123 BrowserThread::IO, FROM_HERE,
1124 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591125 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461126 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351127 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331128 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461129}
1130
[email protected]f05763972012-06-06 18:17:261131bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141132 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081133 const GURL& current_url,
1134 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261135 if (current_url.is_empty()) {
1136 // Always choose a new process when navigating to extension URLs. The
1137 // process grouping logic will combine all of a given extension's pages
1138 // into the same process.
[email protected]885c0e92012-11-13 20:27:421139 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261140 return true;
[email protected]e3daf3c2011-10-05 21:17:081141
[email protected]f05763972012-06-06 18:17:261142 return false;
1143 }
1144
1145 // Also, we must switch if one is an extension and the other is not the exact
1146 // same extension.
[email protected]885c0e92012-11-13 20:27:421147 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1148 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261149 if (current_url.GetOrigin() != new_url.GetOrigin())
1150 return true;
1151 }
1152
[email protected]e9841fbd2013-02-22 23:12:141153 // The checks below only matter if we can retrieve which extensions are
1154 // installed.
1155 Profile* profile =
1156 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1157 ExtensionService* service =
1158 extensions::ExtensionSystem::Get(profile)->extension_service();
1159 if (!service)
1160 return false;
1161
1162 // We must swap if the URL is for an extension and we are not using an
1163 // extension process.
1164 const Extension* new_extension =
1165 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1166 // Ignore all hosted apps except the Chrome Web Store, since they do not
1167 // require their own BrowsingInstance (e.g., postMessage is ok).
1168 if (new_extension &&
1169 new_extension->is_hosted_app() &&
1170 new_extension->id() != extension_misc::kWebStoreAppId)
1171 new_extension = NULL;
1172 if (new_extension &&
1173 site_instance->HasProcess() &&
1174 !service->process_map()->Contains(new_extension->id(),
1175 site_instance->GetProcess()->GetID()))
1176 return true;
1177
[email protected]f05763972012-06-06 18:17:261178 return false;
[email protected]e3daf3c2011-10-05 21:17:081179}
1180
[email protected]395045c2012-05-22 15:04:381181bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1182 content::ResourceContext* resource_context, const GURL& current_url,
1183 const GURL& new_url) {
1184 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1185 return extensions::CrossesExtensionProcessBoundary(
1186 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171187 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381188}
1189
[email protected]763ec4ca2011-04-29 15:48:121190std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1191 const std::string& alias_name) {
1192 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1193}
1194
[email protected]b80f68432011-05-02 17:22:301195void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1196 CommandLine* command_line, int child_process_id) {
1197#if defined(USE_LINUX_BREAKPAD)
1198 if (IsCrashReporterEnabled()) {
1199 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1200 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1201 }
1202#elif defined(OS_MACOSX)
1203 if (IsCrashReporterEnabled()) {
1204 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1205 child_process_logging::GetClientId());
1206 }
1207#endif // OS_MACOSX
1208
[email protected]f1933792011-06-14 00:49:341209 if (logging::DialogsAreSuppressed())
1210 command_line->AppendSwitch(switches::kNoErrorDialogs);
1211
[email protected]b80f68432011-05-02 17:22:301212 std::string process_type =
1213 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171214 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321215
1216 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1217 command_line->AppendSwitch(switches::kChromeFrame);
1218
[email protected]718eab62011-10-05 21:16:521219 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451220 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301221 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1222 if (!user_data_dir.empty())
1223 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1224#if defined(OS_CHROMEOS)
1225 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441226 browser_command_line.GetSwitchValueASCII(
1227 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301228 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441229 command_line->AppendSwitchASCII(
1230 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301231#endif
1232
[email protected]f3b1a082011-11-18 00:34:301233 content::RenderProcessHost* process =
1234 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371235 if (process) {
1236 Profile* profile = Profile::FromBrowserContext(
1237 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131238 ExtensionService* extension_service =
1239 extensions::ExtensionSystem::Get(profile)->extension_service();
1240 if (extension_service) {
1241 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001242 if (process_map && process_map->Contains(process->GetID()))
1243 command_line->AppendSwitch(switches::kExtensionProcess);
1244 }
[email protected]b80f68432011-05-02 17:22:301245
[email protected]a8d851f82011-12-21 00:32:371246 PrefService* prefs = profile->GetPrefs();
1247 // Currently this pref is only registered if applied via a policy.
1248 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1249 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1250 // Turn this policy into a command line switch.
1251 command_line->AppendSwitch(switches::kDisable3DAPIs);
1252 }
[email protected]718eab62011-10-05 21:16:521253
[email protected]a8d851f82011-12-21 00:32:371254 // Disable client-side phishing detection in the renderer if it is
1255 // disabled in the Profile preferences or the browser process.
1256 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1257 !g_browser_process->safe_browsing_detection_service()) {
1258 command_line->AppendSwitch(
1259 switches::kDisableClientSidePhishingDetection);
1260 }
[email protected]0045b0f42012-07-26 11:52:081261
1262 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211263 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521264
1265 InstantService* instant_service =
1266 InstantServiceFactory::GetForProfile(profile);
1267 if (instant_service &&
1268 instant_service->IsInstantProcess(process->GetID()))
1269 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301270
[email protected]d5bcd06f2013-04-21 08:07:241271#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301272 SigninManager* signin_manager =
1273 SigninManagerFactory::GetForProfile(profile);
1274 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1275 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241276#endif
[email protected]47c7ec82012-01-18 03:29:211277 }
[email protected]4287a3d2011-06-13 23:56:511278
[email protected]87552982012-11-02 17:21:401279 if (content::IsThreadedCompositingEnabled())
1280 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1281
[email protected]16dc42452013-04-09 04:37:191282 if (message_center::IsRichNotificationEnabled())
1283 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191284
[email protected]47c7ec82012-01-18 03:29:211285 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511286 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171287 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481288 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171289 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511290 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481291 switches::kAllowLegacyExtensionManifests,
[email protected]9d450492013-06-13 23:08:371292 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1293 // to browser.
1294 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511295 switches::kAllowScriptingGallery,
1296 switches::kAppsCheckoutURL,
1297 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311298 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511299 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501300 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531301 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111302 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531303 switches::kEnableAdview,
1304 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211305 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511306 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511307 switches::kEnableIPCFuzzing,
1308 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451309 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481310 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051311 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511312 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291313 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511314 switches::kMemoryProfiling,
1315 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371316 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371317 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511318 switches::kPpapiFlashArgs,
1319 switches::kPpapiFlashInProcess,
1320 switches::kPpapiFlashPath,
1321 switches::kPpapiFlashVersion,
1322 switches::kProfilingAtStart,
1323 switches::kProfilingFile,
1324 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371325 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511326 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291327 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381328 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511329 };
1330
1331 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1332 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171333 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381334 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351335 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381336 switches::kEnableExperimentalExtensionApis,
1337 switches::kWhitelistedExtensionID,
1338 };
1339
1340 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1341 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511342 } else if (process_type == switches::kPluginProcess) {
1343 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441344#if defined(OS_CHROMEOS)
1345 chromeos::switches::kLoginProfile,
1346#endif
[email protected]4287a3d2011-06-13 23:56:511347 switches::kMemoryProfiling,
1348 switches::kSilentDumpOnDCHECK,
1349 switches::kUserDataDir,
1350 };
1351
1352 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1353 arraysize(kSwitchNames));
1354 } else if (process_type == switches::kZygoteProcess) {
1355 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511356 switches::kUserDataDir, // Make logs go to the right file.
1357 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501358 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511359 switches::kPpapiFlashInProcess,
1360 switches::kPpapiFlashPath,
1361 switches::kPpapiFlashVersion,
1362 };
1363
1364 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1365 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111366 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001367 base::FilePath user_data_dir =
1368 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1369 if (!user_data_dir.empty())
1370 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111371 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1372 // because GPU is expected to be unreliable.
1373 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1374 !command_line->HasSwitch(switches::kDisableBreakpad))
1375 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301376 }
[email protected]6f08af82011-09-15 01:19:031377
1378 // The command line switch kEnableBenchmarking needs to be specified along
1379 // with the kEnableStatsTable switch to ensure that the stats table global
1380 // is initialized correctly.
1381 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1382 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301383}
1384
1385std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431386 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351387 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301388 return g_browser_process->GetApplicationLocale();
1389}
1390
[email protected]597a867b2011-11-18 18:31:201391std::string ChromeContentBrowserClient::GetAcceptLangs(
1392 content::BrowserContext* context) {
1393 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371394 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081395}
1396
[email protected]9ec0f452012-05-31 15:58:531397gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221398 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531399 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081400}
1401
[email protected]a2176792011-05-08 19:30:491402bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091403 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191404 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201405 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201407 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051408 return io_data->GetCookieSettings()->
1409 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491410}
1411
[email protected]ed24fad2011-05-10 22:44:011412bool ChromeContentBrowserClient::AllowGetCookie(
1413 const GURL& url,
1414 const GURL& first_party,
1415 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201416 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011417 int render_process_id,
1418 int render_view_id) {
1419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201420 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051421 bool allow = io_data->GetCookieSettings()->
1422 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011423
[email protected]8093a542011-05-13 07:29:321424 BrowserThread::PostTask(
1425 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031426 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431427 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011428 return allow;
1429}
1430
1431bool ChromeContentBrowserClient::AllowSetCookie(
1432 const GURL& url,
1433 const GURL& first_party,
1434 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201435 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011436 int render_process_id,
1437 int render_view_id,
1438 net::CookieOptions* options) {
1439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201440 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051441 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1442 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1443
[email protected]8093a542011-05-13 07:29:321444 BrowserThread::PostTask(
1445 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031446 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431447 render_view_id, url, first_party, cookie_line, *options,
1448 !allow));
[email protected]ed24fad2011-05-10 22:44:011449 return allow;
1450}
1451
[email protected]d5a19162011-06-30 18:51:541452bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201453 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541454 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201455 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431456 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1457 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261458
[email protected]bf510ed2012-06-05 08:31:431459 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1460 // Could we even support per-origin settings?
1461 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541462}
1463
[email protected]5c5a88e2011-11-12 00:45:351464bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351465 const GURL& url,
1466 const string16& name,
1467 const string16& display_name,
1468 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201469 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481470 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201472 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351473 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1474 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1475
[email protected]62151052012-02-01 18:40:481476 // Record access to database for potential display in UI.
1477 std::vector<std::pair<int, int> >::const_iterator i;
1478 for (i = render_views.begin(); i != render_views.end(); ++i) {
1479 BrowserThread::PostTask(
1480 BrowserThread::UI, FROM_HERE,
1481 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1482 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351483 }
1484
1485 return allow;
1486}
1487
1488bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351489 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201490 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481491 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201493 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351494 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1495 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1496
[email protected]62151052012-02-01 18:40:481497 // Record access to file system for potential display in UI.
1498 std::vector<std::pair<int, int> >::const_iterator i;
1499 for (i = render_views.begin(); i != render_views.end(); ++i) {
1500 BrowserThread::PostTask(
1501 BrowserThread::UI, FROM_HERE,
1502 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1503 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351504 }
1505
1506 return allow;
1507}
1508
[email protected]7c5ff9a2012-03-02 07:42:491509bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1510 const GURL& url,
1511 const string16& name,
1512 content::ResourceContext* context,
1513 const std::vector<std::pair<int, int> >& render_views) {
1514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1515 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1516 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1517 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1518
1519 // Record access to IndexedDB for potential display in UI.
1520 std::vector<std::pair<int, int> >::const_iterator i;
1521 for (i = render_views.begin(); i != render_views.end(); ++i) {
1522 BrowserThread::PostTask(
1523 BrowserThread::UI, FROM_HERE,
1524 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1525 i->first, i->second, url, name, !allow));
1526 }
1527
1528 return allow;
1529}
1530
[email protected]6133f922011-07-01 21:34:341531net::URLRequestContext*
1532ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201533 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421535 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201536 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341537 return io_data->extensions_request_context();
1538 }
1539
1540 return NULL;
1541}
1542
[email protected]317f96c92011-05-31 06:53:411543QuotaPermissionContext*
1544ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1545 return new ChromeQuotaPermissionContext();
1546}
1547
[email protected]848dd042011-06-04 18:24:031548void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171549 int render_process_id,
1550 int render_view_id,
1551 int cert_error,
1552 const net::SSLInfo& ssl_info,
1553 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021554 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031555 bool overridable,
[email protected]d9be47702012-05-16 03:41:221556 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171557 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001558 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021559 if (resource_type != ResourceType::MAIN_FRAME) {
1560 // A sub-resource has a certificate error. The user doesn't really
1561 // have a context for making the right decision, so block the
1562 // request hard, without an info bar to allow showing the insecure
1563 // content.
[email protected]8c965c22013-05-23 19:28:001564 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021565 return;
1566 }
1567
[email protected]f9034cf2011-07-21 12:43:411568 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131569 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171570 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411571 if (!tab) {
1572 NOTREACHED();
1573 return;
1574 }
1575 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501576 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301577 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011578 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1579 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411580 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171581 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411582 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001583 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411584 return;
1585 }
1586 }
1587
[email protected]1e87df32012-09-12 04:53:191588#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231589 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1590 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1591 if (captive_portal_tab_helper)
1592 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191593#endif
1594
[email protected]f9034cf2011-07-21 12:43:411595 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221596 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1597 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031598}
1599
[email protected]c99c442e2011-08-24 11:37:301600void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451601 int render_process_id,
1602 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401603 const net::HttpNetworkSession* network_session,
1604 net::SSLCertRequestInfo* cert_request_info,
1605 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131606 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451607 render_process_id, render_view_id);
1608 if (!tab) {
1609 NOTREACHED();
1610 return;
1611 }
1612
[email protected]6786bf402011-12-03 15:19:451613 GURL requesting_url("https://" + cert_request_info->host_and_port);
1614 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1615 << cert_request_info->host_and_port;
1616
[email protected]627e0512011-12-21 22:55:301617 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451618 scoped_ptr<Value> filter(
1619 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1620 requesting_url,
1621 requesting_url,
1622 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1623 std::string(), NULL));
1624
1625 if (filter.get()) {
1626 // Try to automatically select a client certificate.
1627 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1628 DictionaryValue* filter_dict =
1629 static_cast<DictionaryValue*>(filter.get());
1630
1631 const std::vector<scoped_refptr<net::X509Certificate> >&
1632 all_client_certs = cert_request_info->client_certs;
1633 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091634 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451635 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091636 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451637 return;
1638 }
1639 }
1640 } else {
1641 NOTREACHED();
1642 }
1643 }
1644
[email protected]11feec322012-09-18 03:58:521645 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1646 if (!ssl_tab_helper) {
1647 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451648 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141649 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401650 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451651 return;
1652 }
[email protected]11feec322012-09-18 03:58:521653 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401654 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451655}
1656
[email protected]3b455502012-12-11 18:22:581657void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451658 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581659 net::CertificateMimeType cert_type,
1660 const void* cert_data,
1661 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451662 int render_process_id,
1663 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581664 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1665 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451666}
1667
[email protected]dc73a7b2012-03-25 15:27:181668content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561669 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181670}
1671
[email protected]941623e2011-06-07 23:06:041672void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1673 const GURL& source_origin,
1674 int callback_context,
1675 int render_process_id,
1676 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111677#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021678 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1679 WebContents* contents =
1680 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1681 if (!contents) {
[email protected]941623e2011-06-07 23:06:041682 NOTREACHED();
1683 return;
1684 }
1685
[email protected]d0d9c3ee2012-06-19 03:07:021686 // Skip showing the infobar if the request comes from an extension, and that
1687 // extension has the 'notify' permission. (If the extension does not have the
1688 // permission, the user will still be prompted.)
1689 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011690 ExtensionInfoMap* extension_info_map =
1691 extensions::ExtensionSystem::Get(profile)->info_map();
1692 DesktopNotificationService* notification_service =
1693 DesktopNotificationServiceFactory::GetForProfile(profile);
1694 const Extension* extension = NULL;
1695 if (extension_info_map) {
1696 ExtensionSet extensions;
1697 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1698 source_origin, render_process_id,
1699 extensions::APIPermission::kNotification, &extensions);
1700 for (ExtensionSet::const_iterator iter = extensions.begin();
1701 iter != extensions.end(); ++iter) {
1702 if (notification_service->IsExtensionEnabled((*iter)->id())) {
[email protected]cadac622013-06-11 16:46:361703 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011704 break;
1705 }
1706 }
1707 }
[email protected]eb4832a2012-12-08 01:57:521708 RenderViewHost* rvh =
1709 RenderViewHost::FromID(render_process_id, render_view_id);
1710 if (IsExtensionWithPermissionOrSuggestInConsole(
1711 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021712 if (rvh)
1713 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1714 return;
1715 }
1716
[email protected]c7cd5942013-04-30 03:31:011717 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021718 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111719#else
1720 NOTIMPLEMENTED();
1721#endif
[email protected]941623e2011-06-07 23:06:041722}
1723
1724WebKit::WebNotificationPresenter::Permission
1725 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021726 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201727 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021728 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111729#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041730 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201731 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041732
[email protected]c7cd5942013-04-30 03:31:011733 DesktopNotificationService* notification_service =
1734 io_data->GetNotificationService();
1735 if (notification_service) {
1736 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1737 ExtensionSet extensions;
1738 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1739 source_origin, render_process_id,
1740 extensions::APIPermission::kNotification, &extensions);
1741 for (ExtensionSet::const_iterator iter = extensions.begin();
1742 iter != extensions.end(); ++iter) {
1743 if (notification_service->IsExtensionEnabled((*iter)->id()))
1744 return WebKit::WebNotificationPresenter::PermissionAllowed;
1745 }
1746
1747 return notification_service->HasPermission(source_origin);
1748 }
1749
1750 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111751#else
1752 return WebKit::WebNotificationPresenter::PermissionAllowed;
1753#endif
[email protected]941623e2011-06-07 23:06:041754}
1755
1756void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171757 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041758 int render_process_id,
1759 int render_view_id,
1760 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111761#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041762 RenderViewHost* rvh = RenderViewHost::FromID(
1763 render_process_id, render_view_id);
1764 if (!rvh) {
1765 NOTREACHED();
1766 return;
1767 }
1768
[email protected]9f76c1e2012-03-05 15:15:581769 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301770 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041771 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371772 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041773 service->ShowDesktopNotification(
1774 params, render_process_id, render_view_id,
1775 worker ? DesktopNotificationService::WorkerNotification :
1776 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111777#else
1778 NOTIMPLEMENTED();
1779#endif
[email protected]941623e2011-06-07 23:06:041780}
1781
1782void ChromeContentBrowserClient::CancelDesktopNotification(
1783 int render_process_id,
1784 int render_view_id,
1785 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111786#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041787 RenderViewHost* rvh = RenderViewHost::FromID(
1788 render_process_id, render_view_id);
1789 if (!rvh) {
1790 NOTREACHED();
1791 return;
1792 }
1793
[email protected]9f76c1e2012-03-05 15:15:581794 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301795 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041796 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371797 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041798 service->CancelDesktopNotification(
1799 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111800#else
1801 NOTIMPLEMENTED();
1802#endif
[email protected]941623e2011-06-07 23:06:041803}
1804
[email protected]9f3fba52011-06-08 20:37:191805bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351806 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021807 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191808 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201809 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011810 int render_process_id,
1811 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191812 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011813
1814 *no_javascript_access = false;
1815
[email protected]9f3fba52011-06-08 20:37:191816 // If the opener is trying to create a background window but doesn't have
1817 // the appropriate permission, fail the attempt.
1818 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201819 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531820 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1821
[email protected]03b6d552012-03-29 04:03:011822 if (!map->SecurityOriginHasAPIPermission(
1823 source_origin,
1824 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061825 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011826 return false;
1827 }
1828
[email protected]7b54ca02012-03-02 18:06:531829 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1830 // return a recently installed Extension even if this CanCreateWindow call
1831 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011832 // because the permission check above would have caused an early return
1833 // already. We must use the full URL to find hosted apps, though, and not
1834 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531835 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351836 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291837 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011838 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191839 }
[email protected]056efdc2013-04-06 00:14:531840
1841 // No new browser window (popup or tab) in app mode.
1842 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1843 chrome::IsRunningInForcedAppMode()) {
1844 return false;
1845 }
1846
[email protected]9f3fba52011-06-08 20:37:191847 return true;
1848}
1849
1850std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201851 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191852 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1853 // Check if it's an extension-created worker, in which case we want to use
1854 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201855 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191856 const Extension* extension =
1857 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1858 return extension ? extension->name() : std::string();
1859}
1860
[email protected]99907362012-01-11 05:41:401861void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1862 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171863}
1864
[email protected]7a06d282013-05-03 04:39:331865// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021866content::SpeechRecognitionManagerDelegate*
1867 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]3bd0aab2013-05-30 20:07:491868#if !defined(OS_ANDROID)
[email protected]c52b2892012-03-07 11:01:021869 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321870#else
[email protected]3bd0aab2013-05-30 20:07:491871 // TODO(janx): Implement speech::AndroidSpeechRecognitionManagerDelegate
1872 // (see crbug.com/222352).
[email protected]a03f2d32012-03-14 00:26:321873 return NULL;
1874#endif
[email protected]66cfec62012-02-24 17:57:511875}
1876
[email protected]ae6e9912011-07-27 01:18:281877net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1878 return g_browser_process->net_log();
1879}
1880
[email protected]32538d92011-08-25 00:09:231881AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1882 return new ChromeAccessTokenStore();
1883}
1884
[email protected]dbae6b02011-06-29 23:51:411885bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011886 return true;
[email protected]dbae6b02011-06-29 23:51:411887}
1888
[email protected]64d69de42012-02-06 00:19:541889void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321890 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061891 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581892 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061893 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061894
[email protected]f3986f82012-01-03 20:00:061895 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541896 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061897 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541898 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061899 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541900 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061901 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541902 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061903 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541904 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061905 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541906 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031907 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1908 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061909
[email protected]64d69de42012-02-06 00:19:541910 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401911 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541912 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401913 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541914 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401915 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541916 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401917 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061918
[email protected]ddf72142012-05-22 04:52:401919 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061920
[email protected]64d69de42012-02-06 00:19:541921 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401922 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541923 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061924 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541925 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061926 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1927 const DictionaryValue* inspector_settings =
1928 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1929 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181930 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1931 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061932 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181933 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541934 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181935 std::make_pair(iter.key(), value));
1936 }
[email protected]f3986f82012-01-03 20:00:061937 }
1938 }
[email protected]64d69de42012-02-06 00:19:541939 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061940
[email protected]ddf72142012-05-22 04:52:401941 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541942 web_prefs->javascript_enabled = false;
1943 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1944 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401945 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541946 web_prefs->plugins_enabled = false;
1947 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1948 web_prefs->java_enabled = false;
1949 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401950 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061951
[email protected]64d69de42012-02-06 00:19:541952 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1953 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061954
[email protected]64d69de42012-02-06 00:19:541955 web_prefs->memory_info_enabled =
1956 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1957 web_prefs->allow_displaying_insecure_content =
1958 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1959 web_prefs->allow_running_insecure_content =
1960 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321961#if defined(OS_ANDROID)
1962 web_prefs->font_scale_factor =
1963 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1964 web_prefs->force_enable_zoom =
1965 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451966#if defined(GOOGLE_TV)
1967 web_prefs->user_gesture_required_for_media_playback = false;
1968#endif
[email protected]d3b935f2012-10-19 23:14:321969#endif
[email protected]5c915252013-05-07 13:15:391970
[email protected]af4256d52013-06-04 20:39:071971#if defined(OS_ANDROID)
1972 web_prefs->password_echo_enabled =
1973 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
1974#else
[email protected]9d06d88d2012-02-23 22:37:081975 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:071976#endif
1977
[email protected]5c915252013-05-07 13:15:391978#if defined(OS_CHROMEOS)
1979 // Enable password echo during OOBE when keyboard driven flag is set.
1980 if (chromeos::UserManager::IsInitialized() &&
1981 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
1982 !chromeos::StartupUtils::IsOobeCompleted()) {
1983 bool keyboard_driven_oobe = false;
1984 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]e8f3f9982013-05-10 20:59:531985 chromeos::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:391986 if (keyboard_driven_oobe)
1987 web_prefs->password_echo_enabled = true;
1988 }
1989#endif
[email protected]f3986f82012-01-03 20:00:061990
[email protected]46f8e742013-05-03 18:37:141991#if defined(OS_ANDROID)
1992 web_prefs->user_style_sheet_enabled = false;
1993#else
[email protected]64d69de42012-02-06 00:19:541994 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151995 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:361996 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:151997 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541998 web_prefs->user_style_sheet_enabled = true;
1999 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152000 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542001 } else {
2002 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062003 }
[email protected]46f8e742013-05-03 18:37:142004#endif
[email protected]f3986f82012-01-03 20:00:062005
[email protected]cfadadd2013-04-03 04:43:022006 web_prefs->asynchronous_spell_checking_enabled = true;
2007 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572008
[email protected]64d69de42012-02-06 00:19:542009 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062010 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542011 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062012 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542013 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062014 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2015
2016 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542017 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062018 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542019 web_prefs->default_encoding);
2020 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402021 prefs->ClearPref(prefs::kDefaultCharset);
2022 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062023 }
[email protected]64d69de42012-02-06 00:19:542024 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062025
[email protected]88ecf66d2012-12-11 22:53:472026 if (content::IsForceCompositingModeEnabled())
2027 web_prefs->force_compositing_mode = true;
2028
[email protected]299d7f12012-05-23 05:31:152029 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232030 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132031 ExtensionService* service =
2032 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062033 if (service) {
[email protected]1bc28312012-11-08 08:31:532034 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2035 const Extension* extension = service->extensions()->GetByID(url.host());
2036 // Ensure that we are only granting extension preferences to URLs with
2037 // the correct scheme. Without this check, chrome-guest:// schemes used by
2038 // webview tags as well as hosts that happen to match the id of an
2039 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422040 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532041 extension_webkit_preferences::SetPreferences(
2042 extension, view_type, web_prefs);
2043 }
[email protected]f3986f82012-01-03 20:00:062044 }
2045
[email protected]cb2edf22013-04-01 20:25:232046 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542047 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232048 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062049 // Disable all kinds of acceleration for background pages.
2050 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542051 web_prefs->force_compositing_mode = false;
2052 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062053 }
[email protected]2e21fe292012-03-02 22:52:322054
2055#if defined(FILE_MANAGER_EXTENSION)
2056 // Override the default of suppressing HW compositing for WebUI pages for the
2057 // file manager, which is implemented using WebUI but wants HW acceleration
2058 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532059 if (url.SchemeIs(extensions::kExtensionScheme) &&
2060 url.host() == kFileBrowserDomain) {
[email protected]2e21fe292012-03-02 22:52:322061 web_prefs->accelerated_compositing_enabled = true;
2062 web_prefs->accelerated_2d_canvas_enabled = true;
2063 }
2064#endif
[email protected]181a95ee2011-07-12 19:26:362065}
2066
2067void ChromeContentBrowserClient::UpdateInspectorSetting(
2068 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062069 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582070 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062071 DictionaryPrefUpdate update(
2072 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2073 prefs::kWebKitInspectorSettings);
2074 DictionaryValue* inspector_settings = update.Get();
2075 inspector_settings->SetWithoutPathExpansion(key,
2076 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362077}
2078
[email protected]b8148ac2011-07-13 22:03:252079void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2080 BrowserURLHandler* handler) {
2081 // Add the default URL handlers.
2082 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2083 BrowserURLHandler::null_handler());
2084 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2085 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2086
[email protected]b3adbd02011-11-30 22:23:272087 // about: handler. Must come before chrome: handler, since it will
2088 // rewrite about: urls to chrome: URLs and then expect chrome: to
2089 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252090 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2091 BrowserURLHandler::null_handler());
2092 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242093 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252094}
2095
2096void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372097 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582098 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472099 BrowsingDataRemover* remover =
2100 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552101 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2102 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252103 // BrowsingDataRemover takes care of deleting itself when done.
2104}
2105
2106void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372107 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582108 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472109 BrowsingDataRemover* remover =
2110 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232111 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552112 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252113 // BrowsingDataRemover takes care of deleting itself when done.
2114}
2115
[email protected]650b2d52013-02-10 03:41:452116base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322117 return download_util::GetDefaultDownloadDirectory();
2118}
2119
[email protected]c9b6eb62011-10-18 20:49:392120std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2121 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2122}
2123
[email protected]b7631cc2012-09-15 05:08:382124void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2125 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542126#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382127 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2128 scoped_ptr<ppapi::host::HostFactory>(
2129 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542130#endif
[email protected]b7631cc2012-09-15 05:08:382131}
2132
[email protected]0c7193742012-11-07 19:05:032133content::BrowserPpapiHost*
2134 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2135 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132136 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032137 while (!iter.Done()) {
2138 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2139 if (host->process() &&
2140 host->process()->GetData().id == plugin_process_id) {
2141 // Found the plugin.
2142 return host->browser_ppapi_host();
2143 }
2144 ++iter;
2145 }
2146 return NULL;
2147}
2148
[email protected]7b38b192013-03-23 18:39:312149bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2150 content::BrowserContext* browser_context, const GURL& site_url) {
2151 if (CommandLine::ForCurrentProcess()->HasSwitch(
2152 switches::kEnableBrowserPluginForAllViewTypes))
2153 return true;
2154
2155 Profile* profile = Profile::FromBrowserContext(browser_context);
2156 ExtensionService* service =
2157 extensions::ExtensionSystem::Get(profile)->extension_service();
2158 if (!service)
2159 return false;
2160
2161 const Extension* extension = service->extensions()->
2162 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2163 if (!extension)
2164 return false;
2165
[email protected]c2d2f102013-04-29 16:42:582166 return extension->HasAPIPermission(APIPermission::kWebView) ||
2167 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312168}
2169
[email protected]38cd8f7f2012-06-15 22:06:072170bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582171 content::BrowserContext* browser_context,
2172 const GURL& url,
[email protected]dda54822013-06-15 01:26:392173 bool private_api,
[email protected]157cc902012-11-02 06:31:582174 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402175#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372176 Profile* profile = Profile::FromBrowserContext(browser_context);
2177 const ExtensionSet* extension_set = NULL;
2178 if (profile) {
2179 extension_set = extensions::ExtensionSystem::Get(profile)->
2180 extension_service()->extensions();
2181 }
[email protected]dda54822013-06-15 01:26:392182
2183 if (private_api) {
2184 // Access to private socket APIs is controlled by the whitelist.
2185 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2186 allowed_socket_origins_)) {
2187 return true;
2188 }
2189 } else {
2190 // Access to public socket APIs is controlled by extension permissions.
2191 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2192 extension_set) {
2193 const Extension* extension = extension_set->GetByID(url.host());
2194 if (extension) {
2195 extensions::SocketPermission::CheckParam check_params(
2196 params.type, params.host, params.port);
2197 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2198 extension, extensions::APIPermission::kSocket, &check_params)) {
2199 return true;
2200 }
2201 }
2202 }
2203 }
2204
2205 // Allow both public and private APIs if the command line says so.
2206 return IsHostAllowedByCommandLine(url, extension_set,
2207 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402208#else
[email protected]a658d452012-03-02 12:45:292209 return false;
[email protected]93f72062013-05-29 20:29:402210#endif
[email protected]e461da2f2012-02-16 19:06:402211}
2212
[email protected]650b2d52013-02-10 03:41:452213base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2214 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142215 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2216 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2217}
2218
[email protected]a28e3302013-02-03 03:50:432219ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2220 WebContents* web_contents) {
2221 return new ChromeSelectFilePolicy(web_contents);
2222}
2223
[email protected]7d9424702013-04-14 13:14:162224void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2225 std::vector<std::string>* additional_allowed_schemes) {
2226 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2227 additional_allowed_schemes);
2228 additional_allowed_schemes->push_back(kChromeUIScheme);
2229 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2230}
2231
[email protected]02250952013-04-24 23:52:532232void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2233 const base::FilePath& storage_partition_path,
2234 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2235#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032236 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]02250952013-04-24 23:52:532237 additional_providers->push_back(new MediaFileSystemMountPointProvider(
[email protected]30a306f42013-06-10 03:09:032238 storage_partition_path,
2239 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]e66f02632013-06-13 22:51:502240 MediaFileSystemMountPointProvider::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532241#endif
2242}
2243
[email protected]e60c0232011-11-11 19:56:352244#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182245void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2246 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382247 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082248 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392249#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452250 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392251 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2252 DCHECK(!data_path.empty());
2253
2254 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452255 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392256 base::PlatformFile f =
2257 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2258 DCHECK(f != base::kInvalidPlatformFileValue);
2259 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2260 FileDescriptor(f, true)));
2261
[email protected]650b2d52013-02-10 03:41:452262 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392263 data_path.AppendASCII("chrome_100_percent.pak");
2264 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2265 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372266 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392267 FileDescriptor(f, true)));
2268
2269 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452270 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392271 GetLocaleFilePath(locale, false);
2272 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2273 DCHECK(f != base::kInvalidPlatformFileValue);
2274 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2275 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382276
[email protected]650b2d52013-02-10 03:41:452277 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372278 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2279 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2280 DCHECK(f != base::kInvalidPlatformFileValue);
2281 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2282 FileDescriptor(f, true)));
2283
[email protected]40da3e0c2012-10-24 22:03:382284#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432285 if (IsCrashReporterEnabled()) {
2286 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2287 if (f == base::kInvalidPlatformFileValue) {
2288 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2289 "be disabled for this process.";
2290 } else {
2291 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2292 FileDescriptor(f, true)));
2293 }
[email protected]40da3e0c2012-10-24 22:03:382294 }
2295#endif // defined(USE_LINUX_BREAKPAD)
2296
2297#else
2298 int crash_signal_fd = GetCrashSignalFD(command_line);
2299 if (crash_signal_fd >= 0) {
2300 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2301 FileDescriptor(crash_signal_fd,
2302 false)));
2303 }
[email protected]29699c22012-10-03 23:57:392304#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302305}
[email protected]e60c0232011-11-11 19:56:352306#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302307
[email protected]4a65826d2011-08-25 16:04:012308#if defined(OS_WIN)
2309const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2310 return chrome::kBrowserResourcesDll;
2311}
[email protected]34f48682013-03-20 00:30:182312
2313void ChromeContentBrowserClient::PreSpawnRenderer(
2314 sandbox::TargetPolicy* policy,
2315 bool* success) {
2316 // This code is duplicated in nacl_exe_win_64.cc.
2317 // Allow the server side of a pipe restricted to the "chrome.nacl."
2318 // namespace so that it cannot impersonate other system or other chrome
2319 // service pipes.
2320 sandbox::ResultCode result = policy->AddRule(
2321 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2322 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2323 L"\\\\.\\pipe\\chrome.nacl.*");
2324 if (result != sandbox::SBOX_ALL_OK) {
2325 *success = false;
2326 return;
2327 }
2328
2329 // Renderers need to send named pipe handles and shared memory
2330 // segment handles to NaCl loader processes.
2331 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2332 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2333 L"File");
2334 if (result != sandbox::SBOX_ALL_OK) {
2335 *success = false;
2336 return;
2337 }
2338}
[email protected]4a65826d2011-08-25 16:04:012339#endif
2340
[email protected]37a72af2011-06-13 05:42:012341#if defined(USE_NSS)
2342crypto::CryptoModuleBlockingPasswordDelegate*
2343 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2344 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292345 return chrome::NewCryptoModuleBlockingDialogDelegate(
2346 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012347}
2348#endif
2349
[email protected]d977f9c2011-03-14 16:10:262350} // namespace chrome