blob: 33ce631dd55b7b90eec7607b42d9a9abc637b635 [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]0533cc6d2013-06-27 22:44:0547#include "chrome/browser/guestview/adview/adview_guest.h"
48#include "chrome/browser/guestview/guestview_constants.h"
49#include "chrome/browser/guestview/webview/webview_guest.h"
[email protected]11158e2d2013-02-01 02:31:5650#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0451#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]01e59752013-06-18 00:17:3552#include "chrome/browser/nacl_host/nacl_host_message_filter.h"
[email protected]0c7193742012-11-07 19:05:0353#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2854#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0455#include "chrome/browser/notifications/desktop_notification_service.h"
56#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4257#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5658#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0659#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4160#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5061#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0762#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4163#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1464#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0365#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1466#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3267#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0668#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1469#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3870#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4371#include "chrome/browser/search/instant_service.h"
72#include "chrome/browser/search/instant_service_factory.h"
73#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1474#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0275#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3376#include "chrome/browser/speech/tts_message_filter.h"
[email protected]8ec71262011-07-28 08:12:4677#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5878#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0379#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5280#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4581#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5482#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4383#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2584#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4485#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5086#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0687#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1588#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2789#include "chrome/browser/validation_message_message_filter.h"
[email protected]b80f68432011-05-02 17:22:3090#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0191#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1492#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3093#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2994#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0495#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3896#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4497#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4398#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:2999#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]dda54822013-06-15 01:26:39100#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]157cc902012-11-02 06:31:58101#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:34102#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37103#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12104#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38105#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09106#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53107#include "chromeos/chromeos_constants.h"
[email protected]d5d383252013-07-04 14:44:32108#include "components/nacl/common/nacl_process_type.h"
[email protected]75fee372013-03-06 00:42:44109#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43110#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30111#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38112#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03113#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31114#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03115#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59116#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36117#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30118#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33119#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05120#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33121#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19122#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10123#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43124#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18125#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23126#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42127#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39128#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23129#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53130#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58131#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34132#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06133#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57134#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38135#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39136#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08137#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24138#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31139#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18140#include "webkit/common/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04141#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26142
[email protected]b48c9182011-10-26 18:03:30143#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38144#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18145#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38146#elif defined(OS_MACOSX)
147#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56148#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30149#elif defined(OS_CHROMEOS)
150#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]0ec5f5f2013-07-04 09:13:58151#include "chrome/browser/chromeos/drive/mount_point_provider_delegate.h"
[email protected]b40015c2013-06-26 08:13:31152#include "chrome/browser/chromeos/fileapi/cros_mount_point_provider.h"
[email protected]5c915252013-05-07 13:15:39153#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49154#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]5c915252013-05-07 13:15:39155#include "chrome/browser/chromeos/system/statistics_provider.h"
[email protected]931d1042013-04-05 17:50:44156#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26157#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30158#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09159#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38160#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09161#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39162#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30163#elif defined(OS_POSIX)
164#include "chrome/browser/chrome_browser_main_posix.h"
165#endif
166
[email protected]6653c192012-04-10 22:52:44167#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30168#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12169#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43170#endif
[email protected]b80f68432011-05-02 17:22:30171
[email protected]1e87df32012-09-12 04:53:19172#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
173#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
174#endif
175
[email protected]29699c22012-10-03 23:57:39176#if defined(OS_ANDROID)
177#include "ui/base/ui_base_paths.h"
178#endif
179
[email protected]37a72af2011-06-13 05:42:01180#if defined(USE_NSS)
181#include "chrome/browser/ui/crypto_module_password_dialog.h"
182#endif
183
[email protected]d5bcd06f2013-04-21 08:07:24184#if !defined(OS_CHROMEOS)
185#include "chrome/browser/signin/signin_manager.h"
186#include "chrome/browser/signin/signin_manager_factory.h"
187#endif
188
[email protected]02250952013-04-24 23:52:53189#if !defined(OS_ANDROID)
190#include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h"
191#endif
192
[email protected]6ef98b5a2013-05-31 23:58:31193#if defined(ENABLE_WEBRTC)
194#include "chrome/browser/media/webrtc_logging_handler_host.h"
195#endif
196
[email protected]02a3dc122013-06-13 15:07:53197#if defined(FILE_MANAGER_EXTENSION)
198#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
199#endif
200
[email protected]c7abd422012-09-25 00:20:08201using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47202using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03203using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39204using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31205using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59206using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08207using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00208using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11209using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33210using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13211using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06212using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34213using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40214using extensions::Manifest;
[email protected]631bb742011-11-02 11:29:39215
[email protected]c5dbef02011-05-13 05:06:09216namespace {
217
[email protected]eabbfb12013-04-05 23:28:35218// Cached version of the locale so we can return the locale on the I/O
219// thread.
220base::LazyInstance<std::string> g_io_thread_application_locale;
221
[email protected]93f72062013-05-29 20:29:40222#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40223const char* kPredefinedAllowedSocketOrigins[] = {
224 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18225 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45226 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
227 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
228 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
229 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35230 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54231 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
232 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
233 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
234 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
235 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
236 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38237 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58238 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29239 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]f6599915a2013-06-20 20:03:50240 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
[email protected]b71313232013-05-06 06:16:29241 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
242 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
243 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
244 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40245};
[email protected]93f72062013-05-29 20:29:40246#endif
[email protected]e461da2f2012-02-16 19:06:40247
[email protected]f8f93eb2012-09-25 03:06:24248// Returns a copy of the given url with its host set to given host and path set
249// to given path. Other parts of the url will be the same.
250GURL ReplaceURLHostAndPath(const GURL& url,
251 const std::string& host,
252 const std::string& path) {
253 url_canon::Replacements<char> replacements;
254 replacements.SetHost(host.c_str(),
255 url_parse::Component(0, host.length()));
256 replacements.SetPath(path.c_str(),
257 url_parse::Component(0, path.length()));
258 return url.ReplaceComponents(replacements);
259}
260
261// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
262GURL AddUberHost(const GURL& url) {
263 const std::string uber_host = chrome::kChromeUIUberHost;
264 const std::string new_path = url.host() + url.path();
265
266 return ReplaceURLHostAndPath(url, uber_host, new_path);
267}
268
[email protected]045bf7c2012-09-28 20:27:36269// If url->host() is "chrome" and url->path() has characters other than the
270// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
271// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24272bool RemoveUberHost(GURL* url) {
273 if (url->host() != chrome::kChromeUIUberHost)
274 return false;
275
[email protected]045bf7c2012-09-28 20:27:36276 if (url->path().empty() || url->path() == "/")
277 return false;
278
[email protected]f8f93eb2012-09-25 03:06:24279 const std::string old_path = url->path();
280
281 const std::string::size_type separator = old_path.find('/', 1);
282 std::string new_host;
283 std::string new_path;
284 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36285 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24286 } else {
287 new_host = old_path.substr(1, separator - 1);
288 new_path = old_path.substr(separator);
289 }
290
[email protected]44e8add2013-06-13 17:29:15291 // Do not allow URLs with paths empty before the first slash since we can't
292 // have an empty host. (e.g "foo://chrome//")
293 if (new_host.empty())
294 return false;
295
[email protected]f8f93eb2012-09-25 03:06:24296 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
297
[email protected]44e8add2013-06-13 17:29:15298 DCHECK(url->is_valid());
299
[email protected]f8f93eb2012-09-25 03:06:24300 return true;
301}
302
[email protected]b8148ac2011-07-13 22:03:25303// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42304bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24305 // Do not handle special URLs such as "about:foo"
306 if (!url->host().empty()) {
307 const GURL chrome_url = AddUberHost(*url);
308
309 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
310 // be called.
311 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
312 browser_context, chrome_url))
313 return true;
314 }
315
[email protected]863f70a2012-01-27 02:05:50316 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
317 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25318 return false;
319
[email protected]fe69558d2012-03-12 11:34:49320#if defined(OS_CHROMEOS)
321 // Special case : in ChromeOS in Guest mode bookmarks and history are
322 // disabled for security reasons. New tab page explains the reasons, so
323 // we redirect user to new tab page.
324 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
325 if (url->SchemeIs(chrome::kChromeUIScheme) &&
326 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
327 url->DomainIs(chrome::kChromeUIHistoryHost))) {
328 // Rewrite with new tab URL
329 *url = GURL(chrome::kChromeUINewTabURL);
330 }
331 }
332#endif
333
[email protected]b8148ac2011-07-13 22:03:25334 // Special case the new tab page. In older versions of Chrome, the new tab
335 // page was hosted at chrome-internal:<blah>. This might be in people's saved
336 // sessions or bookmarks, so we say any URL with that scheme triggers the new
337 // tab page.
338 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
339 // Rewrite it with the proper new tab URL.
340 *url = GURL(chrome::kChromeUINewTabURL);
341 }
342
343 return true;
344}
345
[email protected]f8f93eb2012-09-25 03:06:24346// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
347// "chrome://foo/".
348bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
349 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
350 return false;
351
352 return RemoveUberHost(url);
353}
354
[email protected]8d3132f62011-10-12 07:13:42355// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
356// below. Extension, and isolated apps require different privileges to be
357// granted to their RenderProcessHosts. This classification allows us to make
358// sure URLs are served by hosts with the right set of privileges.
359enum RenderProcessHostPrivilege {
360 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45361 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42362 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45363 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42364};
365
366RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
367 const GURL& url,
368 ExtensionService* service) {
369 // Default to a normal renderer cause it is lower privileged. This should only
370 // occur if the URL on a site instance is either malformed, or uninitialized.
371 // If it is malformed, then there is no need for better privileges anyways.
372 // If it is uninitialized, but eventually settles on being an a scheme other
373 // than normal webrenderer, the navigation logic will correct us out of band
374 // anyways.
375 if (!url.is_valid())
376 return PRIV_NORMAL;
377
[email protected]885c0e92012-11-13 20:27:42378 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44379 const Extension* extension =
380 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43381 if (extension &&
382 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42383 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45384 if (extension && extension->is_hosted_app())
385 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42386
387 return PRIV_EXTENSION;
388 }
389
390 return PRIV_NORMAL;
391}
392
393RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30394 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46395 extensions::ProcessMap* process_map,
396 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46397 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30398 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46399 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21400 return PRIV_NORMAL;
401
[email protected]6f371442011-11-09 06:45:46402 for (std::set<std::string>::iterator iter = extension_ids.begin();
403 iter != extension_ids.end(); ++iter) {
404 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43405 if (extension &&
406 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42407 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45408 if (extension && extension->is_hosted_app())
409 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42410 }
411
[email protected]676f6ab2011-10-19 20:23:21412 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42413}
414
[email protected]6786bf402011-12-03 15:19:45415bool CertMatchesFilter(const net::X509Certificate& cert,
416 const base::DictionaryValue& filter) {
417 // TODO(markusheintz): This is the minimal required filter implementation.
418 // Implement a better matcher.
419
420 // An empty filter matches any client certificate since no requirements are
421 // specified at all.
422 if (filter.empty())
423 return true;
424
425 std::string common_name;
426 if (filter.GetString("ISSUER.CN", &common_name) &&
427 (cert.issuer().common_name == common_name)) {
428 return true;
429 }
430 return false;
431}
432
[email protected]f3986f82012-01-03 20:00:06433// Fills |map| with the per-script font prefs under path |map_name|.
434void FillFontFamilyMap(const PrefService* prefs,
435 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53436 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06437 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
438 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
439 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
440 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23441 if (!font_family.empty())
442 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06443 }
444}
445
[email protected]a1733df2012-06-22 11:24:18446#if defined(OS_POSIX) && !defined(OS_MACOSX)
447int GetCrashSignalFD(const CommandLine& command_line) {
448 if (command_line.HasSwitch(switches::kExtensionProcess)) {
449 ExtensionCrashHandlerHostLinux* crash_handler =
450 ExtensionCrashHandlerHostLinux::GetInstance();
451 return crash_handler->GetDeathSignalSocket();
452 }
453
454 std::string process_type =
455 command_line.GetSwitchValueASCII(switches::kProcessType);
456
457 if (process_type == switches::kRendererProcess)
458 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
459
460 if (process_type == switches::kPluginProcess)
461 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
462
463 if (process_type == switches::kPpapiPluginProcess)
464 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
465
466 if (process_type == switches::kGpuProcess)
467 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
468
469 return -1;
470}
471#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
472
[email protected]d5bcd06f2013-04-21 08:07:24473#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30474GURL GetEffectiveURLForSignin(const GURL& url) {
475 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
476
477 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03478 // Copy the path because the argument to SetPathStr must outlive
479 // the Replacements object.
480 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30481 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03482 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30483 effective_url = effective_url.ReplaceComponents(replacements);
484 return effective_url;
485}
[email protected]d5bcd06f2013-04-21 08:07:24486#endif
[email protected]970c63e2013-03-07 00:25:30487
[email protected]eabbfb12013-04-05 23:28:35488void SetApplicationLocaleOnIOThread(const std::string& locale) {
489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
490 g_io_thread_application_locale.Get() = locale;
491}
492
[email protected]9dbfff12011-07-01 19:37:07493} // namespace
[email protected]c5dbef02011-05-13 05:06:09494
[email protected]d977f9c2011-03-14 16:10:26495namespace chrome {
496
[email protected]e461da2f2012-02-16 19:06:40497ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40498#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40499 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
500 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40501#endif
[email protected]1deace22013-05-22 06:14:46502
503 permissions_policy_delegate_.reset(
504 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40505}
506
507ChromeContentBrowserClient::~ChromeContentBrowserClient() {
508}
509
[email protected]bca18382012-06-25 19:15:23510// static
[email protected]c753f142013-02-10 13:14:04511void ChromeContentBrowserClient::RegisterUserPrefs(
[email protected]443e9312013-05-06 06:17:34512 user_prefs::PrefRegistrySyncable* registry) {
513 registry->RegisterBooleanPref(
514 prefs::kDisable3DAPIs,
515 false,
516 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
517 registry->RegisterBooleanPref(
518 prefs::kEnableHyperlinkAuditing,
519 true,
520 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
521 registry->RegisterBooleanPref(
522 prefs::kEnableMemoryInfo,
523 false,
524 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23525}
526
[email protected]eabbfb12013-04-05 23:28:35527// static
528void ChromeContentBrowserClient::SetApplicationLocale(
529 const std::string& locale) {
530 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
531
532 // This object is guaranteed to outlive all threads so we don't have to
533 // worry about the lack of refcounting and can just post as Unretained.
534 //
535 // The common case is that this function is called early in Chrome startup
536 // before any threads are created (it will also be called later if the user
537 // changes the pref). In this case, there will be no threads created and
538 // posting will fail. When there are no threads, we can just set the string
539 // without worrying about threadsafety.
540 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
541 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
542 g_io_thread_application_locale.Get() = locale;
543 }
544}
545
[email protected]50462bf02011-11-21 19:13:31546content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
547 const content::MainFunctionParams& parameters) {
548 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30549 // Construct the Main browser parts based on the OS type.
550#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31551 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04552#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31553 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30554#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22555 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26556#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31557 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14558#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09559 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30560#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31561 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04562#else
[email protected]b48c9182011-10-26 18:03:30563 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31564 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30565#endif
566
[email protected]7e75e4a2013-05-17 17:20:03567 chrome::AddProfilesExtraParts(main_parts);
568
[email protected]c7480942011-11-08 19:18:27569 // Construct additional browser parts. Stages are called in the order in
570 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22571#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41572 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04573#endif
[email protected]c7480942011-11-08 19:18:27574
575#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41576 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27577#endif
578
[email protected]dc04be7c2012-03-15 23:57:49579#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41580 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49581#endif
582
[email protected]e050ef142012-03-21 01:04:24583#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41584 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24585#endif
586
[email protected]95132f52013-04-12 02:19:04587 chrome::AddMetricsExtraParts(main_parts);
588
[email protected]50462bf02011-11-21 19:13:31589 return main_parts;
[email protected]f967b722011-09-07 00:58:04590}
591
[email protected]e94bbcb2012-09-07 05:33:57592std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19593 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57594 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53595 std::string partition_id;
596
597 // The partition ID for webview guest processes is the string value of its
598 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
599 if (site.SchemeIs(chrome::kGuestScheme))
600 partition_id = site.spec();
601
[email protected]056efdc2013-04-06 00:14:53602 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53603 return partition_id;
604}
605
606bool ChromeContentBrowserClient::IsValidStoragePartitionId(
607 content::BrowserContext* browser_context,
608 const std::string& partition_id) {
609 // The default ID is empty and is always valid.
610 if (partition_id.empty())
611 return true;
612
613 return GURL(partition_id).is_valid();
614}
615
616void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
617 content::BrowserContext* browser_context,
618 const GURL& site,
[email protected]14acc642012-11-17 12:20:10619 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53620 std::string* partition_domain,
621 std::string* partition_name,
622 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10623 // Default to the browser-wide storage partition and override based on |site|
624 // below.
625 partition_domain->clear();
626 partition_name->clear();
627 *in_memory = false;
628
[email protected]1bc28312012-11-08 08:31:53629 // For the webview tag, we create special guest processes, which host the
630 // tag content separately from the main application that embeds the tag.
631 // A webview tag can specify both the partition name and whether the storage
632 // for that partition should be persisted. Each tag gets a SiteInstance with
633 // a specially formatted URL, based on the application it is hosted by and
634 // the partition requested by it. The format for that URL is:
635 // chrome-guest://partition_domain/persist?partition_name
636 if (site.SchemeIs(chrome::kGuestScheme)) {
637 // Since guest URLs are only used for packaged apps, there must be an app
638 // id in the URL.
639 CHECK(site.has_host());
640 *partition_domain = site.host();
641 // Since persistence is optional, the path must either be empty or the
642 // literal string.
643 *in_memory = (site.path() != "/persist");
644 // The partition name is user supplied value, which we have encoded when the
645 // URL was created, so it needs to be decoded.
646 *partition_name = net::UnescapeURLComponent(site.query(),
647 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10648 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
649 // If |can_be_default| is false, the caller is stating that the |site|
650 // should be parsed as if it had isolated storage. In particular it is
651 // important to NOT check ExtensionService for the is_storage_isolated()
652 // attribute because this code path is run during Extension uninstall
653 // to do cleanup after the Extension has already been unloaded from the
654 // ExtensionService.
655 bool is_isolated = !can_be_default;
656 if (can_be_default) {
657 const Extension* extension = NULL;
658 Profile* profile = Profile::FromBrowserContext(browser_context);
659 ExtensionService* extension_service =
660 extensions::ExtensionSystem::Get(profile)->extension_service();
661 if (extension_service) {
662 extension = extension_service->extensions()->
663 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43664 if (extension &&
665 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10666 is_isolated = true;
667 }
668 }
669 }
[email protected]1bc28312012-11-08 08:31:53670
[email protected]14acc642012-11-17 12:20:10671 if (is_isolated) {
672 CHECK(site.has_host());
673 // For extensions with isolated storage, the the host of the |site| is
674 // the |partition_domain|. The |in_memory| and |partition_name| are only
675 // used in guest schemes so they are cleared here.
676 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53677 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10678 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53679 }
[email protected]d1198fd2012-08-13 22:50:19680 }
681
[email protected]14acc642012-11-17 12:20:10682 // Assert that if |can_be_default| is false, the code above must have found a
683 // non-default partition. If this fails, the caller has a serious logic
684 // error about which StoragePartition they expect to be in and it is not
685 // safe to continue.
686 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44687}
688
[email protected]38b098f2012-03-14 21:11:57689content::WebContentsViewDelegate*
690 ChromeContentBrowserClient::GetWebContentsViewDelegate(
691 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27692 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32693}
694
[email protected]24665682013-02-25 20:59:38695// Check if the extension activity log is enabled for the profile.
696static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33697 // crbug.com/247908 - This should be IsLogEnabled except for an issue
698 // in chrome_frame_net_tests
699 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38700}
701
[email protected]738f57a2013-06-29 21:06:54702void ChromeContentBrowserClient::GuestWebContentsCreated(
703 WebContents* guest_web_contents,
704 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22705 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54706 scoped_ptr<base::DictionaryValue> extra_params) {
707 if (opener_web_contents) {
708 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
709 if (!guest) {
710 NOTREACHED();
711 return;
712 }
713
714 switch (guest->GetViewType()) {
715 case GuestView::WEBVIEW: {
[email protected]4c0e8272013-07-03 23:39:22716 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54717 break;
718 }
719 case GuestView::ADVIEW: {
[email protected]4c0e8272013-07-03 23:39:22720 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54721 break;
722 }
723 default:
724 NOTREACHED();
725 break;
726 }
727 return;
728 }
729
730 if (!extra_params) {
731 NOTREACHED();
732 return;
733 }
734 std::string api_type;
735 extra_params->GetString(guestview::kAttributeApi, &api_type);
736
737 if (api_type == "adview") {
[email protected]4c0e8272013-07-03 23:39:22738 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54739 } else if (api_type == "webview") {
[email protected]4c0e8272013-07-03 23:39:22740 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54741 } else {
742 NOTREACHED();
743 }
744}
745
[email protected]44295a12013-06-05 08:45:46746void ChromeContentBrowserClient::GuestWebContentsAttached(
747 WebContents* guest_web_contents,
748 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53749 int browser_plugin_instance_id,
750 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06751 Profile* profile = Profile::FromBrowserContext(
752 embedder_web_contents->GetBrowserContext());
753 ExtensionService* service =
754 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54755 if (!service) {
756 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06757 return;
[email protected]738f57a2013-06-29 21:06:54758 }
[email protected]44703cc72013-01-24 04:56:06759 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
760 const Extension* extension = service->extensions()->
761 GetExtensionOrAppByURL(ExtensionURLInfo(url));
[email protected]738f57a2013-06-29 21:06:54762 if (!extension) {
[email protected]18699372013-06-25 20:42:55763 NOTREACHED();
[email protected]738f57a2013-06-29 21:06:54764 return;
[email protected]18699372013-06-25 20:42:55765 }
[email protected]738f57a2013-06-29 21:06:54766
767 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
768 if (!guest) {
769 NOTREACHED();
770 return;
771 }
772 guest->Attach(embedder_web_contents,
773 extension->id(),
774 browser_plugin_instance_id,
775 extra_params);
[email protected]44703cc72013-01-24 04:56:06776}
777
[email protected]f3b1a082011-11-18 00:34:30778void ChromeContentBrowserClient::RenderProcessHostCreated(
779 content::RenderProcessHost* host) {
780 int id = host->GetID();
781 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41782 net::URLRequestContextGetter* context =
783 profile->GetRequestContextForRenderProcess(id);
784
[email protected]f3b1a082011-11-18 00:34:30785 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41786 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55787#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30788 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55789#endif
[email protected]658677f2012-06-09 06:04:02790#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08791 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03792#endif
[email protected]f3b1a082011-11-18 00:34:30793 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02794 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30795 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56796#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21797 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56798#endif
[email protected]43535512013-02-20 20:41:41799 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
800 id, profile, context));
[email protected]2736c032012-05-11 18:06:07801 host->GetChannel()->AddFilter(
802 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27803 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33804 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31805#if defined(ENABLE_WEBRTC)
806 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
807#endif
[email protected]01e59752013-06-18 00:17:35808#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03809 ExtensionInfoMap* extension_info_map =
810 extensions::ExtensionSystem::Get(profile)->info_map();
811 host->GetChannel()->AddFilter(new NaClHostMessageFilter(
812 id, profile->IsOffTheRecord(),
813 profile->GetPath(), extension_info_map,
814 context));
[email protected]01e59752013-06-18 00:17:35815#endif
[email protected]3e69bc82011-05-26 23:22:38816
[email protected]2ccf45c2011-08-19 23:35:50817 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
818 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07819
[email protected]24665682013-02-25 20:59:38820 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
821 IsExtensionActivityLogEnabledForProfile(profile)));
822
[email protected]39a5b532011-10-22 01:47:07823 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56824
825 RendererContentSettingRules rules;
826 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
827 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14828}
829
[email protected]95c95552013-05-03 04:21:22830GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
831 content::BrowserContext* browser_context,
832 const GURL& url,
833 bool is_renderer_initiated,
834 content::SiteInstance* current_instance) {
835 Profile* profile = Profile::FromBrowserContext(browser_context);
836 if (!profile)
837 return url;
838
839 // Only return the privileged instant URL if we are entering from a browser-
840 // initiated navigation or if we are already in the instant process.
841 bool is_instant_process = false;
842 int process_id = current_instance->GetProcess()->GetID();
843 InstantService* instant_service =
844 InstantServiceFactory::GetForProfile(profile);
845 if (instant_service)
846 is_instant_process = instant_service->IsInstantProcess(process_id);
847
848 DCHECK_EQ(is_instant_process,
849 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
850 if (!is_renderer_initiated || is_instant_process) {
851 // If the input |url| should be assigned to the Instant renderer, make its
852 // privileged URL distinct from other URLs on the search provider's domain.
853 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
854 return chrome::GetPrivilegedURLForInstant(url, profile);
855 }
856
857 return url;
858}
859
[email protected]3d7474ff2011-07-27 17:47:37860GURL ChromeContentBrowserClient::GetEffectiveURL(
861 content::BrowserContext* browser_context, const GURL& url) {
862 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52863 if (!profile)
864 return url;
865
[email protected]d5bcd06f2013-04-21 08:07:24866#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30867 // If the input |url| should be assigned to the Signin renderer, make its
868 // effective URL distinct from other URLs on the signin service's domain.
869 // Note that the signin renderer will be allowed to sign the user in to
870 // Chrome.
871 if (SigninManager::IsWebBasedSigninFlowURL(url))
872 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24873#endif
[email protected]970c63e2013-03-07 00:25:30874
[email protected]c5dec6292013-01-25 04:54:52875 // If the input |url| is part of an installed app, the effective URL is an
876 // extension URL with the ID of that extension as the host. This has the
877 // effect of grouping apps together in a common SiteInstance.
878 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13879 extensions::ExtensionSystem::Get(profile)->extension_service();
880 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08881 return url;
882
[email protected]06bdd2b2012-11-30 18:47:13883 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44884 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08885 if (!extension)
886 return url;
887
[email protected]15877ca2011-11-18 22:40:52888 // Bookmark apps do not use the hosted app process model, and should be
889 // treated as normal URLs.
890 if (extension->from_bookmark())
891 return url;
892
[email protected]36fb2c7c2011-04-04 15:49:08893 // If the URL is part of an extension's web extent, convert it to an
894 // extension URL.
895 return extension->GetResourceURL(url.path());
896}
897
[email protected]056ad2a2011-07-12 02:13:55898bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37899 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52900 // Non-extension, non-Instant URLs should generally use
901 // process-per-site-instance. Because we expect to use the effective URL,
902 // URLs for hosted apps (apart from bookmark apps) should have an extension
903 // scheme by now.
904
905 Profile* profile = Profile::FromBrowserContext(browser_context);
906 if (!profile)
907 return false;
908
[email protected]165fe422013-03-27 06:34:03909 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52910 return true;
911
[email protected]d5bcd06f2013-04-21 08:07:24912#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30913 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
914 return true;
[email protected]d5bcd06f2013-04-21 08:07:24915#endif
[email protected]970c63e2013-03-07 00:25:30916
[email protected]885c0e92012-11-13 20:27:42917 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55918 return false;
919
[email protected]c5dec6292013-01-25 04:54:52920 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13921 extensions::ExtensionSystem::Get(profile)->extension_service();
922 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55923 return false;
924
[email protected]06bdd2b2012-11-30 18:47:13925 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44926 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55927 if (!extension)
928 return false;
929
930 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53931 // permission, or that does not allow JavaScript access to the background
932 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55933 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40934 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06935 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29936 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53937 return false;
938 }
939 }
[email protected]056ad2a2011-07-12 02:13:55940
[email protected]7b54ca02012-03-02 18:06:53941 // Hosted apps that have script access to their background page must use
942 // process per site, since all instances can make synchronous calls to the
943 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55944 return true;
945}
946
[email protected]672c8c12013-03-07 12:30:06947// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41948void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
949 std::vector<std::string>* additional_schemes) {
950 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06951}
952
[email protected]6bd30072013-02-08 18:17:11953net::URLRequestContextGetter*
954ChromeContentBrowserClient::CreateRequestContext(
955 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06956 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11957 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06958 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11959}
960
961net::URLRequestContextGetter*
962ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
963 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40964 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11965 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06966 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11967 Profile* profile = Profile::FromBrowserContext(browser_context);
968 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06969 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11970}
971
[email protected]46fb9442011-12-09 17:57:47972bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
973 return ProfileIOData::IsHandledURL(url);
974}
975
[email protected]c4365fa42013-05-14 01:08:24976bool ChromeContentBrowserClient::CanCommitURL(
977 content::RenderProcessHost* process_host,
978 const GURL& url) {
979 // We need to let most extension URLs commit in any process, since this can
980 // be allowed due to web_accessible_resources. Most hosted app URLs may also
981 // load in any process (e.g., in an iframe). However, the Chrome Web Store
982 // cannot be loaded in iframes and should never be requested outside its
983 // process.
984 Profile* profile =
985 Profile::FromBrowserContext(process_host->GetBrowserContext());
986 ExtensionService* service =
987 extensions::ExtensionSystem::Get(profile)->extension_service();
988 if (!service)
989 return true;
990 const Extension* new_extension =
991 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
992 if (new_extension &&
993 new_extension->is_hosted_app() &&
994 new_extension->id() == extension_misc::kWebStoreAppId &&
995 !service->process_map()->Contains(new_extension->id(),
996 process_host->GetID())) {
997 return false;
998 }
999
1000 return true;
1001}
1002
[email protected]2a5221b2011-09-27 23:07:311003bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301004 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311005 const GURL& site_url) {
1006 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301007 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521008 // This may be NULL during tests. In that case, just assume any site can
1009 // share any host.
1010 if (!profile)
1011 return true;
1012
[email protected]d43f99fe2013-04-03 00:20:141013 // Instant URLs should only be in the instant process and instant process
1014 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521015 InstantService* instant_service =
1016 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141017 if (instant_service) {
1018 bool is_instant_process = instant_service->IsInstantProcess(
1019 process_host->GetID());
1020 bool should_be_in_instant_process =
1021 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1022 if (is_instant_process || should_be_in_instant_process)
1023 return is_instant_process && should_be_in_instant_process;
1024 }
[email protected]c5dec6292013-01-25 04:54:521025
[email protected]d5bcd06f2013-04-21 08:07:241026#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301027 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1028 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1029 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241030#endif
[email protected]970c63e2013-03-07 00:25:301031
[email protected]06bdd2b2012-11-30 18:47:131032 ExtensionService* service =
1033 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461034 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311035
[email protected]ffa97602011-11-17 17:55:521036 // Don't allow the Task Manager to share a process with anything else.
1037 // Otherwise it can affect the renderers it is observing.
1038 // Note: we could create another RenderProcessHostPrivilege bucket for
1039 // this to allow multiple chrome://tasks instances to share, but that's
1040 // a very unlikely case without serious consequences.
1041 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1042 return false;
1043
[email protected]8d3132f62011-10-12 07:13:421044 // These may be NULL during tests. In that case, just assume any site can
1045 // share any host.
[email protected]6f371442011-11-09 06:45:461046 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311047 return true;
1048
[email protected]eec0b33c2011-12-05 22:09:451049 // Otherwise, just make sure the process privilege matches the privilege
1050 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571051 RenderProcessHostPrivilege privilege_required =
1052 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451053 return GetProcessPrivilege(process_host, process_map, service) ==
1054 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311055}
1056
[email protected]76411f412012-02-22 18:56:061057// This function is trying to limit the amount of processes used by extensions
1058// with background pages. It uses a globally set percentage of processes to
1059// run such extensions and if the limit is exceeded, it returns true, to
1060// indicate to the content module to group extensions together.
1061bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1062 content::BrowserContext* browser_context, const GURL& url) {
1063 // It has to be a valid URL for us to check for an extension.
1064 if (!url.is_valid())
1065 return false;
1066
1067 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191068 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131069 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061070 if (!service)
1071 return false;
1072
1073 // We have to have a valid extension with background page to proceed.
1074 const Extension* extension =
1075 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
1076 if (!extension)
1077 return false;
[email protected]9367eabc2013-03-01 01:29:291078 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061079 return false;
1080
1081 std::set<int> process_ids;
1082 size_t max_process_count =
1083 content::RenderProcessHost::GetMaxRendererProcessCount();
1084
1085 // Go through all profiles to ensure we have total count of extension
1086 // processes containing background pages, otherwise one profile can
1087 // starve the other.
1088 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1089 GetLoadedProfiles();
1090 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031091 ExtensionProcessManager* epm =
1092 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321093 for (ExtensionProcessManager::const_iterator iter =
1094 epm->background_hosts().begin();
1095 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131096 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321097 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061098 }
1099 }
1100
1101 if (process_ids.size() >
1102 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1103 return true;
1104 }
1105
1106 return false;
1107}
1108
[email protected]6f371442011-11-09 06:45:461109void ChromeContentBrowserClient::SiteInstanceGotProcess(
1110 SiteInstance* site_instance) {
1111 CHECK(site_instance->HasProcess());
1112
1113 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021114 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521115 if (!profile)
1116 return;
1117
1118 // Remember the ID of the Instant process to signal the renderer process
1119 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031120 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321121 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521122 InstantService* instant_service =
1123 InstantServiceFactory::GetForProfile(profile);
1124 if (instant_service)
1125 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1126 }
1127
[email protected]d5bcd06f2013-04-21 08:07:241128#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301129 // We only expect there to be one signin process as we use process-per-site
1130 // for signin URLs. The signin process will be cleared from SigninManager
1131 // when the renderer is destroyed.
1132 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1133 SigninManager* signin_manager =
1134 SigninManagerFactory::GetForProfile(profile);
1135 if (signin_manager)
1136 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461137 BrowserThread::PostTask(
1138 BrowserThread::IO, FROM_HERE,
1139 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1140 extensions::ExtensionSystem::Get(profile)->info_map(),
1141 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301142 }
[email protected]d5bcd06f2013-04-21 08:07:241143#endif
[email protected]970c63e2013-03-07 00:25:301144
[email protected]06bdd2b2012-11-30 18:47:131145 ExtensionService* service =
1146 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461147 if (!service)
1148 return;
1149
1150 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441151 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591152 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461153 if (!extension)
1154 return;
1155
[email protected]6bc04fd82011-12-04 02:29:351156 service->process_map()->Insert(extension->id(),
1157 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331158 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461159 BrowserThread::PostTask(
1160 BrowserThread::IO, FROM_HERE,
1161 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591162 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461163 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351164 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331165 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461166}
1167
1168void ChromeContentBrowserClient::SiteInstanceDeleting(
1169 SiteInstance* site_instance) {
1170 if (!site_instance->HasProcess())
1171 return;
1172
1173 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021174 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131175 ExtensionService* service =
1176 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461177 if (!service)
1178 return;
1179
1180 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441181 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591182 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461183 if (!extension)
1184 return;
1185
[email protected]6bc04fd82011-12-04 02:29:351186 service->process_map()->Remove(extension->id(),
1187 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331188 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461189 BrowserThread::PostTask(
1190 BrowserThread::IO, FROM_HERE,
1191 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591192 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461193 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351194 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331195 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461196}
1197
[email protected]f05763972012-06-06 18:17:261198bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141199 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081200 const GURL& current_url,
1201 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261202 if (current_url.is_empty()) {
1203 // Always choose a new process when navigating to extension URLs. The
1204 // process grouping logic will combine all of a given extension's pages
1205 // into the same process.
[email protected]885c0e92012-11-13 20:27:421206 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261207 return true;
[email protected]e3daf3c2011-10-05 21:17:081208
[email protected]f05763972012-06-06 18:17:261209 return false;
1210 }
1211
1212 // Also, we must switch if one is an extension and the other is not the exact
1213 // same extension.
[email protected]885c0e92012-11-13 20:27:421214 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1215 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261216 if (current_url.GetOrigin() != new_url.GetOrigin())
1217 return true;
1218 }
1219
[email protected]e9841fbd2013-02-22 23:12:141220 // The checks below only matter if we can retrieve which extensions are
1221 // installed.
1222 Profile* profile =
1223 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1224 ExtensionService* service =
1225 extensions::ExtensionSystem::Get(profile)->extension_service();
1226 if (!service)
1227 return false;
1228
1229 // We must swap if the URL is for an extension and we are not using an
1230 // extension process.
1231 const Extension* new_extension =
1232 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1233 // Ignore all hosted apps except the Chrome Web Store, since they do not
1234 // require their own BrowsingInstance (e.g., postMessage is ok).
1235 if (new_extension &&
1236 new_extension->is_hosted_app() &&
1237 new_extension->id() != extension_misc::kWebStoreAppId)
1238 new_extension = NULL;
1239 if (new_extension &&
1240 site_instance->HasProcess() &&
1241 !service->process_map()->Contains(new_extension->id(),
1242 site_instance->GetProcess()->GetID()))
1243 return true;
1244
[email protected]f05763972012-06-06 18:17:261245 return false;
[email protected]e3daf3c2011-10-05 21:17:081246}
1247
[email protected]395045c2012-05-22 15:04:381248bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1249 content::ResourceContext* resource_context, const GURL& current_url,
1250 const GURL& new_url) {
1251 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1252 return extensions::CrossesExtensionProcessBoundary(
1253 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171254 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381255}
1256
[email protected]3d831992013-07-04 01:13:291257bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1258 return !url.SchemeIs(chrome::kChromeNativeScheme);
1259}
1260
[email protected]763ec4ca2011-04-29 15:48:121261std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1262 const std::string& alias_name) {
1263 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1264}
1265
[email protected]b80f68432011-05-02 17:22:301266void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1267 CommandLine* command_line, int child_process_id) {
1268#if defined(USE_LINUX_BREAKPAD)
1269 if (IsCrashReporterEnabled()) {
1270 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1271 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1272 }
1273#elif defined(OS_MACOSX)
1274 if (IsCrashReporterEnabled()) {
1275 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1276 child_process_logging::GetClientId());
1277 }
1278#endif // OS_MACOSX
1279
[email protected]f1933792011-06-14 00:49:341280 if (logging::DialogsAreSuppressed())
1281 command_line->AppendSwitch(switches::kNoErrorDialogs);
1282
[email protected]b80f68432011-05-02 17:22:301283 std::string process_type =
1284 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171285 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321286
1287 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1288 command_line->AppendSwitch(switches::kChromeFrame);
1289
[email protected]718eab62011-10-05 21:16:521290 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451291 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301292 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1293 if (!user_data_dir.empty())
1294 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1295#if defined(OS_CHROMEOS)
1296 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441297 browser_command_line.GetSwitchValueASCII(
1298 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301299 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441300 command_line->AppendSwitchASCII(
1301 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301302#endif
1303
[email protected]f3b1a082011-11-18 00:34:301304 content::RenderProcessHost* process =
1305 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371306 if (process) {
1307 Profile* profile = Profile::FromBrowserContext(
1308 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131309 ExtensionService* extension_service =
1310 extensions::ExtensionSystem::Get(profile)->extension_service();
1311 if (extension_service) {
1312 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001313 if (process_map && process_map->Contains(process->GetID()))
1314 command_line->AppendSwitch(switches::kExtensionProcess);
1315 }
[email protected]b80f68432011-05-02 17:22:301316
[email protected]a8d851f82011-12-21 00:32:371317 PrefService* prefs = profile->GetPrefs();
1318 // Currently this pref is only registered if applied via a policy.
1319 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1320 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1321 // Turn this policy into a command line switch.
1322 command_line->AppendSwitch(switches::kDisable3DAPIs);
1323 }
[email protected]718eab62011-10-05 21:16:521324
[email protected]a8d851f82011-12-21 00:32:371325 // Disable client-side phishing detection in the renderer if it is
1326 // disabled in the Profile preferences or the browser process.
1327 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1328 !g_browser_process->safe_browsing_detection_service()) {
1329 command_line->AppendSwitch(
1330 switches::kDisableClientSidePhishingDetection);
1331 }
[email protected]0045b0f42012-07-26 11:52:081332
1333 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211334 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521335
1336 InstantService* instant_service =
1337 InstantServiceFactory::GetForProfile(profile);
1338 if (instant_service &&
1339 instant_service->IsInstantProcess(process->GetID()))
1340 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301341
[email protected]d5bcd06f2013-04-21 08:07:241342#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301343 SigninManager* signin_manager =
1344 SigninManagerFactory::GetForProfile(profile);
1345 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1346 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241347#endif
[email protected]47c7ec82012-01-18 03:29:211348 }
[email protected]4287a3d2011-06-13 23:56:511349
[email protected]87552982012-11-02 17:21:401350 if (content::IsThreadedCompositingEnabled())
1351 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1352
[email protected]16dc42452013-04-09 04:37:191353 if (message_center::IsRichNotificationEnabled())
1354 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191355
[email protected]47c7ec82012-01-18 03:29:211356 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511357 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171358 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481359 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171360 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511361 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481362 switches::kAllowLegacyExtensionManifests,
[email protected]9d450492013-06-13 23:08:371363 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1364 // to browser.
1365 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511366 switches::kAllowScriptingGallery,
1367 switches::kAppsCheckoutURL,
1368 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311369 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511370 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501371 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531372 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111373 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531374 switches::kEnableAdview,
1375 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441376 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211377 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511378 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511379 switches::kEnableIPCFuzzing,
1380 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451381 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481382 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051383 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511384 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291385 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511386 switches::kMemoryProfiling,
1387 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371388 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371389 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511390 switches::kPpapiFlashArgs,
1391 switches::kPpapiFlashInProcess,
1392 switches::kPpapiFlashPath,
1393 switches::kPpapiFlashVersion,
1394 switches::kProfilingAtStart,
1395 switches::kProfilingFile,
1396 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371397 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511398 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291399 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381400 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511401 };
1402
1403 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1404 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171405 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381406 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351407 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381408 switches::kEnableExperimentalExtensionApis,
1409 switches::kWhitelistedExtensionID,
1410 };
1411
1412 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1413 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511414 } else if (process_type == switches::kPluginProcess) {
1415 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441416#if defined(OS_CHROMEOS)
1417 chromeos::switches::kLoginProfile,
1418#endif
[email protected]4287a3d2011-06-13 23:56:511419 switches::kMemoryProfiling,
1420 switches::kSilentDumpOnDCHECK,
1421 switches::kUserDataDir,
1422 };
1423
1424 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1425 arraysize(kSwitchNames));
1426 } else if (process_type == switches::kZygoteProcess) {
1427 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511428 switches::kUserDataDir, // Make logs go to the right file.
1429 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501430 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511431 switches::kPpapiFlashInProcess,
1432 switches::kPpapiFlashPath,
1433 switches::kPpapiFlashVersion,
1434 };
1435
1436 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1437 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111438 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001439 base::FilePath user_data_dir =
1440 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1441 if (!user_data_dir.empty())
1442 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111443 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1444 // because GPU is expected to be unreliable.
1445 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1446 !command_line->HasSwitch(switches::kDisableBreakpad))
1447 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301448 }
[email protected]6f08af82011-09-15 01:19:031449
1450 // The command line switch kEnableBenchmarking needs to be specified along
1451 // with the kEnableStatsTable switch to ensure that the stats table global
1452 // is initialized correctly.
1453 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1454 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301455}
1456
1457std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431458 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351459 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301460 return g_browser_process->GetApplicationLocale();
1461}
1462
[email protected]597a867b2011-11-18 18:31:201463std::string ChromeContentBrowserClient::GetAcceptLangs(
1464 content::BrowserContext* context) {
1465 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371466 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081467}
1468
[email protected]9ec0f452012-05-31 15:58:531469gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221470 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531471 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081472}
1473
[email protected]a2176792011-05-08 19:30:491474bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091475 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191476 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201477 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201479 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051480 return io_data->GetCookieSettings()->
1481 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491482}
1483
[email protected]ed24fad2011-05-10 22:44:011484bool ChromeContentBrowserClient::AllowGetCookie(
1485 const GURL& url,
1486 const GURL& first_party,
1487 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201488 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011489 int render_process_id,
1490 int render_view_id) {
1491 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201492 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051493 bool allow = io_data->GetCookieSettings()->
1494 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011495
[email protected]8093a542011-05-13 07:29:321496 BrowserThread::PostTask(
1497 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031498 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431499 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011500 return allow;
1501}
1502
1503bool ChromeContentBrowserClient::AllowSetCookie(
1504 const GURL& url,
1505 const GURL& first_party,
1506 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201507 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011508 int render_process_id,
1509 int render_view_id,
1510 net::CookieOptions* options) {
1511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201512 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051513 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1514 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1515
[email protected]8093a542011-05-13 07:29:321516 BrowserThread::PostTask(
1517 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031518 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431519 render_view_id, url, first_party, cookie_line, *options,
1520 !allow));
[email protected]ed24fad2011-05-10 22:44:011521 return allow;
1522}
1523
[email protected]d5a19162011-06-30 18:51:541524bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201525 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201527 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431528 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1529 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261530
[email protected]bf510ed2012-06-05 08:31:431531 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1532 // Could we even support per-origin settings?
1533 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541534}
1535
[email protected]5c5a88e2011-11-12 00:45:351536bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351537 const GURL& url,
1538 const string16& name,
1539 const string16& display_name,
1540 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201541 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481542 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201544 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351545 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1546 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1547
[email protected]62151052012-02-01 18:40:481548 // Record access to database for potential display in UI.
1549 std::vector<std::pair<int, int> >::const_iterator i;
1550 for (i = render_views.begin(); i != render_views.end(); ++i) {
1551 BrowserThread::PostTask(
1552 BrowserThread::UI, FROM_HERE,
1553 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1554 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351555 }
1556
1557 return allow;
1558}
1559
1560bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351561 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201562 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481563 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201565 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351566 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1567 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1568
[email protected]62151052012-02-01 18:40:481569 // Record access to file system for potential display in UI.
1570 std::vector<std::pair<int, int> >::const_iterator i;
1571 for (i = render_views.begin(); i != render_views.end(); ++i) {
1572 BrowserThread::PostTask(
1573 BrowserThread::UI, FROM_HERE,
1574 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1575 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351576 }
1577
1578 return allow;
1579}
1580
[email protected]7c5ff9a2012-03-02 07:42:491581bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1582 const GURL& url,
1583 const string16& name,
1584 content::ResourceContext* context,
1585 const std::vector<std::pair<int, int> >& render_views) {
1586 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1587 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1588 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1589 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1590
1591 // Record access to IndexedDB for potential display in UI.
1592 std::vector<std::pair<int, int> >::const_iterator i;
1593 for (i = render_views.begin(); i != render_views.end(); ++i) {
1594 BrowserThread::PostTask(
1595 BrowserThread::UI, FROM_HERE,
1596 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1597 i->first, i->second, url, name, !allow));
1598 }
1599
1600 return allow;
1601}
1602
[email protected]6133f922011-07-01 21:34:341603net::URLRequestContext*
1604ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201605 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421607 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201608 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341609 return io_data->extensions_request_context();
1610 }
1611
1612 return NULL;
1613}
1614
[email protected]317f96c92011-05-31 06:53:411615QuotaPermissionContext*
1616ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1617 return new ChromeQuotaPermissionContext();
1618}
1619
[email protected]848dd042011-06-04 18:24:031620void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171621 int render_process_id,
1622 int render_view_id,
1623 int cert_error,
1624 const net::SSLInfo& ssl_info,
1625 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021626 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031627 bool overridable,
[email protected]d9be47702012-05-16 03:41:221628 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171629 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001630 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021631 if (resource_type != ResourceType::MAIN_FRAME) {
1632 // A sub-resource has a certificate error. The user doesn't really
1633 // have a context for making the right decision, so block the
1634 // request hard, without an info bar to allow showing the insecure
1635 // content.
[email protected]8c965c22013-05-23 19:28:001636 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021637 return;
1638 }
1639
[email protected]f9034cf2011-07-21 12:43:411640 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131641 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171642 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411643 if (!tab) {
1644 NOTREACHED();
1645 return;
1646 }
1647 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501648 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301649 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011650 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1651 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411652 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171653 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411654 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001655 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411656 return;
1657 }
1658 }
1659
[email protected]1e87df32012-09-12 04:53:191660#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231661 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1662 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1663 if (captive_portal_tab_helper)
1664 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191665#endif
1666
[email protected]f9034cf2011-07-21 12:43:411667 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221668 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1669 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031670}
1671
[email protected]c99c442e2011-08-24 11:37:301672void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451673 int render_process_id,
1674 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401675 const net::HttpNetworkSession* network_session,
1676 net::SSLCertRequestInfo* cert_request_info,
1677 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131678 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451679 render_process_id, render_view_id);
1680 if (!tab) {
1681 NOTREACHED();
1682 return;
1683 }
1684
[email protected]6786bf402011-12-03 15:19:451685 GURL requesting_url("https://" + cert_request_info->host_and_port);
1686 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1687 << cert_request_info->host_and_port;
1688
[email protected]627e0512011-12-21 22:55:301689 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451690 scoped_ptr<Value> filter(
1691 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1692 requesting_url,
1693 requesting_url,
1694 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1695 std::string(), NULL));
1696
1697 if (filter.get()) {
1698 // Try to automatically select a client certificate.
1699 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1700 DictionaryValue* filter_dict =
1701 static_cast<DictionaryValue*>(filter.get());
1702
1703 const std::vector<scoped_refptr<net::X509Certificate> >&
1704 all_client_certs = cert_request_info->client_certs;
1705 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091706 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451707 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091708 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451709 return;
1710 }
1711 }
1712 } else {
1713 NOTREACHED();
1714 }
1715 }
1716
[email protected]11feec322012-09-18 03:58:521717 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1718 if (!ssl_tab_helper) {
1719 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451720 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141721 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401722 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451723 return;
1724 }
[email protected]11feec322012-09-18 03:58:521725 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401726 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451727}
1728
[email protected]3b455502012-12-11 18:22:581729void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451730 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581731 net::CertificateMimeType cert_type,
1732 const void* cert_data,
1733 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451734 int render_process_id,
1735 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581736 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1737 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451738}
1739
[email protected]dc73a7b2012-03-25 15:27:181740content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561741 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181742}
1743
[email protected]941623e2011-06-07 23:06:041744void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1745 const GURL& source_origin,
1746 int callback_context,
1747 int render_process_id,
1748 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111749#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021750 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1751 WebContents* contents =
1752 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1753 if (!contents) {
[email protected]941623e2011-06-07 23:06:041754 NOTREACHED();
1755 return;
1756 }
1757
[email protected]d0d9c3ee2012-06-19 03:07:021758 // Skip showing the infobar if the request comes from an extension, and that
1759 // extension has the 'notify' permission. (If the extension does not have the
1760 // permission, the user will still be prompted.)
1761 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011762 ExtensionInfoMap* extension_info_map =
1763 extensions::ExtensionSystem::Get(profile)->info_map();
1764 DesktopNotificationService* notification_service =
1765 DesktopNotificationServiceFactory::GetForProfile(profile);
1766 const Extension* extension = NULL;
1767 if (extension_info_map) {
1768 ExtensionSet extensions;
1769 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1770 source_origin, render_process_id,
1771 extensions::APIPermission::kNotification, &extensions);
1772 for (ExtensionSet::const_iterator iter = extensions.begin();
1773 iter != extensions.end(); ++iter) {
1774 if (notification_service->IsExtensionEnabled((*iter)->id())) {
[email protected]cadac622013-06-11 16:46:361775 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011776 break;
1777 }
1778 }
1779 }
[email protected]eb4832a2012-12-08 01:57:521780 RenderViewHost* rvh =
1781 RenderViewHost::FromID(render_process_id, render_view_id);
1782 if (IsExtensionWithPermissionOrSuggestInConsole(
1783 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021784 if (rvh)
1785 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1786 return;
1787 }
1788
[email protected]c7cd5942013-04-30 03:31:011789 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021790 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111791#else
1792 NOTIMPLEMENTED();
1793#endif
[email protected]941623e2011-06-07 23:06:041794}
1795
1796WebKit::WebNotificationPresenter::Permission
1797 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021798 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201799 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021800 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111801#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041802 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201803 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041804
[email protected]c7cd5942013-04-30 03:31:011805 DesktopNotificationService* notification_service =
1806 io_data->GetNotificationService();
1807 if (notification_service) {
1808 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1809 ExtensionSet extensions;
1810 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1811 source_origin, render_process_id,
1812 extensions::APIPermission::kNotification, &extensions);
1813 for (ExtensionSet::const_iterator iter = extensions.begin();
1814 iter != extensions.end(); ++iter) {
1815 if (notification_service->IsExtensionEnabled((*iter)->id()))
1816 return WebKit::WebNotificationPresenter::PermissionAllowed;
1817 }
1818
1819 return notification_service->HasPermission(source_origin);
1820 }
1821
1822 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111823#else
1824 return WebKit::WebNotificationPresenter::PermissionAllowed;
1825#endif
[email protected]941623e2011-06-07 23:06:041826}
1827
1828void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171829 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041830 int render_process_id,
1831 int render_view_id,
1832 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111833#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041834 RenderViewHost* rvh = RenderViewHost::FromID(
1835 render_process_id, render_view_id);
1836 if (!rvh) {
1837 NOTREACHED();
1838 return;
1839 }
1840
[email protected]9f76c1e2012-03-05 15:15:581841 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301842 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041843 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371844 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041845 service->ShowDesktopNotification(
1846 params, render_process_id, render_view_id,
1847 worker ? DesktopNotificationService::WorkerNotification :
1848 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111849#else
1850 NOTIMPLEMENTED();
1851#endif
[email protected]941623e2011-06-07 23:06:041852}
1853
1854void ChromeContentBrowserClient::CancelDesktopNotification(
1855 int render_process_id,
1856 int render_view_id,
1857 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111858#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041859 RenderViewHost* rvh = RenderViewHost::FromID(
1860 render_process_id, render_view_id);
1861 if (!rvh) {
1862 NOTREACHED();
1863 return;
1864 }
1865
[email protected]9f76c1e2012-03-05 15:15:581866 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301867 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041868 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371869 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041870 service->CancelDesktopNotification(
1871 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111872#else
1873 NOTIMPLEMENTED();
1874#endif
[email protected]941623e2011-06-07 23:06:041875}
1876
[email protected]9f3fba52011-06-08 20:37:191877bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351878 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021879 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191880 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201881 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011882 int render_process_id,
1883 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191884 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011885
1886 *no_javascript_access = false;
1887
[email protected]9f3fba52011-06-08 20:37:191888 // If the opener is trying to create a background window but doesn't have
1889 // the appropriate permission, fail the attempt.
1890 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201891 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531892 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1893
[email protected]03b6d552012-03-29 04:03:011894 if (!map->SecurityOriginHasAPIPermission(
1895 source_origin,
1896 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061897 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011898 return false;
1899 }
1900
[email protected]7b54ca02012-03-02 18:06:531901 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1902 // return a recently installed Extension even if this CanCreateWindow call
1903 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011904 // because the permission check above would have caused an early return
1905 // already. We must use the full URL to find hosted apps, though, and not
1906 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531907 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351908 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291909 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011910 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191911 }
[email protected]056efdc2013-04-06 00:14:531912
1913 // No new browser window (popup or tab) in app mode.
1914 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1915 chrome::IsRunningInForcedAppMode()) {
1916 return false;
1917 }
1918
[email protected]9f3fba52011-06-08 20:37:191919 return true;
1920}
1921
1922std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201923 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191924 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1925 // Check if it's an extension-created worker, in which case we want to use
1926 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201927 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191928 const Extension* extension =
1929 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1930 return extension ? extension->name() : std::string();
1931}
1932
[email protected]99907362012-01-11 05:41:401933void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1934 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171935}
1936
[email protected]7a06d282013-05-03 04:39:331937// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021938content::SpeechRecognitionManagerDelegate*
1939 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]3bd0aab2013-05-30 20:07:491940#if !defined(OS_ANDROID)
[email protected]c52b2892012-03-07 11:01:021941 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321942#else
[email protected]3bd0aab2013-05-30 20:07:491943 // TODO(janx): Implement speech::AndroidSpeechRecognitionManagerDelegate
1944 // (see crbug.com/222352).
[email protected]a03f2d32012-03-14 00:26:321945 return NULL;
1946#endif
[email protected]66cfec62012-02-24 17:57:511947}
1948
[email protected]ae6e9912011-07-27 01:18:281949net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1950 return g_browser_process->net_log();
1951}
1952
[email protected]32538d92011-08-25 00:09:231953AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1954 return new ChromeAccessTokenStore();
1955}
1956
[email protected]dbae6b02011-06-29 23:51:411957bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011958 return true;
[email protected]dbae6b02011-06-29 23:51:411959}
1960
[email protected]64d69de42012-02-06 00:19:541961void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321962 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061963 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581964 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061965 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061966
[email protected]f3986f82012-01-03 20:00:061967 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541968 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061969 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541970 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061971 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541972 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061973 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541974 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061975 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541976 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061977 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541978 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031979 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1980 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061981
[email protected]64d69de42012-02-06 00:19:541982 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401983 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541984 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401985 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541986 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401987 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541988 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401989 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061990
[email protected]ddf72142012-05-22 04:52:401991 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061992
[email protected]64d69de42012-02-06 00:19:541993 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401994 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541995 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061996 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541997 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061998 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1999 const DictionaryValue* inspector_settings =
2000 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2001 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182002 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2003 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062004 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182005 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542006 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182007 std::make_pair(iter.key(), value));
2008 }
[email protected]f3986f82012-01-03 20:00:062009 }
2010 }
[email protected]64d69de42012-02-06 00:19:542011 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062012
[email protected]ddf72142012-05-22 04:52:402013 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542014 web_prefs->javascript_enabled = false;
2015 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2016 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402017 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542018 web_prefs->plugins_enabled = false;
2019 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2020 web_prefs->java_enabled = false;
2021 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402022 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062023
[email protected]64d69de42012-02-06 00:19:542024 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2025 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062026
[email protected]64d69de42012-02-06 00:19:542027 web_prefs->memory_info_enabled =
2028 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2029 web_prefs->allow_displaying_insecure_content =
2030 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2031 web_prefs->allow_running_insecure_content =
2032 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322033#if defined(OS_ANDROID)
2034 web_prefs->font_scale_factor =
2035 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2036 web_prefs->force_enable_zoom =
2037 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:452038#if defined(GOOGLE_TV)
2039 web_prefs->user_gesture_required_for_media_playback = false;
2040#endif
[email protected]d3b935f2012-10-19 23:14:322041#endif
[email protected]5c915252013-05-07 13:15:392042
[email protected]af4256d52013-06-04 20:39:072043#if defined(OS_ANDROID)
2044 web_prefs->password_echo_enabled =
2045 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2046#else
[email protected]9d06d88d2012-02-23 22:37:082047 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072048#endif
2049
[email protected]5c915252013-05-07 13:15:392050#if defined(OS_CHROMEOS)
2051 // Enable password echo during OOBE when keyboard driven flag is set.
2052 if (chromeos::UserManager::IsInitialized() &&
2053 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
2054 !chromeos::StartupUtils::IsOobeCompleted()) {
2055 bool keyboard_driven_oobe = false;
2056 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]0071aed32013-06-19 13:39:552057 chromeos::system::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:392058 if (keyboard_driven_oobe)
2059 web_prefs->password_echo_enabled = true;
2060 }
2061#endif
[email protected]f3986f82012-01-03 20:00:062062
[email protected]46f8e742013-05-03 18:37:142063#if defined(OS_ANDROID)
2064 web_prefs->user_style_sheet_enabled = false;
2065#else
[email protected]64d69de42012-02-06 00:19:542066 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152067 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362068 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152069 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542070 web_prefs->user_style_sheet_enabled = true;
2071 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152072 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542073 } else {
2074 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062075 }
[email protected]46f8e742013-05-03 18:37:142076#endif
[email protected]f3986f82012-01-03 20:00:062077
[email protected]cfadadd2013-04-03 04:43:022078 web_prefs->asynchronous_spell_checking_enabled = true;
2079 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572080
[email protected]64d69de42012-02-06 00:19:542081 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062082 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542083 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062084 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542085 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062086 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2087
2088 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542089 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062090 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542091 web_prefs->default_encoding);
2092 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402093 prefs->ClearPref(prefs::kDefaultCharset);
2094 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062095 }
[email protected]64d69de42012-02-06 00:19:542096 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062097
[email protected]88ecf66d2012-12-11 22:53:472098 if (content::IsForceCompositingModeEnabled())
2099 web_prefs->force_compositing_mode = true;
2100
[email protected]299d7f12012-05-23 05:31:152101 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232102 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132103 ExtensionService* service =
2104 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062105 if (service) {
[email protected]1bc28312012-11-08 08:31:532106 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2107 const Extension* extension = service->extensions()->GetByID(url.host());
2108 // Ensure that we are only granting extension preferences to URLs with
2109 // the correct scheme. Without this check, chrome-guest:// schemes used by
2110 // webview tags as well as hosts that happen to match the id of an
2111 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422112 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532113 extension_webkit_preferences::SetPreferences(
2114 extension, view_type, web_prefs);
2115 }
[email protected]f3986f82012-01-03 20:00:062116 }
2117
[email protected]cb2edf22013-04-01 20:25:232118 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542119 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232120 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062121 // Disable all kinds of acceleration for background pages.
2122 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542123 web_prefs->force_compositing_mode = false;
2124 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062125 }
[email protected]2e21fe292012-03-02 22:52:322126
2127#if defined(FILE_MANAGER_EXTENSION)
2128 // Override the default of suppressing HW compositing for WebUI pages for the
2129 // file manager, which is implemented using WebUI but wants HW acceleration
2130 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532131 if (url.SchemeIs(extensions::kExtensionScheme) &&
2132 url.host() == kFileBrowserDomain) {
[email protected]2e21fe292012-03-02 22:52:322133 web_prefs->accelerated_compositing_enabled = true;
2134 web_prefs->accelerated_2d_canvas_enabled = true;
2135 }
2136#endif
[email protected]181a95ee2011-07-12 19:26:362137}
2138
2139void ChromeContentBrowserClient::UpdateInspectorSetting(
2140 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062141 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582142 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062143 DictionaryPrefUpdate update(
2144 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2145 prefs::kWebKitInspectorSettings);
2146 DictionaryValue* inspector_settings = update.Get();
2147 inspector_settings->SetWithoutPathExpansion(key,
2148 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362149}
2150
[email protected]b8148ac2011-07-13 22:03:252151void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2152 BrowserURLHandler* handler) {
2153 // Add the default URL handlers.
2154 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2155 BrowserURLHandler::null_handler());
2156 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2157 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2158
[email protected]b3adbd02011-11-30 22:23:272159 // about: handler. Must come before chrome: handler, since it will
2160 // rewrite about: urls to chrome: URLs and then expect chrome: to
2161 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252162 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2163 BrowserURLHandler::null_handler());
2164 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242165 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252166}
2167
2168void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372169 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582170 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472171 BrowsingDataRemover* remover =
2172 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552173 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2174 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252175 // BrowsingDataRemover takes care of deleting itself when done.
2176}
2177
2178void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372179 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582180 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472181 BrowsingDataRemover* remover =
2182 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232183 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552184 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252185 // BrowsingDataRemover takes care of deleting itself when done.
2186}
2187
[email protected]650b2d52013-02-10 03:41:452188base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322189 return download_util::GetDefaultDownloadDirectory();
2190}
2191
[email protected]c9b6eb62011-10-18 20:49:392192std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2193 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2194}
2195
[email protected]b7631cc2012-09-15 05:08:382196void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2197 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542198#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382199 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2200 scoped_ptr<ppapi::host::HostFactory>(
2201 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542202#endif
[email protected]b7631cc2012-09-15 05:08:382203}
2204
[email protected]0c7193742012-11-07 19:05:032205content::BrowserPpapiHost*
2206 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2207 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132208 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032209 while (!iter.Done()) {
2210 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2211 if (host->process() &&
2212 host->process()->GetData().id == plugin_process_id) {
2213 // Found the plugin.
2214 return host->browser_ppapi_host();
2215 }
2216 ++iter;
2217 }
2218 return NULL;
2219}
2220
[email protected]7b38b192013-03-23 18:39:312221bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2222 content::BrowserContext* browser_context, const GURL& site_url) {
2223 if (CommandLine::ForCurrentProcess()->HasSwitch(
2224 switches::kEnableBrowserPluginForAllViewTypes))
2225 return true;
2226
2227 Profile* profile = Profile::FromBrowserContext(browser_context);
2228 ExtensionService* service =
2229 extensions::ExtensionSystem::Get(profile)->extension_service();
2230 if (!service)
2231 return false;
2232
2233 const Extension* extension = service->extensions()->
2234 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2235 if (!extension)
2236 return false;
2237
[email protected]c2d2f102013-04-29 16:42:582238 return extension->HasAPIPermission(APIPermission::kWebView) ||
2239 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312240}
2241
[email protected]38cd8f7f2012-06-15 22:06:072242bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582243 content::BrowserContext* browser_context,
2244 const GURL& url,
[email protected]dda54822013-06-15 01:26:392245 bool private_api,
[email protected]157cc902012-11-02 06:31:582246 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402247#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372248 Profile* profile = Profile::FromBrowserContext(browser_context);
2249 const ExtensionSet* extension_set = NULL;
2250 if (profile) {
2251 extension_set = extensions::ExtensionSystem::Get(profile)->
2252 extension_service()->extensions();
2253 }
[email protected]dda54822013-06-15 01:26:392254
2255 if (private_api) {
2256 // Access to private socket APIs is controlled by the whitelist.
2257 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2258 allowed_socket_origins_)) {
2259 return true;
2260 }
2261 } else {
2262 // Access to public socket APIs is controlled by extension permissions.
2263 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2264 extension_set) {
2265 const Extension* extension = extension_set->GetByID(url.host());
2266 if (extension) {
2267 extensions::SocketPermission::CheckParam check_params(
2268 params.type, params.host, params.port);
2269 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2270 extension, extensions::APIPermission::kSocket, &check_params)) {
2271 return true;
2272 }
2273 }
2274 }
2275 }
2276
2277 // Allow both public and private APIs if the command line says so.
2278 return IsHostAllowedByCommandLine(url, extension_set,
2279 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402280#else
[email protected]a658d452012-03-02 12:45:292281 return false;
[email protected]93f72062013-05-29 20:29:402282#endif
[email protected]e461da2f2012-02-16 19:06:402283}
2284
[email protected]650b2d52013-02-10 03:41:452285base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2286 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142287 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2288 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2289}
2290
[email protected]a28e3302013-02-03 03:50:432291ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2292 WebContents* web_contents) {
2293 return new ChromeSelectFilePolicy(web_contents);
2294}
2295
[email protected]7d9424702013-04-14 13:14:162296void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2297 std::vector<std::string>* additional_allowed_schemes) {
2298 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2299 additional_allowed_schemes);
2300 additional_allowed_schemes->push_back(kChromeUIScheme);
2301 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2302}
2303
[email protected]02250952013-04-24 23:52:532304void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2305 const base::FilePath& storage_partition_path,
[email protected]b40015c2013-06-26 08:13:312306 quota::SpecialStoragePolicy* special_storage_policy,
2307 fileapi::ExternalMountPoints* external_mount_points,
[email protected]02250952013-04-24 23:52:532308 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2309#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032310 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]02250952013-04-24 23:52:532311 additional_providers->push_back(new MediaFileSystemMountPointProvider(
[email protected]30a306f42013-06-10 03:09:032312 storage_partition_path,
2313 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]e66f02632013-06-13 22:51:502314 MediaFileSystemMountPointProvider::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532315#endif
[email protected]b40015c2013-06-26 08:13:312316#if defined(OS_CHROMEOS)
2317 DCHECK(external_mount_points);
2318 chromeos::CrosMountPointProvider* cros_mount_provider =
2319 new chromeos::CrosMountPointProvider(
[email protected]0ec5f5f2013-07-04 09:13:582320 new drive::MountPointProviderDelegate(external_mount_points),
[email protected]b40015c2013-06-26 08:13:312321 special_storage_policy,
2322 external_mount_points,
2323 fileapi::ExternalMountPoints::GetSystemInstance());
2324 cros_mount_provider->AddSystemMountPoints();
2325 DCHECK(cros_mount_provider->CanHandleType(fileapi::kFileSystemTypeExternal));
2326 additional_providers->push_back(cros_mount_provider);
2327#endif
[email protected]02250952013-04-24 23:52:532328}
2329
[email protected]e60c0232011-11-11 19:56:352330#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182331void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2332 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382333 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082334 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392335#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452336 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392337 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2338 DCHECK(!data_path.empty());
2339
2340 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452341 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392342 base::PlatformFile f =
2343 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2344 DCHECK(f != base::kInvalidPlatformFileValue);
2345 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2346 FileDescriptor(f, true)));
2347
[email protected]650b2d52013-02-10 03:41:452348 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392349 data_path.AppendASCII("chrome_100_percent.pak");
2350 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2351 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372352 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392353 FileDescriptor(f, true)));
2354
2355 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452356 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392357 GetLocaleFilePath(locale, false);
2358 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2359 DCHECK(f != base::kInvalidPlatformFileValue);
2360 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2361 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382362
[email protected]650b2d52013-02-10 03:41:452363 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372364 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2365 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2366 DCHECK(f != base::kInvalidPlatformFileValue);
2367 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2368 FileDescriptor(f, true)));
2369
[email protected]40da3e0c2012-10-24 22:03:382370#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432371 if (IsCrashReporterEnabled()) {
2372 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2373 if (f == base::kInvalidPlatformFileValue) {
2374 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2375 "be disabled for this process.";
2376 } else {
2377 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2378 FileDescriptor(f, true)));
2379 }
[email protected]40da3e0c2012-10-24 22:03:382380 }
2381#endif // defined(USE_LINUX_BREAKPAD)
2382
2383#else
2384 int crash_signal_fd = GetCrashSignalFD(command_line);
2385 if (crash_signal_fd >= 0) {
2386 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2387 FileDescriptor(crash_signal_fd,
2388 false)));
2389 }
[email protected]29699c22012-10-03 23:57:392390#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302391}
[email protected]e60c0232011-11-11 19:56:352392#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302393
[email protected]4a65826d2011-08-25 16:04:012394#if defined(OS_WIN)
2395const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2396 return chrome::kBrowserResourcesDll;
2397}
[email protected]34f48682013-03-20 00:30:182398
2399void ChromeContentBrowserClient::PreSpawnRenderer(
2400 sandbox::TargetPolicy* policy,
2401 bool* success) {
2402 // This code is duplicated in nacl_exe_win_64.cc.
2403 // Allow the server side of a pipe restricted to the "chrome.nacl."
2404 // namespace so that it cannot impersonate other system or other chrome
2405 // service pipes.
2406 sandbox::ResultCode result = policy->AddRule(
2407 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2408 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2409 L"\\\\.\\pipe\\chrome.nacl.*");
2410 if (result != sandbox::SBOX_ALL_OK) {
2411 *success = false;
2412 return;
2413 }
2414
2415 // Renderers need to send named pipe handles and shared memory
2416 // segment handles to NaCl loader processes.
2417 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2418 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2419 L"File");
2420 if (result != sandbox::SBOX_ALL_OK) {
2421 *success = false;
2422 return;
2423 }
2424}
[email protected]4a65826d2011-08-25 16:04:012425#endif
2426
[email protected]37a72af2011-06-13 05:42:012427#if defined(USE_NSS)
2428crypto::CryptoModuleBlockingPasswordDelegate*
2429 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2430 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292431 return chrome::NewCryptoModuleBlockingDialogDelegate(
2432 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012433}
2434#endif
2435
[email protected]d977f9c2011-03-14 16:10:262436} // namespace chrome