blob: 5abfa6ce2538a5c407410ced9a78e5d16d08ead3 [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]f19bbf62013-07-09 01:22:32151#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h"
152#include "chrome/browser/chromeos/fileapi/file_system_backend.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)
[email protected]f19bbf62013-07-09 01:22:32190#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53191#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]855e18b2013-07-08 21:02:00197#if defined(ENABLE_INPUT_SPEECH)
198#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
199#endif
200
[email protected]02a3dc122013-06-13 15:07:53201#if defined(FILE_MANAGER_EXTENSION)
202#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
203#endif
204
[email protected]c7abd422012-09-25 00:20:08205using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47206using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03207using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39208using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31209using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59210using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08211using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00212using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11213using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33214using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13215using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06216using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34217using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40218using extensions::Manifest;
[email protected]631bb742011-11-02 11:29:39219
[email protected]c5dbef02011-05-13 05:06:09220namespace {
221
[email protected]eabbfb12013-04-05 23:28:35222// Cached version of the locale so we can return the locale on the I/O
223// thread.
224base::LazyInstance<std::string> g_io_thread_application_locale;
225
[email protected]93f72062013-05-29 20:29:40226#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40227const char* kPredefinedAllowedSocketOrigins[] = {
228 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18229 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45230 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
231 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
232 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
233 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35234 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54235 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
236 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
237 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
238 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
239 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
240 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38241 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58242 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29243 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]f6599915a2013-06-20 20:03:50244 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
[email protected]b71313232013-05-06 06:16:29245 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
246 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
247 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
248 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40249};
[email protected]93f72062013-05-29 20:29:40250#endif
[email protected]e461da2f2012-02-16 19:06:40251
[email protected]f8f93eb2012-09-25 03:06:24252// Returns a copy of the given url with its host set to given host and path set
253// to given path. Other parts of the url will be the same.
254GURL ReplaceURLHostAndPath(const GURL& url,
255 const std::string& host,
256 const std::string& path) {
257 url_canon::Replacements<char> replacements;
258 replacements.SetHost(host.c_str(),
259 url_parse::Component(0, host.length()));
260 replacements.SetPath(path.c_str(),
261 url_parse::Component(0, path.length()));
262 return url.ReplaceComponents(replacements);
263}
264
265// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
266GURL AddUberHost(const GURL& url) {
267 const std::string uber_host = chrome::kChromeUIUberHost;
268 const std::string new_path = url.host() + url.path();
269
270 return ReplaceURLHostAndPath(url, uber_host, new_path);
271}
272
[email protected]045bf7c2012-09-28 20:27:36273// If url->host() is "chrome" and url->path() has characters other than the
274// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
275// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24276bool RemoveUberHost(GURL* url) {
277 if (url->host() != chrome::kChromeUIUberHost)
278 return false;
279
[email protected]045bf7c2012-09-28 20:27:36280 if (url->path().empty() || url->path() == "/")
281 return false;
282
[email protected]f8f93eb2012-09-25 03:06:24283 const std::string old_path = url->path();
284
285 const std::string::size_type separator = old_path.find('/', 1);
286 std::string new_host;
287 std::string new_path;
288 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36289 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24290 } else {
291 new_host = old_path.substr(1, separator - 1);
292 new_path = old_path.substr(separator);
293 }
294
[email protected]44e8add2013-06-13 17:29:15295 // Do not allow URLs with paths empty before the first slash since we can't
296 // have an empty host. (e.g "foo://chrome//")
297 if (new_host.empty())
298 return false;
299
[email protected]f8f93eb2012-09-25 03:06:24300 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
301
[email protected]44e8add2013-06-13 17:29:15302 DCHECK(url->is_valid());
303
[email protected]f8f93eb2012-09-25 03:06:24304 return true;
305}
306
[email protected]b8148ac2011-07-13 22:03:25307// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42308bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24309 // Do not handle special URLs such as "about:foo"
310 if (!url->host().empty()) {
311 const GURL chrome_url = AddUberHost(*url);
312
313 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
314 // be called.
315 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
316 browser_context, chrome_url))
317 return true;
318 }
319
[email protected]863f70a2012-01-27 02:05:50320 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
321 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25322 return false;
323
[email protected]fe69558d2012-03-12 11:34:49324#if defined(OS_CHROMEOS)
325 // Special case : in ChromeOS in Guest mode bookmarks and history are
326 // disabled for security reasons. New tab page explains the reasons, so
327 // we redirect user to new tab page.
328 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
329 if (url->SchemeIs(chrome::kChromeUIScheme) &&
330 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
331 url->DomainIs(chrome::kChromeUIHistoryHost))) {
332 // Rewrite with new tab URL
333 *url = GURL(chrome::kChromeUINewTabURL);
334 }
335 }
336#endif
337
[email protected]b8148ac2011-07-13 22:03:25338 // Special case the new tab page. In older versions of Chrome, the new tab
339 // page was hosted at chrome-internal:<blah>. This might be in people's saved
340 // sessions or bookmarks, so we say any URL with that scheme triggers the new
341 // tab page.
342 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
343 // Rewrite it with the proper new tab URL.
344 *url = GURL(chrome::kChromeUINewTabURL);
345 }
346
347 return true;
348}
349
[email protected]f8f93eb2012-09-25 03:06:24350// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
351// "chrome://foo/".
352bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
353 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
354 return false;
355
356 return RemoveUberHost(url);
357}
358
[email protected]8d3132f62011-10-12 07:13:42359// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
360// below. Extension, and isolated apps require different privileges to be
361// granted to their RenderProcessHosts. This classification allows us to make
362// sure URLs are served by hosts with the right set of privileges.
363enum RenderProcessHostPrivilege {
364 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45365 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42366 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45367 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42368};
369
370RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
371 const GURL& url,
372 ExtensionService* service) {
373 // Default to a normal renderer cause it is lower privileged. This should only
374 // occur if the URL on a site instance is either malformed, or uninitialized.
375 // If it is malformed, then there is no need for better privileges anyways.
376 // If it is uninitialized, but eventually settles on being an a scheme other
377 // than normal webrenderer, the navigation logic will correct us out of band
378 // anyways.
379 if (!url.is_valid())
380 return PRIV_NORMAL;
381
[email protected]885c0e92012-11-13 20:27:42382 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44383 const Extension* extension =
384 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43385 if (extension &&
386 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42387 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45388 if (extension && extension->is_hosted_app())
389 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42390
391 return PRIV_EXTENSION;
392 }
393
394 return PRIV_NORMAL;
395}
396
397RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30398 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46399 extensions::ProcessMap* process_map,
400 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46401 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30402 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46403 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21404 return PRIV_NORMAL;
405
[email protected]6f371442011-11-09 06:45:46406 for (std::set<std::string>::iterator iter = extension_ids.begin();
407 iter != extension_ids.end(); ++iter) {
408 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43409 if (extension &&
410 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42411 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45412 if (extension && extension->is_hosted_app())
413 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42414 }
415
[email protected]676f6ab2011-10-19 20:23:21416 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42417}
418
[email protected]6786bf402011-12-03 15:19:45419bool CertMatchesFilter(const net::X509Certificate& cert,
420 const base::DictionaryValue& filter) {
421 // TODO(markusheintz): This is the minimal required filter implementation.
422 // Implement a better matcher.
423
424 // An empty filter matches any client certificate since no requirements are
425 // specified at all.
426 if (filter.empty())
427 return true;
428
429 std::string common_name;
430 if (filter.GetString("ISSUER.CN", &common_name) &&
431 (cert.issuer().common_name == common_name)) {
432 return true;
433 }
434 return false;
435}
436
[email protected]f3986f82012-01-03 20:00:06437// Fills |map| with the per-script font prefs under path |map_name|.
438void FillFontFamilyMap(const PrefService* prefs,
439 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53440 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06441 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
442 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
443 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
444 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23445 if (!font_family.empty())
446 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06447 }
448}
449
[email protected]a1733df2012-06-22 11:24:18450#if defined(OS_POSIX) && !defined(OS_MACOSX)
451int GetCrashSignalFD(const CommandLine& command_line) {
452 if (command_line.HasSwitch(switches::kExtensionProcess)) {
453 ExtensionCrashHandlerHostLinux* crash_handler =
454 ExtensionCrashHandlerHostLinux::GetInstance();
455 return crash_handler->GetDeathSignalSocket();
456 }
457
458 std::string process_type =
459 command_line.GetSwitchValueASCII(switches::kProcessType);
460
461 if (process_type == switches::kRendererProcess)
462 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
463
464 if (process_type == switches::kPluginProcess)
465 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
466
467 if (process_type == switches::kPpapiPluginProcess)
468 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
469
470 if (process_type == switches::kGpuProcess)
471 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
472
473 return -1;
474}
475#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
476
[email protected]d5bcd06f2013-04-21 08:07:24477#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30478GURL GetEffectiveURLForSignin(const GURL& url) {
479 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
480
481 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03482 // Copy the path because the argument to SetPathStr must outlive
483 // the Replacements object.
484 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30485 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03486 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30487 effective_url = effective_url.ReplaceComponents(replacements);
488 return effective_url;
489}
[email protected]d5bcd06f2013-04-21 08:07:24490#endif
[email protected]970c63e2013-03-07 00:25:30491
[email protected]eabbfb12013-04-05 23:28:35492void SetApplicationLocaleOnIOThread(const std::string& locale) {
493 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
494 g_io_thread_application_locale.Get() = locale;
495}
496
[email protected]9dbfff12011-07-01 19:37:07497} // namespace
[email protected]c5dbef02011-05-13 05:06:09498
[email protected]d977f9c2011-03-14 16:10:26499namespace chrome {
500
[email protected]e461da2f2012-02-16 19:06:40501ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40502#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40503 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
504 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40505#endif
[email protected]1deace22013-05-22 06:14:46506
507 permissions_policy_delegate_.reset(
508 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40509}
510
511ChromeContentBrowserClient::~ChromeContentBrowserClient() {
512}
513
[email protected]bca18382012-06-25 19:15:23514// static
[email protected]37ca3fe02013-07-05 15:32:44515void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34516 user_prefs::PrefRegistrySyncable* registry) {
517 registry->RegisterBooleanPref(
518 prefs::kDisable3DAPIs,
519 false,
520 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
521 registry->RegisterBooleanPref(
522 prefs::kEnableHyperlinkAuditing,
523 true,
524 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
525 registry->RegisterBooleanPref(
526 prefs::kEnableMemoryInfo,
527 false,
528 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23529}
530
[email protected]eabbfb12013-04-05 23:28:35531// static
532void ChromeContentBrowserClient::SetApplicationLocale(
533 const std::string& locale) {
534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
535
536 // This object is guaranteed to outlive all threads so we don't have to
537 // worry about the lack of refcounting and can just post as Unretained.
538 //
539 // The common case is that this function is called early in Chrome startup
540 // before any threads are created (it will also be called later if the user
541 // changes the pref). In this case, there will be no threads created and
542 // posting will fail. When there are no threads, we can just set the string
543 // without worrying about threadsafety.
544 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
545 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
546 g_io_thread_application_locale.Get() = locale;
547 }
548}
549
[email protected]50462bf02011-11-21 19:13:31550content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
551 const content::MainFunctionParams& parameters) {
552 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30553 // Construct the Main browser parts based on the OS type.
554#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31555 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04556#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31557 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30558#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22559 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26560#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31561 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14562#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09563 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30564#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31565 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04566#else
[email protected]b48c9182011-10-26 18:03:30567 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31568 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30569#endif
570
[email protected]7e75e4a2013-05-17 17:20:03571 chrome::AddProfilesExtraParts(main_parts);
572
[email protected]c7480942011-11-08 19:18:27573 // Construct additional browser parts. Stages are called in the order in
574 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22575#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41576 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04577#endif
[email protected]c7480942011-11-08 19:18:27578
579#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41580 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27581#endif
582
[email protected]dc04be7c2012-03-15 23:57:49583#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41584 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49585#endif
586
[email protected]e050ef142012-03-21 01:04:24587#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41588 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24589#endif
590
[email protected]95132f52013-04-12 02:19:04591 chrome::AddMetricsExtraParts(main_parts);
592
[email protected]50462bf02011-11-21 19:13:31593 return main_parts;
[email protected]f967b722011-09-07 00:58:04594}
595
[email protected]e94bbcb2012-09-07 05:33:57596std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19597 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57598 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53599 std::string partition_id;
600
601 // The partition ID for webview guest processes is the string value of its
602 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
603 if (site.SchemeIs(chrome::kGuestScheme))
604 partition_id = site.spec();
605
[email protected]056efdc2013-04-06 00:14:53606 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53607 return partition_id;
608}
609
610bool ChromeContentBrowserClient::IsValidStoragePartitionId(
611 content::BrowserContext* browser_context,
612 const std::string& partition_id) {
613 // The default ID is empty and is always valid.
614 if (partition_id.empty())
615 return true;
616
617 return GURL(partition_id).is_valid();
618}
619
620void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
621 content::BrowserContext* browser_context,
622 const GURL& site,
[email protected]14acc642012-11-17 12:20:10623 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53624 std::string* partition_domain,
625 std::string* partition_name,
626 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10627 // Default to the browser-wide storage partition and override based on |site|
628 // below.
629 partition_domain->clear();
630 partition_name->clear();
631 *in_memory = false;
632
[email protected]1bc28312012-11-08 08:31:53633 // For the webview tag, we create special guest processes, which host the
634 // tag content separately from the main application that embeds the tag.
635 // A webview tag can specify both the partition name and whether the storage
636 // for that partition should be persisted. Each tag gets a SiteInstance with
637 // a specially formatted URL, based on the application it is hosted by and
638 // the partition requested by it. The format for that URL is:
639 // chrome-guest://partition_domain/persist?partition_name
640 if (site.SchemeIs(chrome::kGuestScheme)) {
641 // Since guest URLs are only used for packaged apps, there must be an app
642 // id in the URL.
643 CHECK(site.has_host());
644 *partition_domain = site.host();
645 // Since persistence is optional, the path must either be empty or the
646 // literal string.
647 *in_memory = (site.path() != "/persist");
648 // The partition name is user supplied value, which we have encoded when the
649 // URL was created, so it needs to be decoded.
650 *partition_name = net::UnescapeURLComponent(site.query(),
651 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10652 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
653 // If |can_be_default| is false, the caller is stating that the |site|
654 // should be parsed as if it had isolated storage. In particular it is
655 // important to NOT check ExtensionService for the is_storage_isolated()
656 // attribute because this code path is run during Extension uninstall
657 // to do cleanup after the Extension has already been unloaded from the
658 // ExtensionService.
659 bool is_isolated = !can_be_default;
660 if (can_be_default) {
661 const Extension* extension = NULL;
662 Profile* profile = Profile::FromBrowserContext(browser_context);
663 ExtensionService* extension_service =
664 extensions::ExtensionSystem::Get(profile)->extension_service();
665 if (extension_service) {
666 extension = extension_service->extensions()->
667 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43668 if (extension &&
669 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10670 is_isolated = true;
671 }
672 }
673 }
[email protected]1bc28312012-11-08 08:31:53674
[email protected]14acc642012-11-17 12:20:10675 if (is_isolated) {
676 CHECK(site.has_host());
677 // For extensions with isolated storage, the the host of the |site| is
678 // the |partition_domain|. The |in_memory| and |partition_name| are only
679 // used in guest schemes so they are cleared here.
680 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53681 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10682 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53683 }
[email protected]d1198fd2012-08-13 22:50:19684 }
685
[email protected]14acc642012-11-17 12:20:10686 // Assert that if |can_be_default| is false, the code above must have found a
687 // non-default partition. If this fails, the caller has a serious logic
688 // error about which StoragePartition they expect to be in and it is not
689 // safe to continue.
690 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44691}
692
[email protected]38b098f2012-03-14 21:11:57693content::WebContentsViewDelegate*
694 ChromeContentBrowserClient::GetWebContentsViewDelegate(
695 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27696 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32697}
698
[email protected]24665682013-02-25 20:59:38699// Check if the extension activity log is enabled for the profile.
700static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33701 // crbug.com/247908 - This should be IsLogEnabled except for an issue
702 // in chrome_frame_net_tests
703 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38704}
705
[email protected]738f57a2013-06-29 21:06:54706void ChromeContentBrowserClient::GuestWebContentsCreated(
707 WebContents* guest_web_contents,
708 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22709 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54710 scoped_ptr<base::DictionaryValue> extra_params) {
711 if (opener_web_contents) {
712 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
713 if (!guest) {
714 NOTREACHED();
715 return;
716 }
717
718 switch (guest->GetViewType()) {
719 case GuestView::WEBVIEW: {
[email protected]4c0e8272013-07-03 23:39:22720 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54721 break;
722 }
723 case GuestView::ADVIEW: {
[email protected]4c0e8272013-07-03 23:39:22724 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54725 break;
726 }
727 default:
728 NOTREACHED();
729 break;
730 }
731 return;
732 }
733
734 if (!extra_params) {
735 NOTREACHED();
736 return;
737 }
738 std::string api_type;
739 extra_params->GetString(guestview::kAttributeApi, &api_type);
740
741 if (api_type == "adview") {
[email protected]4c0e8272013-07-03 23:39:22742 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54743 } else if (api_type == "webview") {
[email protected]4c0e8272013-07-03 23:39:22744 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54745 } else {
746 NOTREACHED();
747 }
748}
749
[email protected]44295a12013-06-05 08:45:46750void ChromeContentBrowserClient::GuestWebContentsAttached(
751 WebContents* guest_web_contents,
752 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53753 int browser_plugin_instance_id,
754 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06755 Profile* profile = Profile::FromBrowserContext(
756 embedder_web_contents->GetBrowserContext());
757 ExtensionService* service =
758 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54759 if (!service) {
760 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06761 return;
[email protected]738f57a2013-06-29 21:06:54762 }
[email protected]44703cc72013-01-24 04:56:06763 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
764 const Extension* extension = service->extensions()->
765 GetExtensionOrAppByURL(ExtensionURLInfo(url));
[email protected]738f57a2013-06-29 21:06:54766 if (!extension) {
[email protected]18699372013-06-25 20:42:55767 NOTREACHED();
[email protected]738f57a2013-06-29 21:06:54768 return;
[email protected]18699372013-06-25 20:42:55769 }
[email protected]738f57a2013-06-29 21:06:54770
771 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
772 if (!guest) {
773 NOTREACHED();
774 return;
775 }
776 guest->Attach(embedder_web_contents,
777 extension->id(),
778 browser_plugin_instance_id,
779 extra_params);
[email protected]44703cc72013-01-24 04:56:06780}
781
[email protected]f3b1a082011-11-18 00:34:30782void ChromeContentBrowserClient::RenderProcessHostCreated(
783 content::RenderProcessHost* host) {
784 int id = host->GetID();
785 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41786 net::URLRequestContextGetter* context =
787 profile->GetRequestContextForRenderProcess(id);
788
[email protected]f3b1a082011-11-18 00:34:30789 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41790 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55791#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30792 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55793#endif
[email protected]658677f2012-06-09 06:04:02794#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08795 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03796#endif
[email protected]f3b1a082011-11-18 00:34:30797 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02798 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30799 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56800#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21801 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56802#endif
[email protected]43535512013-02-20 20:41:41803 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
804 id, profile, context));
[email protected]2736c032012-05-11 18:06:07805 host->GetChannel()->AddFilter(
806 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27807 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33808 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31809#if defined(ENABLE_WEBRTC)
810 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
811#endif
[email protected]01e59752013-06-18 00:17:35812#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03813 ExtensionInfoMap* extension_info_map =
814 extensions::ExtensionSystem::Get(profile)->info_map();
815 host->GetChannel()->AddFilter(new NaClHostMessageFilter(
816 id, profile->IsOffTheRecord(),
817 profile->GetPath(), extension_info_map,
818 context));
[email protected]01e59752013-06-18 00:17:35819#endif
[email protected]3e69bc82011-05-26 23:22:38820
[email protected]2ccf45c2011-08-19 23:35:50821 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
822 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07823
[email protected]24665682013-02-25 20:59:38824 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
825 IsExtensionActivityLogEnabledForProfile(profile)));
826
[email protected]39a5b532011-10-22 01:47:07827 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56828
829 RendererContentSettingRules rules;
830 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
831 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14832}
833
[email protected]95c95552013-05-03 04:21:22834GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
835 content::BrowserContext* browser_context,
836 const GURL& url,
837 bool is_renderer_initiated,
838 content::SiteInstance* current_instance) {
839 Profile* profile = Profile::FromBrowserContext(browser_context);
840 if (!profile)
841 return url;
842
843 // Only return the privileged instant URL if we are entering from a browser-
844 // initiated navigation or if we are already in the instant process.
845 bool is_instant_process = false;
846 int process_id = current_instance->GetProcess()->GetID();
847 InstantService* instant_service =
848 InstantServiceFactory::GetForProfile(profile);
849 if (instant_service)
850 is_instant_process = instant_service->IsInstantProcess(process_id);
851
852 DCHECK_EQ(is_instant_process,
853 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
854 if (!is_renderer_initiated || is_instant_process) {
855 // If the input |url| should be assigned to the Instant renderer, make its
856 // privileged URL distinct from other URLs on the search provider's domain.
857 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
858 return chrome::GetPrivilegedURLForInstant(url, profile);
859 }
860
861 return url;
862}
863
[email protected]3d7474ff2011-07-27 17:47:37864GURL ChromeContentBrowserClient::GetEffectiveURL(
865 content::BrowserContext* browser_context, const GURL& url) {
866 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52867 if (!profile)
868 return url;
869
[email protected]d5bcd06f2013-04-21 08:07:24870#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30871 // If the input |url| should be assigned to the Signin renderer, make its
872 // effective URL distinct from other URLs on the signin service's domain.
873 // Note that the signin renderer will be allowed to sign the user in to
874 // Chrome.
875 if (SigninManager::IsWebBasedSigninFlowURL(url))
876 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24877#endif
[email protected]970c63e2013-03-07 00:25:30878
[email protected]c5dec6292013-01-25 04:54:52879 // If the input |url| is part of an installed app, the effective URL is an
880 // extension URL with the ID of that extension as the host. This has the
881 // effect of grouping apps together in a common SiteInstance.
882 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13883 extensions::ExtensionSystem::Get(profile)->extension_service();
884 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08885 return url;
886
[email protected]06bdd2b2012-11-30 18:47:13887 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44888 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08889 if (!extension)
890 return url;
891
[email protected]15877ca2011-11-18 22:40:52892 // Bookmark apps do not use the hosted app process model, and should be
893 // treated as normal URLs.
894 if (extension->from_bookmark())
895 return url;
896
[email protected]36fb2c7c2011-04-04 15:49:08897 // If the URL is part of an extension's web extent, convert it to an
898 // extension URL.
899 return extension->GetResourceURL(url.path());
900}
901
[email protected]056ad2a2011-07-12 02:13:55902bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37903 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52904 // Non-extension, non-Instant URLs should generally use
905 // process-per-site-instance. Because we expect to use the effective URL,
906 // URLs for hosted apps (apart from bookmark apps) should have an extension
907 // scheme by now.
908
909 Profile* profile = Profile::FromBrowserContext(browser_context);
910 if (!profile)
911 return false;
912
[email protected]165fe422013-03-27 06:34:03913 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52914 return true;
915
[email protected]d5bcd06f2013-04-21 08:07:24916#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30917 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
918 return true;
[email protected]d5bcd06f2013-04-21 08:07:24919#endif
[email protected]970c63e2013-03-07 00:25:30920
[email protected]885c0e92012-11-13 20:27:42921 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55922 return false;
923
[email protected]c5dec6292013-01-25 04:54:52924 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13925 extensions::ExtensionSystem::Get(profile)->extension_service();
926 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55927 return false;
928
[email protected]06bdd2b2012-11-30 18:47:13929 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44930 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55931 if (!extension)
932 return false;
933
934 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53935 // permission, or that does not allow JavaScript access to the background
936 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55937 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40938 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06939 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29940 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53941 return false;
942 }
943 }
[email protected]056ad2a2011-07-12 02:13:55944
[email protected]7b54ca02012-03-02 18:06:53945 // Hosted apps that have script access to their background page must use
946 // process per site, since all instances can make synchronous calls to the
947 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55948 return true;
949}
950
[email protected]672c8c12013-03-07 12:30:06951// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41952void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
953 std::vector<std::string>* additional_schemes) {
954 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06955}
956
[email protected]6bd30072013-02-08 18:17:11957net::URLRequestContextGetter*
958ChromeContentBrowserClient::CreateRequestContext(
959 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06960 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11961 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06962 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11963}
964
965net::URLRequestContextGetter*
966ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
967 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40968 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11969 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06970 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11971 Profile* profile = Profile::FromBrowserContext(browser_context);
972 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06973 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11974}
975
[email protected]46fb9442011-12-09 17:57:47976bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
977 return ProfileIOData::IsHandledURL(url);
978}
979
[email protected]c4365fa42013-05-14 01:08:24980bool ChromeContentBrowserClient::CanCommitURL(
981 content::RenderProcessHost* process_host,
982 const GURL& url) {
983 // We need to let most extension URLs commit in any process, since this can
984 // be allowed due to web_accessible_resources. Most hosted app URLs may also
985 // load in any process (e.g., in an iframe). However, the Chrome Web Store
986 // cannot be loaded in iframes and should never be requested outside its
987 // process.
988 Profile* profile =
989 Profile::FromBrowserContext(process_host->GetBrowserContext());
990 ExtensionService* service =
991 extensions::ExtensionSystem::Get(profile)->extension_service();
992 if (!service)
993 return true;
994 const Extension* new_extension =
995 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
996 if (new_extension &&
997 new_extension->is_hosted_app() &&
998 new_extension->id() == extension_misc::kWebStoreAppId &&
999 !service->process_map()->Contains(new_extension->id(),
1000 process_host->GetID())) {
1001 return false;
1002 }
1003
1004 return true;
1005}
1006
[email protected]2a5221b2011-09-27 23:07:311007bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301008 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311009 const GURL& site_url) {
1010 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301011 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521012 // This may be NULL during tests. In that case, just assume any site can
1013 // share any host.
1014 if (!profile)
1015 return true;
1016
[email protected]d43f99fe2013-04-03 00:20:141017 // Instant URLs should only be in the instant process and instant process
1018 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521019 InstantService* instant_service =
1020 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141021 if (instant_service) {
1022 bool is_instant_process = instant_service->IsInstantProcess(
1023 process_host->GetID());
1024 bool should_be_in_instant_process =
1025 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1026 if (is_instant_process || should_be_in_instant_process)
1027 return is_instant_process && should_be_in_instant_process;
1028 }
[email protected]c5dec6292013-01-25 04:54:521029
[email protected]d5bcd06f2013-04-21 08:07:241030#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301031 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1032 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1033 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241034#endif
[email protected]970c63e2013-03-07 00:25:301035
[email protected]06bdd2b2012-11-30 18:47:131036 ExtensionService* service =
1037 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461038 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311039
[email protected]ffa97602011-11-17 17:55:521040 // Don't allow the Task Manager to share a process with anything else.
1041 // Otherwise it can affect the renderers it is observing.
1042 // Note: we could create another RenderProcessHostPrivilege bucket for
1043 // this to allow multiple chrome://tasks instances to share, but that's
1044 // a very unlikely case without serious consequences.
1045 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1046 return false;
1047
[email protected]8d3132f62011-10-12 07:13:421048 // These may be NULL during tests. In that case, just assume any site can
1049 // share any host.
[email protected]6f371442011-11-09 06:45:461050 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311051 return true;
1052
[email protected]eec0b33c2011-12-05 22:09:451053 // Otherwise, just make sure the process privilege matches the privilege
1054 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571055 RenderProcessHostPrivilege privilege_required =
1056 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451057 return GetProcessPrivilege(process_host, process_map, service) ==
1058 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311059}
1060
[email protected]76411f412012-02-22 18:56:061061// This function is trying to limit the amount of processes used by extensions
1062// with background pages. It uses a globally set percentage of processes to
1063// run such extensions and if the limit is exceeded, it returns true, to
1064// indicate to the content module to group extensions together.
1065bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1066 content::BrowserContext* browser_context, const GURL& url) {
1067 // It has to be a valid URL for us to check for an extension.
1068 if (!url.is_valid())
1069 return false;
1070
1071 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191072 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131073 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061074 if (!service)
1075 return false;
1076
1077 // We have to have a valid extension with background page to proceed.
1078 const Extension* extension =
1079 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
1080 if (!extension)
1081 return false;
[email protected]9367eabc2013-03-01 01:29:291082 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061083 return false;
1084
1085 std::set<int> process_ids;
1086 size_t max_process_count =
1087 content::RenderProcessHost::GetMaxRendererProcessCount();
1088
1089 // Go through all profiles to ensure we have total count of extension
1090 // processes containing background pages, otherwise one profile can
1091 // starve the other.
1092 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1093 GetLoadedProfiles();
1094 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031095 ExtensionProcessManager* epm =
1096 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321097 for (ExtensionProcessManager::const_iterator iter =
1098 epm->background_hosts().begin();
1099 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131100 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321101 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061102 }
1103 }
1104
1105 if (process_ids.size() >
1106 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1107 return true;
1108 }
1109
1110 return false;
1111}
1112
[email protected]6f371442011-11-09 06:45:461113void ChromeContentBrowserClient::SiteInstanceGotProcess(
1114 SiteInstance* site_instance) {
1115 CHECK(site_instance->HasProcess());
1116
1117 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021118 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521119 if (!profile)
1120 return;
1121
1122 // Remember the ID of the Instant process to signal the renderer process
1123 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031124 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321125 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521126 InstantService* instant_service =
1127 InstantServiceFactory::GetForProfile(profile);
1128 if (instant_service)
1129 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1130 }
1131
[email protected]d5bcd06f2013-04-21 08:07:241132#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301133 // We only expect there to be one signin process as we use process-per-site
1134 // for signin URLs. The signin process will be cleared from SigninManager
1135 // when the renderer is destroyed.
1136 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1137 SigninManager* signin_manager =
1138 SigninManagerFactory::GetForProfile(profile);
1139 if (signin_manager)
1140 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461141 BrowserThread::PostTask(
1142 BrowserThread::IO, FROM_HERE,
1143 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1144 extensions::ExtensionSystem::Get(profile)->info_map(),
1145 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301146 }
[email protected]d5bcd06f2013-04-21 08:07:241147#endif
[email protected]970c63e2013-03-07 00:25:301148
[email protected]06bdd2b2012-11-30 18:47:131149 ExtensionService* service =
1150 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461151 if (!service)
1152 return;
1153
1154 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441155 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591156 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461157 if (!extension)
1158 return;
1159
[email protected]6bc04fd82011-12-04 02:29:351160 service->process_map()->Insert(extension->id(),
1161 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331162 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461163 BrowserThread::PostTask(
1164 BrowserThread::IO, FROM_HERE,
1165 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591166 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461167 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351168 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331169 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461170}
1171
1172void ChromeContentBrowserClient::SiteInstanceDeleting(
1173 SiteInstance* site_instance) {
1174 if (!site_instance->HasProcess())
1175 return;
1176
1177 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021178 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131179 ExtensionService* service =
1180 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461181 if (!service)
1182 return;
1183
1184 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441185 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591186 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461187 if (!extension)
1188 return;
1189
[email protected]6bc04fd82011-12-04 02:29:351190 service->process_map()->Remove(extension->id(),
1191 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331192 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461193 BrowserThread::PostTask(
1194 BrowserThread::IO, FROM_HERE,
1195 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591196 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461197 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351198 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331199 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461200}
1201
[email protected]f05763972012-06-06 18:17:261202bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141203 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081204 const GURL& current_url,
1205 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261206 if (current_url.is_empty()) {
1207 // Always choose a new process when navigating to extension URLs. The
1208 // process grouping logic will combine all of a given extension's pages
1209 // into the same process.
[email protected]885c0e92012-11-13 20:27:421210 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261211 return true;
[email protected]e3daf3c2011-10-05 21:17:081212
[email protected]f05763972012-06-06 18:17:261213 return false;
1214 }
1215
1216 // Also, we must switch if one is an extension and the other is not the exact
1217 // same extension.
[email protected]885c0e92012-11-13 20:27:421218 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1219 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261220 if (current_url.GetOrigin() != new_url.GetOrigin())
1221 return true;
1222 }
1223
[email protected]e9841fbd2013-02-22 23:12:141224 // The checks below only matter if we can retrieve which extensions are
1225 // installed.
1226 Profile* profile =
1227 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1228 ExtensionService* service =
1229 extensions::ExtensionSystem::Get(profile)->extension_service();
1230 if (!service)
1231 return false;
1232
1233 // We must swap if the URL is for an extension and we are not using an
1234 // extension process.
1235 const Extension* new_extension =
1236 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1237 // Ignore all hosted apps except the Chrome Web Store, since they do not
1238 // require their own BrowsingInstance (e.g., postMessage is ok).
1239 if (new_extension &&
1240 new_extension->is_hosted_app() &&
1241 new_extension->id() != extension_misc::kWebStoreAppId)
1242 new_extension = NULL;
1243 if (new_extension &&
1244 site_instance->HasProcess() &&
1245 !service->process_map()->Contains(new_extension->id(),
1246 site_instance->GetProcess()->GetID()))
1247 return true;
1248
[email protected]f05763972012-06-06 18:17:261249 return false;
[email protected]e3daf3c2011-10-05 21:17:081250}
1251
[email protected]395045c2012-05-22 15:04:381252bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1253 content::ResourceContext* resource_context, const GURL& current_url,
1254 const GURL& new_url) {
1255 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1256 return extensions::CrossesExtensionProcessBoundary(
1257 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171258 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381259}
1260
[email protected]3d831992013-07-04 01:13:291261bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1262 return !url.SchemeIs(chrome::kChromeNativeScheme);
1263}
1264
[email protected]763ec4ca2011-04-29 15:48:121265std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1266 const std::string& alias_name) {
1267 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1268}
1269
[email protected]b80f68432011-05-02 17:22:301270void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1271 CommandLine* command_line, int child_process_id) {
1272#if defined(USE_LINUX_BREAKPAD)
1273 if (IsCrashReporterEnabled()) {
1274 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1275 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1276 }
1277#elif defined(OS_MACOSX)
1278 if (IsCrashReporterEnabled()) {
1279 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1280 child_process_logging::GetClientId());
1281 }
1282#endif // OS_MACOSX
1283
[email protected]f1933792011-06-14 00:49:341284 if (logging::DialogsAreSuppressed())
1285 command_line->AppendSwitch(switches::kNoErrorDialogs);
1286
[email protected]b80f68432011-05-02 17:22:301287 std::string process_type =
1288 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171289 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321290
1291 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1292 command_line->AppendSwitch(switches::kChromeFrame);
1293
[email protected]718eab62011-10-05 21:16:521294 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451295 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301296 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1297 if (!user_data_dir.empty())
1298 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1299#if defined(OS_CHROMEOS)
1300 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441301 browser_command_line.GetSwitchValueASCII(
1302 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301303 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441304 command_line->AppendSwitchASCII(
1305 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301306#endif
1307
[email protected]f3b1a082011-11-18 00:34:301308 content::RenderProcessHost* process =
1309 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371310 if (process) {
1311 Profile* profile = Profile::FromBrowserContext(
1312 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131313 ExtensionService* extension_service =
1314 extensions::ExtensionSystem::Get(profile)->extension_service();
1315 if (extension_service) {
1316 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001317 if (process_map && process_map->Contains(process->GetID()))
1318 command_line->AppendSwitch(switches::kExtensionProcess);
1319 }
[email protected]b80f68432011-05-02 17:22:301320
[email protected]a8d851f82011-12-21 00:32:371321 PrefService* prefs = profile->GetPrefs();
1322 // Currently this pref is only registered if applied via a policy.
1323 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1324 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1325 // Turn this policy into a command line switch.
1326 command_line->AppendSwitch(switches::kDisable3DAPIs);
1327 }
[email protected]718eab62011-10-05 21:16:521328
[email protected]a8d851f82011-12-21 00:32:371329 // Disable client-side phishing detection in the renderer if it is
1330 // disabled in the Profile preferences or the browser process.
1331 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1332 !g_browser_process->safe_browsing_detection_service()) {
1333 command_line->AppendSwitch(
1334 switches::kDisableClientSidePhishingDetection);
1335 }
[email protected]0045b0f42012-07-26 11:52:081336
1337 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211338 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521339
1340 InstantService* instant_service =
1341 InstantServiceFactory::GetForProfile(profile);
1342 if (instant_service &&
1343 instant_service->IsInstantProcess(process->GetID()))
1344 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301345
[email protected]d5bcd06f2013-04-21 08:07:241346#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301347 SigninManager* signin_manager =
1348 SigninManagerFactory::GetForProfile(profile);
1349 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1350 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241351#endif
[email protected]47c7ec82012-01-18 03:29:211352 }
[email protected]4287a3d2011-06-13 23:56:511353
[email protected]87552982012-11-02 17:21:401354 if (content::IsThreadedCompositingEnabled())
1355 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1356
[email protected]16dc42452013-04-09 04:37:191357 if (message_center::IsRichNotificationEnabled())
1358 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191359
[email protected]47c7ec82012-01-18 03:29:211360 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511361 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171362 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481363 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171364 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511365 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481366 switches::kAllowLegacyExtensionManifests,
[email protected]9d450492013-06-13 23:08:371367 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1368 // to browser.
1369 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511370 switches::kAllowScriptingGallery,
1371 switches::kAppsCheckoutURL,
1372 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311373 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511374 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501375 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531376 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111377 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531378 switches::kEnableAdview,
1379 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441380 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211381 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511382 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511383 switches::kEnableIPCFuzzing,
1384 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451385 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481386 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051387 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511388 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291389 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511390 switches::kMemoryProfiling,
1391 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371392 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371393 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511394 switches::kPpapiFlashArgs,
1395 switches::kPpapiFlashInProcess,
1396 switches::kPpapiFlashPath,
1397 switches::kPpapiFlashVersion,
1398 switches::kProfilingAtStart,
1399 switches::kProfilingFile,
1400 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371401 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511402 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291403 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381404 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511405 };
1406
1407 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1408 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171409 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381410 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351411 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381412 switches::kEnableExperimentalExtensionApis,
1413 switches::kWhitelistedExtensionID,
1414 };
1415
1416 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1417 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511418 } else if (process_type == switches::kPluginProcess) {
1419 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441420#if defined(OS_CHROMEOS)
1421 chromeos::switches::kLoginProfile,
1422#endif
[email protected]4287a3d2011-06-13 23:56:511423 switches::kMemoryProfiling,
1424 switches::kSilentDumpOnDCHECK,
1425 switches::kUserDataDir,
1426 };
1427
1428 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1429 arraysize(kSwitchNames));
1430 } else if (process_type == switches::kZygoteProcess) {
1431 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511432 switches::kUserDataDir, // Make logs go to the right file.
1433 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501434 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511435 switches::kPpapiFlashInProcess,
1436 switches::kPpapiFlashPath,
1437 switches::kPpapiFlashVersion,
1438 };
1439
1440 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1441 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111442 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001443 base::FilePath user_data_dir =
1444 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1445 if (!user_data_dir.empty())
1446 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111447 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1448 // because GPU is expected to be unreliable.
1449 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1450 !command_line->HasSwitch(switches::kDisableBreakpad))
1451 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301452 }
[email protected]6f08af82011-09-15 01:19:031453
1454 // The command line switch kEnableBenchmarking needs to be specified along
1455 // with the kEnableStatsTable switch to ensure that the stats table global
1456 // is initialized correctly.
1457 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1458 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301459}
1460
1461std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431462 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351463 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301464 return g_browser_process->GetApplicationLocale();
1465}
1466
[email protected]597a867b2011-11-18 18:31:201467std::string ChromeContentBrowserClient::GetAcceptLangs(
1468 content::BrowserContext* context) {
1469 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371470 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081471}
1472
[email protected]9ec0f452012-05-31 15:58:531473gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221474 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531475 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081476}
1477
[email protected]a2176792011-05-08 19:30:491478bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091479 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191480 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201481 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201483 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051484 return io_data->GetCookieSettings()->
1485 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491486}
1487
[email protected]ed24fad2011-05-10 22:44:011488bool ChromeContentBrowserClient::AllowGetCookie(
1489 const GURL& url,
1490 const GURL& first_party,
1491 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201492 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011493 int render_process_id,
1494 int render_view_id) {
1495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201496 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051497 bool allow = io_data->GetCookieSettings()->
1498 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011499
[email protected]8093a542011-05-13 07:29:321500 BrowserThread::PostTask(
1501 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031502 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431503 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011504 return allow;
1505}
1506
1507bool ChromeContentBrowserClient::AllowSetCookie(
1508 const GURL& url,
1509 const GURL& first_party,
1510 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201511 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011512 int render_process_id,
1513 int render_view_id,
1514 net::CookieOptions* options) {
1515 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201516 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051517 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1518 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1519
[email protected]8093a542011-05-13 07:29:321520 BrowserThread::PostTask(
1521 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031522 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431523 render_view_id, url, first_party, cookie_line, *options,
1524 !allow));
[email protected]ed24fad2011-05-10 22:44:011525 return allow;
1526}
1527
[email protected]d5a19162011-06-30 18:51:541528bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201529 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541530 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201531 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431532 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1533 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261534
[email protected]bf510ed2012-06-05 08:31:431535 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1536 // Could we even support per-origin settings?
1537 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541538}
1539
[email protected]5c5a88e2011-11-12 00:45:351540bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351541 const GURL& url,
1542 const string16& name,
1543 const string16& display_name,
1544 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201545 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481546 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351547 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201548 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351549 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1550 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1551
[email protected]62151052012-02-01 18:40:481552 // Record access to database for potential display in UI.
1553 std::vector<std::pair<int, int> >::const_iterator i;
1554 for (i = render_views.begin(); i != render_views.end(); ++i) {
1555 BrowserThread::PostTask(
1556 BrowserThread::UI, FROM_HERE,
1557 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1558 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351559 }
1560
1561 return allow;
1562}
1563
1564bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351565 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201566 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481567 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351568 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201569 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351570 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1571 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1572
[email protected]62151052012-02-01 18:40:481573 // Record access to file system for potential display in UI.
1574 std::vector<std::pair<int, int> >::const_iterator i;
1575 for (i = render_views.begin(); i != render_views.end(); ++i) {
1576 BrowserThread::PostTask(
1577 BrowserThread::UI, FROM_HERE,
1578 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1579 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351580 }
1581
1582 return allow;
1583}
1584
[email protected]7c5ff9a2012-03-02 07:42:491585bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1586 const GURL& url,
1587 const string16& name,
1588 content::ResourceContext* context,
1589 const std::vector<std::pair<int, int> >& render_views) {
1590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1591 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1592 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1593 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1594
1595 // Record access to IndexedDB for potential display in UI.
1596 std::vector<std::pair<int, int> >::const_iterator i;
1597 for (i = render_views.begin(); i != render_views.end(); ++i) {
1598 BrowserThread::PostTask(
1599 BrowserThread::UI, FROM_HERE,
1600 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1601 i->first, i->second, url, name, !allow));
1602 }
1603
1604 return allow;
1605}
1606
[email protected]6133f922011-07-01 21:34:341607net::URLRequestContext*
1608ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201609 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421611 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201612 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341613 return io_data->extensions_request_context();
1614 }
1615
1616 return NULL;
1617}
1618
[email protected]317f96c92011-05-31 06:53:411619QuotaPermissionContext*
1620ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1621 return new ChromeQuotaPermissionContext();
1622}
1623
[email protected]848dd042011-06-04 18:24:031624void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171625 int render_process_id,
1626 int render_view_id,
1627 int cert_error,
1628 const net::SSLInfo& ssl_info,
1629 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021630 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031631 bool overridable,
[email protected]d9be47702012-05-16 03:41:221632 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171633 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001634 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021635 if (resource_type != ResourceType::MAIN_FRAME) {
1636 // A sub-resource has a certificate error. The user doesn't really
1637 // have a context for making the right decision, so block the
1638 // request hard, without an info bar to allow showing the insecure
1639 // content.
[email protected]8c965c22013-05-23 19:28:001640 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021641 return;
1642 }
1643
[email protected]f9034cf2011-07-21 12:43:411644 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131645 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171646 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411647 if (!tab) {
1648 NOTREACHED();
1649 return;
1650 }
1651 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501652 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301653 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011654 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1655 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411656 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171657 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411658 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001659 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411660 return;
1661 }
1662 }
1663
[email protected]1e87df32012-09-12 04:53:191664#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231665 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1666 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1667 if (captive_portal_tab_helper)
1668 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191669#endif
1670
[email protected]f9034cf2011-07-21 12:43:411671 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221672 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1673 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031674}
1675
[email protected]c99c442e2011-08-24 11:37:301676void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451677 int render_process_id,
1678 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401679 const net::HttpNetworkSession* network_session,
1680 net::SSLCertRequestInfo* cert_request_info,
1681 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131682 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451683 render_process_id, render_view_id);
1684 if (!tab) {
1685 NOTREACHED();
1686 return;
1687 }
1688
[email protected]6786bf402011-12-03 15:19:451689 GURL requesting_url("https://" + cert_request_info->host_and_port);
1690 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1691 << cert_request_info->host_and_port;
1692
[email protected]627e0512011-12-21 22:55:301693 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451694 scoped_ptr<Value> filter(
1695 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1696 requesting_url,
1697 requesting_url,
1698 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1699 std::string(), NULL));
1700
1701 if (filter.get()) {
1702 // Try to automatically select a client certificate.
1703 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1704 DictionaryValue* filter_dict =
1705 static_cast<DictionaryValue*>(filter.get());
1706
1707 const std::vector<scoped_refptr<net::X509Certificate> >&
1708 all_client_certs = cert_request_info->client_certs;
1709 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091710 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451711 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091712 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451713 return;
1714 }
1715 }
1716 } else {
1717 NOTREACHED();
1718 }
1719 }
1720
[email protected]11feec322012-09-18 03:58:521721 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1722 if (!ssl_tab_helper) {
1723 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451724 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141725 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401726 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451727 return;
1728 }
[email protected]11feec322012-09-18 03:58:521729 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401730 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451731}
1732
[email protected]3b455502012-12-11 18:22:581733void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451734 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581735 net::CertificateMimeType cert_type,
1736 const void* cert_data,
1737 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451738 int render_process_id,
1739 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581740 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1741 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451742}
1743
[email protected]dc73a7b2012-03-25 15:27:181744content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561745 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181746}
1747
[email protected]941623e2011-06-07 23:06:041748void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1749 const GURL& source_origin,
1750 int callback_context,
1751 int render_process_id,
1752 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111753#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1755 WebContents* contents =
1756 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1757 if (!contents) {
[email protected]941623e2011-06-07 23:06:041758 NOTREACHED();
1759 return;
1760 }
1761
[email protected]d0d9c3ee2012-06-19 03:07:021762 // Skip showing the infobar if the request comes from an extension, and that
1763 // extension has the 'notify' permission. (If the extension does not have the
1764 // permission, the user will still be prompted.)
1765 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011766 ExtensionInfoMap* extension_info_map =
1767 extensions::ExtensionSystem::Get(profile)->info_map();
1768 DesktopNotificationService* notification_service =
1769 DesktopNotificationServiceFactory::GetForProfile(profile);
1770 const Extension* extension = NULL;
1771 if (extension_info_map) {
1772 ExtensionSet extensions;
1773 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1774 source_origin, render_process_id,
1775 extensions::APIPermission::kNotification, &extensions);
1776 for (ExtensionSet::const_iterator iter = extensions.begin();
1777 iter != extensions.end(); ++iter) {
1778 if (notification_service->IsExtensionEnabled((*iter)->id())) {
[email protected]cadac622013-06-11 16:46:361779 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011780 break;
1781 }
1782 }
1783 }
[email protected]eb4832a2012-12-08 01:57:521784 RenderViewHost* rvh =
1785 RenderViewHost::FromID(render_process_id, render_view_id);
1786 if (IsExtensionWithPermissionOrSuggestInConsole(
1787 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021788 if (rvh)
1789 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1790 return;
1791 }
1792
[email protected]c7cd5942013-04-30 03:31:011793 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021794 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111795#else
1796 NOTIMPLEMENTED();
1797#endif
[email protected]941623e2011-06-07 23:06:041798}
1799
1800WebKit::WebNotificationPresenter::Permission
1801 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021802 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201803 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021804 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111805#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201807 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041808
[email protected]c7cd5942013-04-30 03:31:011809 DesktopNotificationService* notification_service =
1810 io_data->GetNotificationService();
1811 if (notification_service) {
1812 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1813 ExtensionSet extensions;
1814 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1815 source_origin, render_process_id,
1816 extensions::APIPermission::kNotification, &extensions);
1817 for (ExtensionSet::const_iterator iter = extensions.begin();
1818 iter != extensions.end(); ++iter) {
1819 if (notification_service->IsExtensionEnabled((*iter)->id()))
1820 return WebKit::WebNotificationPresenter::PermissionAllowed;
1821 }
1822
1823 return notification_service->HasPermission(source_origin);
1824 }
1825
1826 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111827#else
1828 return WebKit::WebNotificationPresenter::PermissionAllowed;
1829#endif
[email protected]941623e2011-06-07 23:06:041830}
1831
1832void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171833 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041834 int render_process_id,
1835 int render_view_id,
1836 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111837#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041838 RenderViewHost* rvh = RenderViewHost::FromID(
1839 render_process_id, render_view_id);
1840 if (!rvh) {
1841 NOTREACHED();
1842 return;
1843 }
1844
[email protected]9f76c1e2012-03-05 15:15:581845 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301846 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041847 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371848 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041849 service->ShowDesktopNotification(
1850 params, render_process_id, render_view_id,
1851 worker ? DesktopNotificationService::WorkerNotification :
1852 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111853#else
1854 NOTIMPLEMENTED();
1855#endif
[email protected]941623e2011-06-07 23:06:041856}
1857
1858void ChromeContentBrowserClient::CancelDesktopNotification(
1859 int render_process_id,
1860 int render_view_id,
1861 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111862#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041863 RenderViewHost* rvh = RenderViewHost::FromID(
1864 render_process_id, render_view_id);
1865 if (!rvh) {
1866 NOTREACHED();
1867 return;
1868 }
1869
[email protected]9f76c1e2012-03-05 15:15:581870 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301871 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041872 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371873 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041874 service->CancelDesktopNotification(
1875 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111876#else
1877 NOTIMPLEMENTED();
1878#endif
[email protected]941623e2011-06-07 23:06:041879}
1880
[email protected]9f3fba52011-06-08 20:37:191881bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351882 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021883 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191884 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201885 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011886 int render_process_id,
1887 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191888 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011889
1890 *no_javascript_access = false;
1891
[email protected]9f3fba52011-06-08 20:37:191892 // If the opener is trying to create a background window but doesn't have
1893 // the appropriate permission, fail the attempt.
1894 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201895 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531896 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1897
[email protected]03b6d552012-03-29 04:03:011898 if (!map->SecurityOriginHasAPIPermission(
1899 source_origin,
1900 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061901 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011902 return false;
1903 }
1904
[email protected]7b54ca02012-03-02 18:06:531905 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1906 // return a recently installed Extension even if this CanCreateWindow call
1907 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011908 // because the permission check above would have caused an early return
1909 // already. We must use the full URL to find hosted apps, though, and not
1910 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531911 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351912 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291913 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011914 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191915 }
[email protected]056efdc2013-04-06 00:14:531916
1917 // No new browser window (popup or tab) in app mode.
1918 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1919 chrome::IsRunningInForcedAppMode()) {
1920 return false;
1921 }
1922
[email protected]9f3fba52011-06-08 20:37:191923 return true;
1924}
1925
1926std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201927 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191928 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1929 // Check if it's an extension-created worker, in which case we want to use
1930 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201931 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191932 const Extension* extension =
1933 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1934 return extension ? extension->name() : std::string();
1935}
1936
[email protected]99907362012-01-11 05:41:401937void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1938 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171939}
1940
[email protected]7a06d282013-05-03 04:39:331941// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021942content::SpeechRecognitionManagerDelegate*
1943 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:001944#if defined(ENABLE_INPUT_SPEECH)
1945 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:321946#else
[email protected]855e18b2013-07-08 21:02:001947 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
1948 // need the base delegate without the bubble UI.
1949 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321950#endif
[email protected]66cfec62012-02-24 17:57:511951}
1952
[email protected]ae6e9912011-07-27 01:18:281953net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1954 return g_browser_process->net_log();
1955}
1956
[email protected]32538d92011-08-25 00:09:231957AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1958 return new ChromeAccessTokenStore();
1959}
1960
[email protected]dbae6b02011-06-29 23:51:411961bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011962 return true;
[email protected]dbae6b02011-06-29 23:51:411963}
1964
[email protected]64d69de42012-02-06 00:19:541965void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321966 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061967 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581968 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061969 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061970
[email protected]f3986f82012-01-03 20:00:061971 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541972 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061973 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541974 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061975 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541976 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061977 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541978 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061979 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541980 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061981 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541982 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031983 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1984 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061985
[email protected]64d69de42012-02-06 00:19:541986 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401987 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541988 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401989 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541990 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401991 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541992 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401993 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061994
[email protected]ddf72142012-05-22 04:52:401995 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061996
[email protected]64d69de42012-02-06 00:19:541997 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401998 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541999 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062000 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542001 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062002 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2003 const DictionaryValue* inspector_settings =
2004 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2005 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182006 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2007 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062008 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182009 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542010 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182011 std::make_pair(iter.key(), value));
2012 }
[email protected]f3986f82012-01-03 20:00:062013 }
2014 }
[email protected]64d69de42012-02-06 00:19:542015 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062016
[email protected]ddf72142012-05-22 04:52:402017 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542018 web_prefs->javascript_enabled = false;
2019 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2020 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402021 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542022 web_prefs->plugins_enabled = false;
2023 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2024 web_prefs->java_enabled = false;
2025 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402026 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062027
[email protected]64d69de42012-02-06 00:19:542028 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2029 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062030
[email protected]64d69de42012-02-06 00:19:542031 web_prefs->memory_info_enabled =
2032 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2033 web_prefs->allow_displaying_insecure_content =
2034 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2035 web_prefs->allow_running_insecure_content =
2036 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322037#if defined(OS_ANDROID)
2038 web_prefs->font_scale_factor =
2039 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2040 web_prefs->force_enable_zoom =
2041 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:452042#if defined(GOOGLE_TV)
2043 web_prefs->user_gesture_required_for_media_playback = false;
2044#endif
[email protected]d3b935f2012-10-19 23:14:322045#endif
[email protected]5c915252013-05-07 13:15:392046
[email protected]af4256d52013-06-04 20:39:072047#if defined(OS_ANDROID)
2048 web_prefs->password_echo_enabled =
2049 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2050#else
[email protected]9d06d88d2012-02-23 22:37:082051 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072052#endif
2053
[email protected]5c915252013-05-07 13:15:392054#if defined(OS_CHROMEOS)
2055 // Enable password echo during OOBE when keyboard driven flag is set.
2056 if (chromeos::UserManager::IsInitialized() &&
2057 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
2058 !chromeos::StartupUtils::IsOobeCompleted()) {
2059 bool keyboard_driven_oobe = false;
2060 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]0071aed32013-06-19 13:39:552061 chromeos::system::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:392062 if (keyboard_driven_oobe)
2063 web_prefs->password_echo_enabled = true;
2064 }
2065#endif
[email protected]f3986f82012-01-03 20:00:062066
[email protected]46f8e742013-05-03 18:37:142067#if defined(OS_ANDROID)
2068 web_prefs->user_style_sheet_enabled = false;
2069#else
[email protected]64d69de42012-02-06 00:19:542070 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152071 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362072 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152073 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542074 web_prefs->user_style_sheet_enabled = true;
2075 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152076 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542077 } else {
2078 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062079 }
[email protected]46f8e742013-05-03 18:37:142080#endif
[email protected]f3986f82012-01-03 20:00:062081
[email protected]cfadadd2013-04-03 04:43:022082 web_prefs->asynchronous_spell_checking_enabled = true;
2083 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572084
[email protected]64d69de42012-02-06 00:19:542085 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062086 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542087 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062088 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542089 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062090 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2091
2092 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542093 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062094 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542095 web_prefs->default_encoding);
2096 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402097 prefs->ClearPref(prefs::kDefaultCharset);
2098 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062099 }
[email protected]64d69de42012-02-06 00:19:542100 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062101
[email protected]88ecf66d2012-12-11 22:53:472102 if (content::IsForceCompositingModeEnabled())
2103 web_prefs->force_compositing_mode = true;
2104
[email protected]299d7f12012-05-23 05:31:152105 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232106 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132107 ExtensionService* service =
2108 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062109 if (service) {
[email protected]1bc28312012-11-08 08:31:532110 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2111 const Extension* extension = service->extensions()->GetByID(url.host());
2112 // Ensure that we are only granting extension preferences to URLs with
2113 // the correct scheme. Without this check, chrome-guest:// schemes used by
2114 // webview tags as well as hosts that happen to match the id of an
2115 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422116 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532117 extension_webkit_preferences::SetPreferences(
2118 extension, view_type, web_prefs);
2119 }
[email protected]f3986f82012-01-03 20:00:062120 }
2121
[email protected]cb2edf22013-04-01 20:25:232122 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542123 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232124 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062125 // Disable all kinds of acceleration for background pages.
2126 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542127 web_prefs->force_compositing_mode = false;
2128 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062129 }
[email protected]2e21fe292012-03-02 22:52:322130
2131#if defined(FILE_MANAGER_EXTENSION)
2132 // Override the default of suppressing HW compositing for WebUI pages for the
2133 // file manager, which is implemented using WebUI but wants HW acceleration
2134 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532135 if (url.SchemeIs(extensions::kExtensionScheme) &&
2136 url.host() == kFileBrowserDomain) {
[email protected]2e21fe292012-03-02 22:52:322137 web_prefs->accelerated_compositing_enabled = true;
2138 web_prefs->accelerated_2d_canvas_enabled = true;
2139 }
2140#endif
[email protected]181a95ee2011-07-12 19:26:362141}
2142
2143void ChromeContentBrowserClient::UpdateInspectorSetting(
2144 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062145 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582146 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062147 DictionaryPrefUpdate update(
2148 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2149 prefs::kWebKitInspectorSettings);
2150 DictionaryValue* inspector_settings = update.Get();
2151 inspector_settings->SetWithoutPathExpansion(key,
2152 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362153}
2154
[email protected]b8148ac2011-07-13 22:03:252155void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2156 BrowserURLHandler* handler) {
2157 // Add the default URL handlers.
2158 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2159 BrowserURLHandler::null_handler());
2160 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2161 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2162
[email protected]b3adbd02011-11-30 22:23:272163 // about: handler. Must come before chrome: handler, since it will
2164 // rewrite about: urls to chrome: URLs and then expect chrome: to
2165 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252166 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2167 BrowserURLHandler::null_handler());
2168 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242169 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252170}
2171
2172void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372173 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582174 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472175 BrowsingDataRemover* remover =
2176 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552177 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2178 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252179 // BrowsingDataRemover takes care of deleting itself when done.
2180}
2181
2182void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372183 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582184 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472185 BrowsingDataRemover* remover =
2186 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232187 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552188 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252189 // BrowsingDataRemover takes care of deleting itself when done.
2190}
2191
[email protected]650b2d52013-02-10 03:41:452192base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322193 return download_util::GetDefaultDownloadDirectory();
2194}
2195
[email protected]c9b6eb62011-10-18 20:49:392196std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2197 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2198}
2199
[email protected]b7631cc2012-09-15 05:08:382200void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2201 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542202#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382203 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2204 scoped_ptr<ppapi::host::HostFactory>(
2205 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542206#endif
[email protected]b7631cc2012-09-15 05:08:382207}
2208
[email protected]0c7193742012-11-07 19:05:032209content::BrowserPpapiHost*
2210 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2211 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132212 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032213 while (!iter.Done()) {
2214 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2215 if (host->process() &&
2216 host->process()->GetData().id == plugin_process_id) {
2217 // Found the plugin.
2218 return host->browser_ppapi_host();
2219 }
2220 ++iter;
2221 }
2222 return NULL;
2223}
2224
[email protected]7b38b192013-03-23 18:39:312225bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2226 content::BrowserContext* browser_context, const GURL& site_url) {
2227 if (CommandLine::ForCurrentProcess()->HasSwitch(
2228 switches::kEnableBrowserPluginForAllViewTypes))
2229 return true;
2230
2231 Profile* profile = Profile::FromBrowserContext(browser_context);
2232 ExtensionService* service =
2233 extensions::ExtensionSystem::Get(profile)->extension_service();
2234 if (!service)
2235 return false;
2236
2237 const Extension* extension = service->extensions()->
2238 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2239 if (!extension)
2240 return false;
2241
[email protected]c2d2f102013-04-29 16:42:582242 return extension->HasAPIPermission(APIPermission::kWebView) ||
2243 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312244}
2245
[email protected]38cd8f7f2012-06-15 22:06:072246bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582247 content::BrowserContext* browser_context,
2248 const GURL& url,
[email protected]dda54822013-06-15 01:26:392249 bool private_api,
[email protected]157cc902012-11-02 06:31:582250 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402251#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372252 Profile* profile = Profile::FromBrowserContext(browser_context);
2253 const ExtensionSet* extension_set = NULL;
2254 if (profile) {
2255 extension_set = extensions::ExtensionSystem::Get(profile)->
2256 extension_service()->extensions();
2257 }
[email protected]dda54822013-06-15 01:26:392258
2259 if (private_api) {
2260 // Access to private socket APIs is controlled by the whitelist.
2261 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2262 allowed_socket_origins_)) {
2263 return true;
2264 }
2265 } else {
2266 // Access to public socket APIs is controlled by extension permissions.
2267 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2268 extension_set) {
2269 const Extension* extension = extension_set->GetByID(url.host());
2270 if (extension) {
2271 extensions::SocketPermission::CheckParam check_params(
2272 params.type, params.host, params.port);
2273 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2274 extension, extensions::APIPermission::kSocket, &check_params)) {
2275 return true;
2276 }
2277 }
2278 }
2279 }
2280
2281 // Allow both public and private APIs if the command line says so.
2282 return IsHostAllowedByCommandLine(url, extension_set,
2283 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402284#else
[email protected]a658d452012-03-02 12:45:292285 return false;
[email protected]93f72062013-05-29 20:29:402286#endif
[email protected]e461da2f2012-02-16 19:06:402287}
2288
[email protected]650b2d52013-02-10 03:41:452289base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2290 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142291 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2292 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2293}
2294
[email protected]a28e3302013-02-03 03:50:432295ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2296 WebContents* web_contents) {
2297 return new ChromeSelectFilePolicy(web_contents);
2298}
2299
[email protected]7d9424702013-04-14 13:14:162300void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2301 std::vector<std::string>* additional_allowed_schemes) {
2302 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2303 additional_allowed_schemes);
2304 additional_allowed_schemes->push_back(kChromeUIScheme);
2305 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2306}
2307
[email protected]f19bbf62013-07-09 01:22:322308void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]02250952013-04-24 23:52:532309 const base::FilePath& storage_partition_path,
[email protected]b40015c2013-06-26 08:13:312310 quota::SpecialStoragePolicy* special_storage_policy,
2311 fileapi::ExternalMountPoints* external_mount_points,
[email protected]f19bbf62013-07-09 01:22:322312 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532313#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032314 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322315 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032316 storage_partition_path,
2317 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322318 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532319#endif
[email protected]b40015c2013-06-26 08:13:312320#if defined(OS_CHROMEOS)
2321 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322322 chromeos::FileSystemBackend* backend =
2323 new chromeos::FileSystemBackend(
2324 new drive::FileSystemBackendDelegate(external_mount_points),
[email protected]b40015c2013-06-26 08:13:312325 special_storage_policy,
2326 external_mount_points,
2327 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322328 backend->AddSystemMountPoints();
2329 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2330 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312331#endif
[email protected]02250952013-04-24 23:52:532332}
2333
[email protected]e60c0232011-11-11 19:56:352334#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182335void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2336 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382337 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082338 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392339#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452340 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392341 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2342 DCHECK(!data_path.empty());
2343
2344 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452345 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392346 base::PlatformFile f =
2347 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2348 DCHECK(f != base::kInvalidPlatformFileValue);
2349 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2350 FileDescriptor(f, true)));
2351
[email protected]650b2d52013-02-10 03:41:452352 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392353 data_path.AppendASCII("chrome_100_percent.pak");
2354 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2355 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372356 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392357 FileDescriptor(f, true)));
2358
2359 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452360 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392361 GetLocaleFilePath(locale, false);
2362 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2363 DCHECK(f != base::kInvalidPlatformFileValue);
2364 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2365 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382366
[email protected]650b2d52013-02-10 03:41:452367 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372368 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2369 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2370 DCHECK(f != base::kInvalidPlatformFileValue);
2371 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2372 FileDescriptor(f, true)));
2373
[email protected]40da3e0c2012-10-24 22:03:382374#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432375 if (IsCrashReporterEnabled()) {
2376 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2377 if (f == base::kInvalidPlatformFileValue) {
2378 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2379 "be disabled for this process.";
2380 } else {
2381 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2382 FileDescriptor(f, true)));
2383 }
[email protected]40da3e0c2012-10-24 22:03:382384 }
2385#endif // defined(USE_LINUX_BREAKPAD)
2386
2387#else
2388 int crash_signal_fd = GetCrashSignalFD(command_line);
2389 if (crash_signal_fd >= 0) {
2390 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2391 FileDescriptor(crash_signal_fd,
2392 false)));
2393 }
[email protected]29699c22012-10-03 23:57:392394#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302395}
[email protected]e60c0232011-11-11 19:56:352396#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302397
[email protected]4a65826d2011-08-25 16:04:012398#if defined(OS_WIN)
2399const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2400 return chrome::kBrowserResourcesDll;
2401}
[email protected]34f48682013-03-20 00:30:182402
2403void ChromeContentBrowserClient::PreSpawnRenderer(
2404 sandbox::TargetPolicy* policy,
2405 bool* success) {
2406 // This code is duplicated in nacl_exe_win_64.cc.
2407 // Allow the server side of a pipe restricted to the "chrome.nacl."
2408 // namespace so that it cannot impersonate other system or other chrome
2409 // service pipes.
2410 sandbox::ResultCode result = policy->AddRule(
2411 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2412 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2413 L"\\\\.\\pipe\\chrome.nacl.*");
2414 if (result != sandbox::SBOX_ALL_OK) {
2415 *success = false;
2416 return;
2417 }
2418
2419 // Renderers need to send named pipe handles and shared memory
2420 // segment handles to NaCl loader processes.
2421 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2422 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2423 L"File");
2424 if (result != sandbox::SBOX_ALL_OK) {
2425 *success = false;
2426 return;
2427 }
2428}
[email protected]4a65826d2011-08-25 16:04:012429#endif
2430
[email protected]37a72af2011-06-13 05:42:012431#if defined(USE_NSS)
2432crypto::CryptoModuleBlockingPasswordDelegate*
2433 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2434 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292435 return chrome::NewCryptoModuleBlockingDialogDelegate(
2436 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012437}
2438#endif
2439
[email protected]d977f9c2011-03-14 16:10:262440} // namespace chrome