blob: 47135629df8cdc7033281443dd5205d9050c2c59 [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]5c129792013-07-10 02:08:4823#include "chrome/browser/browser_shutdown.h"
[email protected]b0cb5e82012-07-19 19:22:4724#include "chrome/browser/browsing_data/browsing_data_helper.h"
25#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1226#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4127#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4128#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5629#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0530#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4531#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3232#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0833#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4934#include "chrome/browser/download/download_prefs.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]190e5e22013-07-27 05:59:2360#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4161#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5062#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0763#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4164#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1465#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0366#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1467#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3268#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0669#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1470#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3871#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4372#include "chrome/browser/search/instant_service.h"
73#include "chrome/browser/search/instant_service_factory.h"
74#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1475#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0276#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3377#include "chrome/browser/speech/tts_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]180c66a62013-08-05 12:01:3681#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:4582#include "chrome/browser/tab_contents/tab_util.h"
[email protected]916615b2013-09-11 18:19:4483#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
[email protected]40aa8bb2013-08-23 20:28:2384#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
[email protected]a28e3302013-02-03 03:50:4385#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2586#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4487#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5088#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0689#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1590#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2791#include "chrome/browser/validation_message_message_filter.h"
[email protected]4a65826d2011-08-25 16:04:0192#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1493#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3094#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2995#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0496#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3897#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4498#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4399#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:29100#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]dda54822013-06-15 01:26:39101#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]157cc902012-11-02 06:31:58102#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]9a60d1602013-09-11 04:09:12103#include "chrome/common/extensions/web_accessible_resources_handler.h"
[email protected]f1933792011-06-14 00:49:34104#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37105#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12106#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38107#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09108#include "chrome/common/url_constants.h"
[email protected]264c0acac2013-10-01 13:33:30109#include "chrome/installer/util/google_update_settings.h"
[email protected]e8f3f9982013-05-10 20:59:53110#include "chromeos/chromeos_constants.h"
[email protected]d5d383252013-07-04 14:44:32111#include "components/nacl/common/nacl_process_type.h"
[email protected]499e7c52013-10-04 16:03:09112#include "components/translate/common/translate_switches.h"
[email protected]75fee372013-03-06 00:42:44113#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43114#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30115#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38116#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03117#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31118#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03119#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59120#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:30121#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33122#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05123#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33124#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19125#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10126#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43127#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18128#include "content/public/common/content_descriptors.h"
[email protected]22aa4f82013-09-24 17:01:44129#include "content/public/common/url_utils.h"
[email protected]cb2edf22013-04-01 20:25:23130#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42131#include "extensions/common/constants.h"
[email protected]49d9b142013-07-19 08:50:27132#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39133#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23134#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53135#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58136#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34137#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06138#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57139#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38140#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39141#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08142#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24143#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31144#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18145#include "webkit/common/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:26146
[email protected]b48c9182011-10-26 18:03:30147#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38148#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18149#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38150#elif defined(OS_MACOSX)
151#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56152#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30153#elif defined(OS_CHROMEOS)
154#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]f19bbf62013-07-09 01:22:32155#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h"
156#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39157#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49158#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10159#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44160#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26161#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30162#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09163#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38164#include "chrome/browser/android/crash_dump_manager.h"
[email protected]916615b2013-09-11 18:19:44165#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
[email protected]81054f812012-08-30 00:47:09166#include "chrome/browser/chrome_browser_main_android.h"
[email protected]2b12c322013-09-19 06:53:56167#include "chrome/browser/media/encrypted_media_message_filter_android.h"
[email protected]29699c22012-10-03 23:57:39168#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30169#elif defined(OS_POSIX)
170#include "chrome/browser/chrome_browser_main_posix.h"
171#endif
172
[email protected]a220b5932013-09-21 03:47:44173#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:30174#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12175#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43176#endif
[email protected]b80f68432011-05-02 17:22:30177
[email protected]1e87df32012-09-12 04:53:19178#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
179#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
180#endif
181
[email protected]29699c22012-10-03 23:57:39182#if defined(OS_ANDROID)
183#include "ui/base/ui_base_paths.h"
184#endif
185
[email protected]37a72af2011-06-13 05:42:01186#if defined(USE_NSS)
187#include "chrome/browser/ui/crypto_module_password_dialog.h"
188#endif
189
[email protected]d5bcd06f2013-04-21 08:07:24190#if !defined(OS_CHROMEOS)
191#include "chrome/browser/signin/signin_manager.h"
192#include "chrome/browser/signin/signin_manager_factory.h"
193#endif
194
[email protected]02250952013-04-24 23:52:53195#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32196#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53197#endif
198
[email protected]6ef98b5a2013-05-31 23:58:31199#if defined(ENABLE_WEBRTC)
200#include "chrome/browser/media/webrtc_logging_handler_host.h"
201#endif
202
[email protected]855e18b2013-07-08 21:02:00203#if defined(ENABLE_INPUT_SPEECH)
204#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
205#endif
206
[email protected]02a3dc122013-06-13 15:07:53207#if defined(FILE_MANAGER_EXTENSION)
[email protected]473c9a4f2013-09-05 03:09:46208#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]02a3dc122013-06-13 15:07:53209#endif
210
[email protected]e8b6ca02013-07-10 18:00:51211#if defined(TOOLKIT_GTK)
212#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
213#endif
214
215#if defined(TOOLKIT_VIEWS)
216#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
217#endif
218
219#if defined(USE_ASH)
220#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
221#endif
222
223#if defined(USE_AURA)
224#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
225#endif
226
227#if defined(USE_X11)
228#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
229#endif
230
[email protected]c6ce08072013-07-31 07:48:53231#if defined(ENABLE_SPELLCHECK)
232#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
233#endif
234
[email protected]190e5e22013-07-27 05:59:23235using WebKit::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08236using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47237using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03238using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39239using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31240using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59241using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08242using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00243using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11244using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33245using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13246using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06247using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34248using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40249using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38250using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39251
[email protected]c5dbef02011-05-13 05:06:09252namespace {
253
[email protected]eabbfb12013-04-05 23:28:35254// Cached version of the locale so we can return the locale on the I/O
255// thread.
256base::LazyInstance<std::string> g_io_thread_application_locale;
257
[email protected]93f72062013-05-29 20:29:40258#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40259const char* kPredefinedAllowedSocketOrigins[] = {
260 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18261 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45262 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
263 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
264 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
265 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35266 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54267 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
268 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
269 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
270 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
271 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
272 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38273 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58274 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29275 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42276 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
277 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
278 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
279 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
280 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
281 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40282};
[email protected]93f72062013-05-29 20:29:40283#endif
[email protected]e461da2f2012-02-16 19:06:40284
[email protected]f8f93eb2012-09-25 03:06:24285// Returns a copy of the given url with its host set to given host and path set
286// to given path. Other parts of the url will be the same.
287GURL ReplaceURLHostAndPath(const GURL& url,
288 const std::string& host,
289 const std::string& path) {
290 url_canon::Replacements<char> replacements;
291 replacements.SetHost(host.c_str(),
292 url_parse::Component(0, host.length()));
293 replacements.SetPath(path.c_str(),
294 url_parse::Component(0, path.length()));
295 return url.ReplaceComponents(replacements);
296}
297
298// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
299GURL AddUberHost(const GURL& url) {
300 const std::string uber_host = chrome::kChromeUIUberHost;
301 const std::string new_path = url.host() + url.path();
302
303 return ReplaceURLHostAndPath(url, uber_host, new_path);
304}
305
[email protected]045bf7c2012-09-28 20:27:36306// If url->host() is "chrome" and url->path() has characters other than the
307// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
308// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24309bool RemoveUberHost(GURL* url) {
310 if (url->host() != chrome::kChromeUIUberHost)
311 return false;
312
[email protected]045bf7c2012-09-28 20:27:36313 if (url->path().empty() || url->path() == "/")
314 return false;
315
[email protected]f8f93eb2012-09-25 03:06:24316 const std::string old_path = url->path();
317
318 const std::string::size_type separator = old_path.find('/', 1);
319 std::string new_host;
320 std::string new_path;
321 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36322 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24323 } else {
324 new_host = old_path.substr(1, separator - 1);
325 new_path = old_path.substr(separator);
326 }
327
[email protected]44e8add2013-06-13 17:29:15328 // Do not allow URLs with paths empty before the first slash since we can't
329 // have an empty host. (e.g "foo://chrome//")
330 if (new_host.empty())
331 return false;
332
[email protected]f8f93eb2012-09-25 03:06:24333 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
334
[email protected]44e8add2013-06-13 17:29:15335 DCHECK(url->is_valid());
336
[email protected]f8f93eb2012-09-25 03:06:24337 return true;
338}
339
[email protected]b8148ac2011-07-13 22:03:25340// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42341bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24342 // Do not handle special URLs such as "about:foo"
343 if (!url->host().empty()) {
344 const GURL chrome_url = AddUberHost(*url);
345
346 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
347 // be called.
348 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
349 browser_context, chrome_url))
350 return true;
351 }
352
[email protected]863f70a2012-01-27 02:05:50353 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
354 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25355 return false;
356
[email protected]fe69558d2012-03-12 11:34:49357#if defined(OS_CHROMEOS)
358 // Special case : in ChromeOS in Guest mode bookmarks and history are
359 // disabled for security reasons. New tab page explains the reasons, so
360 // we redirect user to new tab page.
361 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
362 if (url->SchemeIs(chrome::kChromeUIScheme) &&
363 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
[email protected]b9171622013-10-01 22:05:23364#if defined(ENABLE_ENHANCED_BOOKMARKS)
365 url->DomainIs(chrome::kChromeUIEnhancedBookmarksHost) ||
366#endif
[email protected]fe69558d2012-03-12 11:34:49367 url->DomainIs(chrome::kChromeUIHistoryHost))) {
368 // Rewrite with new tab URL
369 *url = GURL(chrome::kChromeUINewTabURL);
370 }
371 }
372#endif
373
[email protected]b8148ac2011-07-13 22:03:25374 // Special case the new tab page. In older versions of Chrome, the new tab
375 // page was hosted at chrome-internal:<blah>. This might be in people's saved
376 // sessions or bookmarks, so we say any URL with that scheme triggers the new
377 // tab page.
378 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
379 // Rewrite it with the proper new tab URL.
380 *url = GURL(chrome::kChromeUINewTabURL);
381 }
382
383 return true;
384}
385
[email protected]f8f93eb2012-09-25 03:06:24386// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
387// "chrome://foo/".
388bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
389 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
390 return false;
391
392 return RemoveUberHost(url);
393}
394
[email protected]8d3132f62011-10-12 07:13:42395// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
396// below. Extension, and isolated apps require different privileges to be
397// granted to their RenderProcessHosts. This classification allows us to make
398// sure URLs are served by hosts with the right set of privileges.
399enum RenderProcessHostPrivilege {
400 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45401 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42402 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45403 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42404};
405
406RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
407 const GURL& url,
408 ExtensionService* service) {
409 // Default to a normal renderer cause it is lower privileged. This should only
410 // occur if the URL on a site instance is either malformed, or uninitialized.
411 // If it is malformed, then there is no need for better privileges anyways.
412 // If it is uninitialized, but eventually settles on being an a scheme other
413 // than normal webrenderer, the navigation logic will correct us out of band
414 // anyways.
415 if (!url.is_valid())
416 return PRIV_NORMAL;
417
[email protected]885c0e92012-11-13 20:27:42418 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44419 const Extension* extension =
420 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43421 if (extension &&
422 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42423 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45424 if (extension && extension->is_hosted_app())
425 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42426
427 return PRIV_EXTENSION;
428 }
429
430 return PRIV_NORMAL;
431}
432
433RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30434 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46435 extensions::ProcessMap* process_map,
436 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46437 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30438 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46439 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21440 return PRIV_NORMAL;
441
[email protected]6f371442011-11-09 06:45:46442 for (std::set<std::string>::iterator iter = extension_ids.begin();
443 iter != extension_ids.end(); ++iter) {
444 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43445 if (extension &&
446 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42447 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45448 if (extension && extension->is_hosted_app())
449 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42450 }
451
[email protected]676f6ab2011-10-19 20:23:21452 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42453}
454
[email protected]6786bf402011-12-03 15:19:45455bool CertMatchesFilter(const net::X509Certificate& cert,
456 const base::DictionaryValue& filter) {
457 // TODO(markusheintz): This is the minimal required filter implementation.
458 // Implement a better matcher.
459
460 // An empty filter matches any client certificate since no requirements are
461 // specified at all.
462 if (filter.empty())
463 return true;
464
465 std::string common_name;
466 if (filter.GetString("ISSUER.CN", &common_name) &&
467 (cert.issuer().common_name == common_name)) {
468 return true;
469 }
470 return false;
471}
472
[email protected]f3986f82012-01-03 20:00:06473// Fills |map| with the per-script font prefs under path |map_name|.
474void FillFontFamilyMap(const PrefService* prefs,
475 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53476 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06477 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
478 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
479 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
480 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23481 if (!font_family.empty())
482 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06483 }
484}
485
[email protected]a1733df2012-06-22 11:24:18486#if defined(OS_POSIX) && !defined(OS_MACOSX)
487int GetCrashSignalFD(const CommandLine& command_line) {
488 if (command_line.HasSwitch(switches::kExtensionProcess)) {
489 ExtensionCrashHandlerHostLinux* crash_handler =
490 ExtensionCrashHandlerHostLinux::GetInstance();
491 return crash_handler->GetDeathSignalSocket();
492 }
493
494 std::string process_type =
495 command_line.GetSwitchValueASCII(switches::kProcessType);
496
497 if (process_type == switches::kRendererProcess)
498 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
499
500 if (process_type == switches::kPluginProcess)
501 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
502
503 if (process_type == switches::kPpapiPluginProcess)
504 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
505
506 if (process_type == switches::kGpuProcess)
507 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
508
509 return -1;
510}
511#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
512
[email protected]d5bcd06f2013-04-21 08:07:24513#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30514GURL GetEffectiveURLForSignin(const GURL& url) {
515 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
516
517 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03518 // Copy the path because the argument to SetPathStr must outlive
519 // the Replacements object.
520 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30521 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03522 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30523 effective_url = effective_url.ReplaceComponents(replacements);
524 return effective_url;
525}
[email protected]d5bcd06f2013-04-21 08:07:24526#endif
[email protected]970c63e2013-03-07 00:25:30527
[email protected]eabbfb12013-04-05 23:28:35528void SetApplicationLocaleOnIOThread(const std::string& locale) {
529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
530 g_io_thread_application_locale.Get() = locale;
531}
532
[email protected]916615b2013-09-11 18:19:44533void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) {
534 WebContents* tab = tab_util::GetWebContentsByID(params.render_process_id(),
535 params.opener_id());
[email protected]190e5e22013-07-27 05:59:23536 if (!tab)
537 return;
538
[email protected]190e5e22013-07-27 05:59:23539 PopupBlockerTabHelper* popup_helper =
540 PopupBlockerTabHelper::FromWebContents(tab);
541 if (!popup_helper)
542 return;
[email protected]916615b2013-09-11 18:19:44543 popup_helper->AddBlockedPopup(params);
[email protected]190e5e22013-07-27 05:59:23544}
[email protected]190e5e22013-07-27 05:59:23545
[email protected]916615b2013-09-11 18:19:44546#if defined(OS_ANDROID)
547void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) {
548 WebContents* web_contents =
549 tab_util::GetWebContentsByID(params.render_process_id(),
550 params.opener_id());
551 if (!web_contents)
552 return;
553
554 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params);
555}
556#endif // defined(OS_ANDROID)
557
[email protected]9dbfff12011-07-01 19:37:07558} // namespace
[email protected]c5dbef02011-05-13 05:06:09559
[email protected]d977f9c2011-03-14 16:10:26560namespace chrome {
561
[email protected]e461da2f2012-02-16 19:06:40562ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40563#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40564 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
565 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40566#endif
[email protected]1deace22013-05-22 06:14:46567
568 permissions_policy_delegate_.reset(
569 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40570}
571
572ChromeContentBrowserClient::~ChromeContentBrowserClient() {
573}
574
[email protected]bca18382012-06-25 19:15:23575// static
[email protected]37ca3fe02013-07-05 15:32:44576void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34577 user_prefs::PrefRegistrySyncable* registry) {
578 registry->RegisterBooleanPref(
579 prefs::kDisable3DAPIs,
580 false,
581 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
582 registry->RegisterBooleanPref(
583 prefs::kEnableHyperlinkAuditing,
584 true,
585 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
586 registry->RegisterBooleanPref(
587 prefs::kEnableMemoryInfo,
588 false,
589 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23590}
591
[email protected]eabbfb12013-04-05 23:28:35592// static
593void ChromeContentBrowserClient::SetApplicationLocale(
594 const std::string& locale) {
595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
596
597 // This object is guaranteed to outlive all threads so we don't have to
598 // worry about the lack of refcounting and can just post as Unretained.
599 //
600 // The common case is that this function is called early in Chrome startup
601 // before any threads are created (it will also be called later if the user
602 // changes the pref). In this case, there will be no threads created and
603 // posting will fail. When there are no threads, we can just set the string
604 // without worrying about threadsafety.
605 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
606 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
607 g_io_thread_application_locale.Get() = locale;
608 }
609}
610
[email protected]50462bf02011-11-21 19:13:31611content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
612 const content::MainFunctionParams& parameters) {
613 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30614 // Construct the Main browser parts based on the OS type.
615#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31616 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04617#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31618 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30619#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22620 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26621#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31622 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14623#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09624 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30625#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31626 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04627#else
[email protected]b48c9182011-10-26 18:03:30628 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31629 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30630#endif
631
[email protected]7e75e4a2013-05-17 17:20:03632 chrome::AddProfilesExtraParts(main_parts);
633
[email protected]c7480942011-11-08 19:18:27634 // Construct additional browser parts. Stages are called in the order in
635 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22636#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51637 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04638#endif
[email protected]c7480942011-11-08 19:18:27639
640#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51641 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27642#endif
643
[email protected]dc04be7c2012-03-15 23:57:49644#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51645 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49646#endif
647
[email protected]e050ef142012-03-21 01:04:24648#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51649 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
650#endif
651
652#if defined(USE_X11)
653 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24654#endif
655
[email protected]95132f52013-04-12 02:19:04656 chrome::AddMetricsExtraParts(main_parts);
657
[email protected]50462bf02011-11-21 19:13:31658 return main_parts;
[email protected]f967b722011-09-07 00:58:04659}
660
[email protected]e94bbcb2012-09-07 05:33:57661std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19662 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57663 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53664 std::string partition_id;
665
666 // The partition ID for webview guest processes is the string value of its
667 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
[email protected]6eb1a11e2013-10-09 00:54:37668 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:53669 partition_id = site.spec();
670
[email protected]056efdc2013-04-06 00:14:53671 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53672 return partition_id;
673}
674
675bool ChromeContentBrowserClient::IsValidStoragePartitionId(
676 content::BrowserContext* browser_context,
677 const std::string& partition_id) {
678 // The default ID is empty and is always valid.
679 if (partition_id.empty())
680 return true;
681
682 return GURL(partition_id).is_valid();
683}
684
685void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
686 content::BrowserContext* browser_context,
687 const GURL& site,
[email protected]14acc642012-11-17 12:20:10688 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53689 std::string* partition_domain,
690 std::string* partition_name,
691 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10692 // Default to the browser-wide storage partition and override based on |site|
693 // below.
694 partition_domain->clear();
695 partition_name->clear();
696 *in_memory = false;
697
[email protected]1bc28312012-11-08 08:31:53698 // For the webview tag, we create special guest processes, which host the
699 // tag content separately from the main application that embeds the tag.
700 // A webview tag can specify both the partition name and whether the storage
701 // for that partition should be persisted. Each tag gets a SiteInstance with
702 // a specially formatted URL, based on the application it is hosted by and
703 // the partition requested by it. The format for that URL is:
704 // chrome-guest://partition_domain/persist?partition_name
[email protected]6eb1a11e2013-10-09 00:54:37705 if (site.SchemeIs(content::kGuestScheme)) {
[email protected]1bc28312012-11-08 08:31:53706 // Since guest URLs are only used for packaged apps, there must be an app
707 // id in the URL.
708 CHECK(site.has_host());
709 *partition_domain = site.host();
710 // Since persistence is optional, the path must either be empty or the
711 // literal string.
712 *in_memory = (site.path() != "/persist");
713 // The partition name is user supplied value, which we have encoded when the
714 // URL was created, so it needs to be decoded.
715 *partition_name = net::UnescapeURLComponent(site.query(),
716 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10717 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
718 // If |can_be_default| is false, the caller is stating that the |site|
719 // should be parsed as if it had isolated storage. In particular it is
720 // important to NOT check ExtensionService for the is_storage_isolated()
721 // attribute because this code path is run during Extension uninstall
722 // to do cleanup after the Extension has already been unloaded from the
723 // ExtensionService.
724 bool is_isolated = !can_be_default;
725 if (can_be_default) {
726 const Extension* extension = NULL;
727 Profile* profile = Profile::FromBrowserContext(browser_context);
728 ExtensionService* extension_service =
729 extensions::ExtensionSystem::Get(profile)->extension_service();
730 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55731 extension =
732 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43733 if (extension &&
734 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10735 is_isolated = true;
736 }
737 }
738 }
[email protected]1bc28312012-11-08 08:31:53739
[email protected]14acc642012-11-17 12:20:10740 if (is_isolated) {
741 CHECK(site.has_host());
742 // For extensions with isolated storage, the the host of the |site| is
743 // the |partition_domain|. The |in_memory| and |partition_name| are only
744 // used in guest schemes so they are cleared here.
745 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53746 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10747 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53748 }
[email protected]d1198fd2012-08-13 22:50:19749 }
750
[email protected]14acc642012-11-17 12:20:10751 // Assert that if |can_be_default| is false, the code above must have found a
752 // non-default partition. If this fails, the caller has a serious logic
753 // error about which StoragePartition they expect to be in and it is not
754 // safe to continue.
755 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44756}
757
[email protected]38b098f2012-03-14 21:11:57758content::WebContentsViewDelegate*
759 ChromeContentBrowserClient::GetWebContentsViewDelegate(
760 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27761 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32762}
763
[email protected]738f57a2013-06-29 21:06:54764void ChromeContentBrowserClient::GuestWebContentsCreated(
765 WebContents* guest_web_contents,
766 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22767 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54768 scoped_ptr<base::DictionaryValue> extra_params) {
769 if (opener_web_contents) {
770 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
771 if (!guest) {
772 NOTREACHED();
773 return;
774 }
775
[email protected]50c827d2013-09-13 21:36:09776 // Create a new GuestView of the same type as the opener.
777 *guest_delegate =
778 GuestView::Create(guest_web_contents, guest->GetViewType());
[email protected]738f57a2013-06-29 21:06:54779 return;
780 }
781
782 if (!extra_params) {
783 NOTREACHED();
784 return;
785 }
786 std::string api_type;
[email protected]90547d72013-08-06 05:57:27787 extra_params->GetString(guestview::kParameterApi, &api_type);
[email protected]738f57a2013-06-29 21:06:54788
[email protected]50c827d2013-09-13 21:36:09789 *guest_delegate =
790 GuestView::Create(guest_web_contents,
791 GuestView::GetViewTypeFromString(api_type));
[email protected]738f57a2013-06-29 21:06:54792}
793
[email protected]44295a12013-06-05 08:45:46794void ChromeContentBrowserClient::GuestWebContentsAttached(
795 WebContents* guest_web_contents,
796 WebContents* embedder_web_contents,
[email protected]22aa4f82013-09-24 17:01:44797 const GURL& embedder_frame_url,
[email protected]5715566a2013-06-25 00:04:53798 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06799 Profile* profile = Profile::FromBrowserContext(
800 embedder_web_contents->GetBrowserContext());
801 ExtensionService* service =
802 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54803 if (!service) {
804 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06805 return;
[email protected]738f57a2013-06-29 21:06:54806 }
[email protected]22aa4f82013-09-24 17:01:44807
[email protected]c4927882013-09-26 04:19:09808 // We usually require BrowserPlugins to be hosted by a storage isolated
809 // extension. We treat WebUI pages as a special case if they host the
810 // BrowserPlugin in a component extension iframe. In that case, we use the
[email protected]22aa4f82013-09-24 17:01:44811 // iframe's URL to determine the extension.
812 const GURL& embedder_site_url =
813 embedder_web_contents->GetSiteInstance()->GetSiteURL();
814 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
815 content::HasWebUIScheme(embedder_site_url) ?
816 embedder_frame_url : embedder_site_url);
[email protected]738f57a2013-06-29 21:06:54817 if (!extension) {
[email protected]efd6fb02013-08-05 04:44:06818 // It's ok to return here, since we could be running a browser plugin
819 // outside an extension, and don't need to attach a
820 // BrowserPluginGuestDelegate in that case;
821 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
[email protected]738f57a2013-06-29 21:06:54822 return;
[email protected]18699372013-06-25 20:42:55823 }
[email protected]738f57a2013-06-29 21:06:54824
825 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
826 if (!guest) {
827 NOTREACHED();
828 return;
829 }
[email protected]9934a5e2013-08-22 00:07:56830 guest->Attach(embedder_web_contents, extension->id(), extra_params);
[email protected]44703cc72013-01-24 04:56:06831}
832
[email protected]f3b1a082011-11-18 00:34:30833void ChromeContentBrowserClient::RenderProcessHostCreated(
834 content::RenderProcessHost* host) {
835 int id = host->GetID();
836 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41837 net::URLRequestContextGetter* context =
838 profile->GetRequestContextForRenderProcess(id);
839
[email protected]ba780c12013-10-01 17:07:06840 host->AddFilter(new ChromeRenderMessageFilter(id, profile, context));
[email protected]ebd71962012-12-20 02:56:55841#if defined(ENABLE_PLUGINS)
[email protected]ba780c12013-10-01 17:07:06842 host->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55843#endif
[email protected]658677f2012-06-09 06:04:02844#if defined(ENABLE_PRINTING)
[email protected]ba780c12013-10-01 17:07:06845 host->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03846#endif
[email protected]ba780c12013-10-01 17:07:06847 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53848#if defined(ENABLE_SPELLCHECK)
[email protected]ba780c12013-10-01 17:07:06849 host->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53850#endif
[email protected]7ceb99012011-12-21 08:05:56851#if defined(OS_MACOSX)
[email protected]ba780c12013-10-01 17:07:06852 host->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56853#endif
[email protected]ba780c12013-10-01 17:07:06854 host->AddFilter(new ChromeNetBenchmarkingMessageFilter(
[email protected]43535512013-02-20 20:41:41855 id, profile, context));
[email protected]ba780c12013-10-01 17:07:06856 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
857 host->AddFilter(new ValidationMessageMessageFilter(id));
858 host->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31859#if defined(ENABLE_WEBRTC)
[email protected]10e5c5e52013-10-03 18:44:06860 WebRtcLoggingHandlerHost* webrtc_logging_handler_host =
861 new WebRtcLoggingHandlerHost();
862 host->AddFilter(webrtc_logging_handler_host);
863 host->SetUserData(host, new base::UserDataAdapter<WebRtcLoggingHandlerHost>(
864 webrtc_logging_handler_host));
[email protected]6ef98b5a2013-05-31 23:58:31865#endif
[email protected]01e59752013-06-18 00:17:35866#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03867 ExtensionInfoMap* extension_info_map =
868 extensions::ExtensionSystem::Get(profile)->info_map();
[email protected]ba780c12013-10-01 17:07:06869 host->AddFilter(new NaClHostMessageFilter(
[email protected]14230ca2013-06-26 23:33:03870 id, profile->IsOffTheRecord(),
871 profile->GetPath(), extension_info_map,
872 context));
[email protected]01e59752013-06-18 00:17:35873#endif
[email protected]2b12c322013-09-19 06:53:56874#if defined(OS_ANDROID)
[email protected]ba780c12013-10-01 17:07:06875 host->AddFilter(new EncryptedMediaMessageFilterAndroid());
[email protected]2b12c322013-09-19 06:53:56876#endif
[email protected]3e69bc82011-05-26 23:22:38877
[email protected]2ccf45c2011-08-19 23:35:50878 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
879 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07880
881 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56882
883 RendererContentSettingRules rules;
884 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
885 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14886}
887
[email protected]3d7474ff2011-07-27 17:47:37888GURL ChromeContentBrowserClient::GetEffectiveURL(
889 content::BrowserContext* browser_context, const GURL& url) {
890 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52891 if (!profile)
892 return url;
893
[email protected]b3cb3a32013-07-31 01:32:29894 // If the input |url| should be assigned to the Instant renderer, make its
895 // effective URL distinct from other URLs on the search provider's domain.
896 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
897 return chrome::GetEffectiveURLForInstant(url, profile);
898
[email protected]d5bcd06f2013-04-21 08:07:24899#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30900 // If the input |url| should be assigned to the Signin renderer, make its
901 // effective URL distinct from other URLs on the signin service's domain.
902 // Note that the signin renderer will be allowed to sign the user in to
903 // Chrome.
904 if (SigninManager::IsWebBasedSigninFlowURL(url))
905 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24906#endif
[email protected]970c63e2013-03-07 00:25:30907
[email protected]c5dec6292013-01-25 04:54:52908 // If the input |url| is part of an installed app, the effective URL is an
909 // extension URL with the ID of that extension as the host. This has the
910 // effect of grouping apps together in a common SiteInstance.
911 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13912 extensions::ExtensionSystem::Get(profile)->extension_service();
913 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08914 return url;
915
[email protected]06bdd2b2012-11-30 18:47:13916 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55917 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08918 if (!extension)
919 return url;
920
[email protected]15877ca2011-11-18 22:40:52921 // Bookmark apps do not use the hosted app process model, and should be
922 // treated as normal URLs.
923 if (extension->from_bookmark())
924 return url;
925
[email protected]36fb2c7c2011-04-04 15:49:08926 // If the URL is part of an extension's web extent, convert it to an
927 // extension URL.
928 return extension->GetResourceURL(url.path());
929}
930
[email protected]056ad2a2011-07-12 02:13:55931bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37932 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52933 // Non-extension, non-Instant URLs should generally use
934 // process-per-site-instance. Because we expect to use the effective URL,
935 // URLs for hosted apps (apart from bookmark apps) should have an extension
936 // scheme by now.
937
938 Profile* profile = Profile::FromBrowserContext(browser_context);
939 if (!profile)
940 return false;
941
[email protected]df113a12013-07-24 04:56:08942 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52943 return true;
944
[email protected]d5bcd06f2013-04-21 08:07:24945#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30946 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
947 return true;
[email protected]d5bcd06f2013-04-21 08:07:24948#endif
[email protected]970c63e2013-03-07 00:25:30949
[email protected]885c0e92012-11-13 20:27:42950 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55951 return false;
952
[email protected]c5dec6292013-01-25 04:54:52953 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13954 extensions::ExtensionSystem::Get(profile)->extension_service();
955 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55956 return false;
957
[email protected]be9915fb2013-07-18 09:28:55958 const Extension* extension =
959 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:55960 if (!extension)
961 return false;
962
963 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53964 // permission, or that does not allow JavaScript access to the background
965 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55966 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40967 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06968 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29969 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53970 return false;
971 }
972 }
[email protected]056ad2a2011-07-12 02:13:55973
[email protected]7b54ca02012-03-02 18:06:53974 // Hosted apps that have script access to their background page must use
975 // process per site, since all instances can make synchronous calls to the
976 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55977 return true;
978}
979
[email protected]672c8c12013-03-07 12:30:06980// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41981void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
982 std::vector<std::string>* additional_schemes) {
983 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06984}
985
[email protected]6bd30072013-02-08 18:17:11986net::URLRequestContextGetter*
987ChromeContentBrowserClient::CreateRequestContext(
988 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06989 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11990 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06991 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11992}
993
994net::URLRequestContextGetter*
995ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
996 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40997 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11998 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06999 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111000 Profile* profile = Profile::FromBrowserContext(browser_context);
1001 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:061002 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111003}
1004
[email protected]46fb9442011-12-09 17:57:471005bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1006 return ProfileIOData::IsHandledURL(url);
1007}
1008
[email protected]c4365fa42013-05-14 01:08:241009bool ChromeContentBrowserClient::CanCommitURL(
1010 content::RenderProcessHost* process_host,
1011 const GURL& url) {
1012 // We need to let most extension URLs commit in any process, since this can
1013 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1014 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1015 // cannot be loaded in iframes and should never be requested outside its
1016 // process.
1017 Profile* profile =
1018 Profile::FromBrowserContext(process_host->GetBrowserContext());
1019 ExtensionService* service =
1020 extensions::ExtensionSystem::Get(profile)->extension_service();
1021 if (!service)
1022 return true;
1023 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551024 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241025 if (new_extension &&
1026 new_extension->is_hosted_app() &&
1027 new_extension->id() == extension_misc::kWebStoreAppId &&
1028 !service->process_map()->Contains(new_extension->id(),
1029 process_host->GetID())) {
1030 return false;
1031 }
1032
1033 return true;
1034}
1035
[email protected]9a60d1602013-09-11 04:09:121036bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1037 content::SiteInstance* site_instance, const GURL& url) {
1038 GURL from_url = site_instance->GetSiteURL();
1039 // Do not allow pages from the web or other extensions navigate to
1040 // non-web-accessible extension resources.
1041 if (url.SchemeIs(extensions::kExtensionScheme) &&
1042 (from_url.SchemeIsHTTPOrHTTPS() ||
1043 from_url.SchemeIs(extensions::kExtensionScheme))) {
1044 Profile* profile = Profile::FromBrowserContext(
1045 site_instance->GetProcess()->GetBrowserContext());
1046 ExtensionService* service =
1047 extensions::ExtensionSystem::Get(profile)->extension_service();
1048 if (!service)
1049 return true;
1050 const Extension* extension =
1051 service->extensions()->GetExtensionOrAppByURL(url);
1052 if (!extension)
1053 return true;
1054 const Extension* from_extension =
1055 service->extensions()->GetExtensionOrAppByURL(
1056 site_instance->GetSiteURL());
1057 if (from_extension && from_extension->id() == extension->id())
1058 return true;
1059
1060 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1061 extension, url.path()))
1062 return false;
1063 }
1064 return true;
1065}
1066
[email protected]2a5221b2011-09-27 23:07:311067bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301068 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311069 const GURL& site_url) {
1070 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301071 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521072 // This may be NULL during tests. In that case, just assume any site can
1073 // share any host.
1074 if (!profile)
1075 return true;
1076
[email protected]d43f99fe2013-04-03 00:20:141077 // Instant URLs should only be in the instant process and instant process
1078 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521079 InstantService* instant_service =
1080 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141081 if (instant_service) {
1082 bool is_instant_process = instant_service->IsInstantProcess(
1083 process_host->GetID());
1084 bool should_be_in_instant_process =
1085 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1086 if (is_instant_process || should_be_in_instant_process)
1087 return is_instant_process && should_be_in_instant_process;
1088 }
[email protected]c5dec6292013-01-25 04:54:521089
[email protected]d5bcd06f2013-04-21 08:07:241090#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301091 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1092 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1093 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241094#endif
[email protected]970c63e2013-03-07 00:25:301095
[email protected]06bdd2b2012-11-30 18:47:131096 ExtensionService* service =
1097 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461098 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311099
[email protected]ffa97602011-11-17 17:55:521100 // Don't allow the Task Manager to share a process with anything else.
1101 // Otherwise it can affect the renderers it is observing.
1102 // Note: we could create another RenderProcessHostPrivilege bucket for
1103 // this to allow multiple chrome://tasks instances to share, but that's
1104 // a very unlikely case without serious consequences.
1105 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1106 return false;
1107
[email protected]8d3132f62011-10-12 07:13:421108 // These may be NULL during tests. In that case, just assume any site can
1109 // share any host.
[email protected]6f371442011-11-09 06:45:461110 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311111 return true;
1112
[email protected]eec0b33c2011-12-05 22:09:451113 // Otherwise, just make sure the process privilege matches the privilege
1114 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571115 RenderProcessHostPrivilege privilege_required =
1116 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451117 return GetProcessPrivilege(process_host, process_map, service) ==
1118 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311119}
1120
[email protected]76411f412012-02-22 18:56:061121// This function is trying to limit the amount of processes used by extensions
1122// with background pages. It uses a globally set percentage of processes to
1123// run such extensions and if the limit is exceeded, it returns true, to
1124// indicate to the content module to group extensions together.
1125bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1126 content::BrowserContext* browser_context, const GURL& url) {
1127 // It has to be a valid URL for us to check for an extension.
1128 if (!url.is_valid())
1129 return false;
1130
1131 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191132 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131133 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061134 if (!service)
1135 return false;
1136
1137 // We have to have a valid extension with background page to proceed.
1138 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551139 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061140 if (!extension)
1141 return false;
[email protected]9367eabc2013-03-01 01:29:291142 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061143 return false;
1144
1145 std::set<int> process_ids;
1146 size_t max_process_count =
1147 content::RenderProcessHost::GetMaxRendererProcessCount();
1148
1149 // Go through all profiles to ensure we have total count of extension
1150 // processes containing background pages, otherwise one profile can
1151 // starve the other.
1152 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1153 GetLoadedProfiles();
1154 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031155 ExtensionProcessManager* epm =
1156 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321157 for (ExtensionProcessManager::const_iterator iter =
1158 epm->background_hosts().begin();
1159 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131160 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321161 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061162 }
1163 }
1164
1165 if (process_ids.size() >
1166 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1167 return true;
1168 }
1169
1170 return false;
1171}
1172
[email protected]6f371442011-11-09 06:45:461173void ChromeContentBrowserClient::SiteInstanceGotProcess(
1174 SiteInstance* site_instance) {
1175 CHECK(site_instance->HasProcess());
1176
1177 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021178 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521179 if (!profile)
1180 return;
1181
1182 // Remember the ID of the Instant process to signal the renderer process
1183 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031184 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321185 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521186 InstantService* instant_service =
1187 InstantServiceFactory::GetForProfile(profile);
1188 if (instant_service)
1189 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1190 }
1191
[email protected]d5bcd06f2013-04-21 08:07:241192#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301193 // We only expect there to be one signin process as we use process-per-site
1194 // for signin URLs. The signin process will be cleared from SigninManager
1195 // when the renderer is destroyed.
1196 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1197 SigninManager* signin_manager =
1198 SigninManagerFactory::GetForProfile(profile);
1199 if (signin_manager)
1200 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461201 BrowserThread::PostTask(
1202 BrowserThread::IO, FROM_HERE,
1203 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1204 extensions::ExtensionSystem::Get(profile)->info_map(),
1205 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301206 }
[email protected]d5bcd06f2013-04-21 08:07:241207#endif
[email protected]970c63e2013-03-07 00:25:301208
[email protected]06bdd2b2012-11-30 18:47:131209 ExtensionService* service =
1210 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461211 if (!service)
1212 return;
1213
[email protected]be9915fb2013-07-18 09:28:551214 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1215 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461216 if (!extension)
1217 return;
1218
[email protected]6bc04fd82011-12-04 02:29:351219 service->process_map()->Insert(extension->id(),
1220 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331221 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461222 BrowserThread::PostTask(
1223 BrowserThread::IO, FROM_HERE,
1224 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591225 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461226 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351227 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331228 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461229}
1230
1231void ChromeContentBrowserClient::SiteInstanceDeleting(
1232 SiteInstance* site_instance) {
1233 if (!site_instance->HasProcess())
1234 return;
1235
1236 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021237 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131238 ExtensionService* service =
1239 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461240 if (!service)
1241 return;
1242
[email protected]be9915fb2013-07-18 09:28:551243 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1244 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461245 if (!extension)
1246 return;
1247
[email protected]6bc04fd82011-12-04 02:29:351248 service->process_map()->Remove(extension->id(),
1249 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331250 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461251 BrowserThread::PostTask(
1252 BrowserThread::IO, FROM_HERE,
1253 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591254 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461255 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351256 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331257 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461258}
1259
[email protected]f05763972012-06-06 18:17:261260bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141261 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081262 const GURL& current_url,
1263 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261264 if (current_url.is_empty()) {
1265 // Always choose a new process when navigating to extension URLs. The
1266 // process grouping logic will combine all of a given extension's pages
1267 // into the same process.
[email protected]885c0e92012-11-13 20:27:421268 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261269 return true;
[email protected]e3daf3c2011-10-05 21:17:081270
[email protected]f05763972012-06-06 18:17:261271 return false;
1272 }
1273
1274 // Also, we must switch if one is an extension and the other is not the exact
1275 // same extension.
[email protected]885c0e92012-11-13 20:27:421276 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1277 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261278 if (current_url.GetOrigin() != new_url.GetOrigin())
1279 return true;
1280 }
1281
[email protected]e9841fbd2013-02-22 23:12:141282 // The checks below only matter if we can retrieve which extensions are
1283 // installed.
1284 Profile* profile =
1285 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1286 ExtensionService* service =
1287 extensions::ExtensionSystem::Get(profile)->extension_service();
1288 if (!service)
1289 return false;
1290
1291 // We must swap if the URL is for an extension and we are not using an
1292 // extension process.
1293 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551294 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141295 // Ignore all hosted apps except the Chrome Web Store, since they do not
1296 // require their own BrowsingInstance (e.g., postMessage is ok).
1297 if (new_extension &&
1298 new_extension->is_hosted_app() &&
1299 new_extension->id() != extension_misc::kWebStoreAppId)
1300 new_extension = NULL;
1301 if (new_extension &&
1302 site_instance->HasProcess() &&
1303 !service->process_map()->Contains(new_extension->id(),
1304 site_instance->GetProcess()->GetID()))
1305 return true;
1306
[email protected]f05763972012-06-06 18:17:261307 return false;
[email protected]e3daf3c2011-10-05 21:17:081308}
1309
[email protected]395045c2012-05-22 15:04:381310bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1311 content::ResourceContext* resource_context, const GURL& current_url,
1312 const GURL& new_url) {
1313 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1314 return extensions::CrossesExtensionProcessBoundary(
1315 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551316 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381317}
1318
[email protected]3d831992013-07-04 01:13:291319bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1320 return !url.SchemeIs(chrome::kChromeNativeScheme);
1321}
1322
[email protected]763ec4ca2011-04-29 15:48:121323std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1324 const std::string& alias_name) {
1325 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1326}
1327
[email protected]b80f68432011-05-02 17:22:301328void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1329 CommandLine* command_line, int child_process_id) {
[email protected]264c0acac2013-10-01 13:33:301330#if defined(OS_POSIX)
[email protected]b80f68432011-05-02 17:22:301331 if (IsCrashReporterEnabled()) {
[email protected]264c0acac2013-10-01 13:33:301332 std::string enable_crash_reporter;
1333 GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter);
1334#if !defined(OS_MACOSX)
1335 enable_crash_reporter += "," + base::GetLinuxDistro();
1336#endif
[email protected]b80f68432011-05-02 17:22:301337 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
[email protected]264c0acac2013-10-01 13:33:301338 enable_crash_reporter);
[email protected]b80f68432011-05-02 17:22:301339 }
[email protected]264c0acac2013-10-01 13:33:301340#endif // OS_POSIX
[email protected]b80f68432011-05-02 17:22:301341
[email protected]f1933792011-06-14 00:49:341342 if (logging::DialogsAreSuppressed())
1343 command_line->AppendSwitch(switches::kNoErrorDialogs);
1344
[email protected]b80f68432011-05-02 17:22:301345 std::string process_type =
1346 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171347 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321348
[email protected]7c9b6f92013-09-10 18:11:351349 static const char* const kCommonSwitchNames[] = {
1350 switches::kChromeFrame,
1351 switches::kUserDataDir, // Make logs go to the right file.
1352 };
1353 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1354 arraysize(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:321355
[email protected]718eab62011-10-05 21:16:521356 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:301357#if defined(OS_CHROMEOS)
1358 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441359 browser_command_line.GetSwitchValueASCII(
1360 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301361 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441362 command_line->AppendSwitchASCII(
1363 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301364#endif
1365
[email protected]f3b1a082011-11-18 00:34:301366 content::RenderProcessHost* process =
1367 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371368 if (process) {
1369 Profile* profile = Profile::FromBrowserContext(
1370 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131371 ExtensionService* extension_service =
1372 extensions::ExtensionSystem::Get(profile)->extension_service();
1373 if (extension_service) {
1374 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001375 if (process_map && process_map->Contains(process->GetID()))
1376 command_line->AppendSwitch(switches::kExtensionProcess);
1377 }
[email protected]b80f68432011-05-02 17:22:301378
[email protected]a8d851f82011-12-21 00:32:371379 PrefService* prefs = profile->GetPrefs();
1380 // Currently this pref is only registered if applied via a policy.
1381 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1382 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1383 // Turn this policy into a command line switch.
1384 command_line->AppendSwitch(switches::kDisable3DAPIs);
1385 }
[email protected]718eab62011-10-05 21:16:521386
[email protected]a8d851f82011-12-21 00:32:371387 // Disable client-side phishing detection in the renderer if it is
1388 // disabled in the Profile preferences or the browser process.
1389 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1390 !g_browser_process->safe_browsing_detection_service()) {
1391 command_line->AppendSwitch(
1392 switches::kDisableClientSidePhishingDetection);
1393 }
[email protected]0045b0f42012-07-26 11:52:081394
1395 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211396 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521397
1398 InstantService* instant_service =
1399 InstantServiceFactory::GetForProfile(profile);
1400 if (instant_service &&
1401 instant_service->IsInstantProcess(process->GetID()))
1402 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301403
[email protected]d5bcd06f2013-04-21 08:07:241404#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301405 SigninManager* signin_manager =
1406 SigninManagerFactory::GetForProfile(profile);
1407 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1408 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241409#endif
[email protected]47c7ec82012-01-18 03:29:211410 }
[email protected]4287a3d2011-06-13 23:56:511411
[email protected]16dc42452013-04-09 04:37:191412 if (message_center::IsRichNotificationEnabled())
1413 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191414
[email protected]47c7ec82012-01-18 03:29:211415 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511416 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171417 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431418 autofill::switches::kDisablePasswordGeneration,
[email protected]e217c5632013-04-12 19:11:481419 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171420 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431421 autofill::switches::kEnablePasswordGeneration,
[email protected]49d9b142013-07-19 08:50:271422 extensions::switches::kAllowLegacyExtensionManifests,
1423 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511424 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271425 extensions::switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511426 switches::kAllowHTTPBackgroundPage,
[email protected]9d450492013-06-13 23:08:371427 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1428 // to browser.
1429 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511430 switches::kAppsCheckoutURL,
1431 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311432 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511433 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501434 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531435 switches::kDisableExtensionsResourceWhitelist,
[email protected]83c85262013-08-22 21:13:461436 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111437 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531438 switches::kEnableAdview,
1439 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441440 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211441 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511442 switches::kEnableIPCFuzzing,
1443 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451444 switches::kEnableNetBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511445 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511446 switches::kMemoryProfiling,
1447 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371448 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371449 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511450 switches::kPpapiFlashArgs,
1451 switches::kPpapiFlashInProcess,
1452 switches::kPpapiFlashPath,
1453 switches::kPpapiFlashVersion,
1454 switches::kProfilingAtStart,
1455 switches::kProfilingFile,
1456 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371457 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511458 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291459 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381460 switches::kWhitelistedExtensionID,
[email protected]499e7c52013-10-04 16:03:091461 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:511462 };
1463
1464 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1465 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171466 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381467 static const char* const kSwitchNames[] = {
[email protected]c8d02992013-07-31 22:16:511468 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271469 extensions::switches::kExtensionsOnChromeURLs,
[email protected]eb653f82012-05-24 02:31:351470 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381471 switches::kWhitelistedExtensionID,
1472 };
1473
1474 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1475 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511476 } else if (process_type == switches::kPluginProcess) {
1477 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441478#if defined(OS_CHROMEOS)
1479 chromeos::switches::kLoginProfile,
1480#endif
[email protected]4287a3d2011-06-13 23:56:511481 switches::kMemoryProfiling,
1482 switches::kSilentDumpOnDCHECK,
[email protected]4287a3d2011-06-13 23:56:511483 };
1484
1485 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1486 arraysize(kSwitchNames));
1487 } else if (process_type == switches::kZygoteProcess) {
1488 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511489 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501490 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511491 switches::kPpapiFlashInProcess,
1492 switches::kPpapiFlashPath,
1493 switches::kPpapiFlashVersion,
1494 };
1495
1496 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1497 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111498 } else if (process_type == switches::kGpuProcess) {
1499 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1500 // because GPU is expected to be unreliable.
1501 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1502 !command_line->HasSwitch(switches::kDisableBreakpad))
1503 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301504 }
[email protected]6f08af82011-09-15 01:19:031505
1506 // The command line switch kEnableBenchmarking needs to be specified along
1507 // with the kEnableStatsTable switch to ensure that the stats table global
1508 // is initialized correctly.
1509 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1510 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301511}
1512
1513std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431514 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351515 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301516 return g_browser_process->GetApplicationLocale();
1517}
1518
[email protected]597a867b2011-11-18 18:31:201519std::string ChromeContentBrowserClient::GetAcceptLangs(
1520 content::BrowserContext* context) {
1521 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371522 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081523}
1524
[email protected]9ec0f452012-05-31 15:58:531525gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221526 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531527 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081528}
1529
[email protected]a2176792011-05-08 19:30:491530bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091531 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191532 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201533 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201535 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051536 return io_data->GetCookieSettings()->
1537 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491538}
1539
[email protected]ed24fad2011-05-10 22:44:011540bool ChromeContentBrowserClient::AllowGetCookie(
1541 const GURL& url,
1542 const GURL& first_party,
1543 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201544 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011545 int render_process_id,
1546 int render_view_id) {
1547 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201548 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051549 bool allow = io_data->GetCookieSettings()->
1550 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011551
[email protected]8093a542011-05-13 07:29:321552 BrowserThread::PostTask(
1553 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031554 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431555 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011556 return allow;
1557}
1558
1559bool ChromeContentBrowserClient::AllowSetCookie(
1560 const GURL& url,
1561 const GURL& first_party,
1562 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201563 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011564 int render_process_id,
1565 int render_view_id,
1566 net::CookieOptions* options) {
1567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201568 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051569 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1570 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1571
[email protected]8093a542011-05-13 07:29:321572 BrowserThread::PostTask(
1573 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031574 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431575 render_view_id, url, first_party, cookie_line, *options,
1576 !allow));
[email protected]ed24fad2011-05-10 22:44:011577 return allow;
1578}
1579
[email protected]d5a19162011-06-30 18:51:541580bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201581 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201583 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431584 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1585 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261586
[email protected]bf510ed2012-06-05 08:31:431587 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1588 // Could we even support per-origin settings?
1589 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541590}
1591
[email protected]5c5a88e2011-11-12 00:45:351592bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351593 const GURL& url,
1594 const string16& name,
1595 const string16& display_name,
1596 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201597 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481598 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201600 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351601 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1602 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1603
[email protected]62151052012-02-01 18:40:481604 // Record access to database for potential display in UI.
1605 std::vector<std::pair<int, int> >::const_iterator i;
1606 for (i = render_views.begin(); i != render_views.end(); ++i) {
1607 BrowserThread::PostTask(
1608 BrowserThread::UI, FROM_HERE,
1609 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1610 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351611 }
1612
1613 return allow;
1614}
1615
1616bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351617 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201618 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481619 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201621 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351622 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1623 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1624
[email protected]62151052012-02-01 18:40:481625 // Record access to file system for potential display in UI.
1626 std::vector<std::pair<int, int> >::const_iterator i;
1627 for (i = render_views.begin(); i != render_views.end(); ++i) {
1628 BrowserThread::PostTask(
1629 BrowserThread::UI, FROM_HERE,
1630 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1631 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351632 }
1633
1634 return allow;
1635}
1636
[email protected]7c5ff9a2012-03-02 07:42:491637bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1638 const GURL& url,
1639 const string16& name,
1640 content::ResourceContext* context,
1641 const std::vector<std::pair<int, int> >& render_views) {
1642 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1643 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1644 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1645 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1646
1647 // Record access to IndexedDB for potential display in UI.
1648 std::vector<std::pair<int, int> >::const_iterator i;
1649 for (i = render_views.begin(); i != render_views.end(); ++i) {
1650 BrowserThread::PostTask(
1651 BrowserThread::UI, FROM_HERE,
1652 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1653 i->first, i->second, url, name, !allow));
1654 }
1655
1656 return allow;
1657}
1658
[email protected]33ad6ce92013-08-27 14:39:081659net::URLRequestContext*
1660ChromeContentBrowserClient::OverrideRequestContextForURL(
1661 const GURL& url, content::ResourceContext* context) {
1662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1663 if (url.SchemeIs(extensions::kExtensionScheme)) {
1664 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1665 return io_data->extensions_request_context();
1666 }
1667
1668 return NULL;
1669}
1670
[email protected]317f96c92011-05-31 06:53:411671QuotaPermissionContext*
1672ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1673 return new ChromeQuotaPermissionContext();
1674}
1675
[email protected]848dd042011-06-04 18:24:031676void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171677 int render_process_id,
1678 int render_view_id,
1679 int cert_error,
1680 const net::SSLInfo& ssl_info,
1681 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021682 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031683 bool overridable,
[email protected]d9be47702012-05-16 03:41:221684 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171685 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001686 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021687 if (resource_type != ResourceType::MAIN_FRAME) {
1688 // A sub-resource has a certificate error. The user doesn't really
1689 // have a context for making the right decision, so block the
1690 // request hard, without an info bar to allow showing the insecure
1691 // content.
[email protected]8c965c22013-05-23 19:28:001692 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021693 return;
1694 }
1695
[email protected]f9034cf2011-07-21 12:43:411696 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131697 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171698 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411699 if (!tab) {
1700 NOTREACHED();
1701 return;
1702 }
1703 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501704 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301705 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011706 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1707 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411708 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171709 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411710 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001711 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411712 return;
1713 }
1714 }
1715
[email protected]1e87df32012-09-12 04:53:191716#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231717 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1718 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1719 if (captive_portal_tab_helper)
1720 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191721#endif
1722
[email protected]f9034cf2011-07-21 12:43:411723 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221724 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1725 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031726}
1727
[email protected]c99c442e2011-08-24 11:37:301728void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451729 int render_process_id,
1730 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401731 const net::HttpNetworkSession* network_session,
1732 net::SSLCertRequestInfo* cert_request_info,
1733 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131734 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451735 render_process_id, render_view_id);
1736 if (!tab) {
1737 NOTREACHED();
1738 return;
1739 }
1740
[email protected]6786bf402011-12-03 15:19:451741 GURL requesting_url("https://" + cert_request_info->host_and_port);
1742 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1743 << cert_request_info->host_and_port;
1744
[email protected]627e0512011-12-21 22:55:301745 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451746 scoped_ptr<Value> filter(
1747 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1748 requesting_url,
1749 requesting_url,
1750 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1751 std::string(), NULL));
1752
1753 if (filter.get()) {
1754 // Try to automatically select a client certificate.
1755 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1756 DictionaryValue* filter_dict =
1757 static_cast<DictionaryValue*>(filter.get());
1758
1759 const std::vector<scoped_refptr<net::X509Certificate> >&
1760 all_client_certs = cert_request_info->client_certs;
1761 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091762 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451763 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091764 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451765 return;
1766 }
1767 }
1768 } else {
1769 NOTREACHED();
1770 }
1771 }
1772
[email protected]11feec322012-09-18 03:58:521773 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1774 if (!ssl_tab_helper) {
1775 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451776 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141777 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401778 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451779 return;
1780 }
[email protected]11feec322012-09-18 03:58:521781 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401782 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451783}
1784
[email protected]3b455502012-12-11 18:22:581785void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451786 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581787 net::CertificateMimeType cert_type,
1788 const void* cert_data,
1789 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451790 int render_process_id,
1791 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581792 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1793 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451794}
1795
[email protected]dc73a7b2012-03-25 15:27:181796content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561797 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181798}
1799
[email protected]941623e2011-06-07 23:06:041800void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1801 const GURL& source_origin,
1802 int callback_context,
1803 int render_process_id,
1804 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111805#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1807 WebContents* contents =
1808 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1809 if (!contents) {
[email protected]941623e2011-06-07 23:06:041810 NOTREACHED();
1811 return;
1812 }
1813
[email protected]d0d9c3ee2012-06-19 03:07:021814 // Skip showing the infobar if the request comes from an extension, and that
1815 // extension has the 'notify' permission. (If the extension does not have the
1816 // permission, the user will still be prompted.)
1817 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011818 ExtensionInfoMap* extension_info_map =
1819 extensions::ExtensionSystem::Get(profile)->info_map();
1820 DesktopNotificationService* notification_service =
1821 DesktopNotificationServiceFactory::GetForProfile(profile);
1822 const Extension* extension = NULL;
1823 if (extension_info_map) {
1824 ExtensionSet extensions;
1825 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1826 source_origin, render_process_id,
1827 extensions::APIPermission::kNotification, &extensions);
1828 for (ExtensionSet::const_iterator iter = extensions.begin();
1829 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381830 if (notification_service->IsNotifierEnabled(NotifierId(
1831 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361832 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011833 break;
1834 }
1835 }
1836 }
[email protected]eb4832a2012-12-08 01:57:521837 RenderViewHost* rvh =
1838 RenderViewHost::FromID(render_process_id, render_view_id);
1839 if (IsExtensionWithPermissionOrSuggestInConsole(
1840 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021841 if (rvh)
1842 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1843 return;
1844 }
1845
[email protected]c7cd5942013-04-30 03:31:011846 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021847 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111848#else
1849 NOTIMPLEMENTED();
1850#endif
[email protected]941623e2011-06-07 23:06:041851}
1852
1853WebKit::WebNotificationPresenter::Permission
1854 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021855 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201856 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021857 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111858#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041859 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481860 // Sometimes a notification may be invoked during the shutdown.
1861 // See http://crbug.com/256638
1862 if (browser_shutdown::IsTryingToQuit())
1863 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
1864
[email protected]df02aca2012-02-09 21:03:201865 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041866
[email protected]c7cd5942013-04-30 03:31:011867 DesktopNotificationService* notification_service =
1868 io_data->GetNotificationService();
1869 if (notification_service) {
1870 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1871 ExtensionSet extensions;
1872 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1873 source_origin, render_process_id,
1874 extensions::APIPermission::kNotification, &extensions);
1875 for (ExtensionSet::const_iterator iter = extensions.begin();
1876 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381877 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
1878 if (notification_service->IsNotifierEnabled(notifier_id))
[email protected]c7cd5942013-04-30 03:31:011879 return WebKit::WebNotificationPresenter::PermissionAllowed;
1880 }
1881
1882 return notification_service->HasPermission(source_origin);
1883 }
1884
1885 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111886#else
1887 return WebKit::WebNotificationPresenter::PermissionAllowed;
1888#endif
[email protected]941623e2011-06-07 23:06:041889}
1890
1891void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171892 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041893 int render_process_id,
1894 int render_view_id,
1895 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111896#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041897 RenderViewHost* rvh = RenderViewHost::FromID(
1898 render_process_id, render_view_id);
1899 if (!rvh) {
1900 NOTREACHED();
1901 return;
1902 }
1903
[email protected]9f76c1e2012-03-05 15:15:581904 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301905 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041906 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371907 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041908 service->ShowDesktopNotification(
1909 params, render_process_id, render_view_id,
1910 worker ? DesktopNotificationService::WorkerNotification :
1911 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111912#else
1913 NOTIMPLEMENTED();
1914#endif
[email protected]941623e2011-06-07 23:06:041915}
1916
1917void ChromeContentBrowserClient::CancelDesktopNotification(
1918 int render_process_id,
1919 int render_view_id,
1920 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111921#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041922 RenderViewHost* rvh = RenderViewHost::FromID(
1923 render_process_id, render_view_id);
1924 if (!rvh) {
1925 NOTREACHED();
1926 return;
1927 }
1928
[email protected]9f76c1e2012-03-05 15:15:581929 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301930 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041931 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371932 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041933 service->CancelDesktopNotification(
1934 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111935#else
1936 NOTIMPLEMENTED();
1937#endif
[email protected]941623e2011-06-07 23:06:041938}
1939
[email protected]9f3fba52011-06-08 20:37:191940bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351941 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:571942 const GURL& opener_top_level_frame_url,
[email protected]34eec7ffe32011-11-02 23:49:021943 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191944 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:231945 const GURL& target_url,
1946 const content::Referrer& referrer,
1947 WindowOpenDisposition disposition,
1948 const WebWindowFeatures& features,
1949 bool user_gesture,
1950 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:201951 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011952 int render_process_id,
[email protected]190e5e22013-07-27 05:59:231953 bool is_guest,
1954 int opener_id,
[email protected]03b6d552012-03-29 04:03:011955 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191956 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011957
1958 *no_javascript_access = false;
1959
[email protected]5e5f55e262c52013-09-12 00:27:191960 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1961 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1962
[email protected]9f3fba52011-06-08 20:37:191963 // If the opener is trying to create a background window but doesn't have
1964 // the appropriate permission, fail the attempt.
[email protected]6940eef82013-09-11 11:58:411965 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]03b6d552012-03-29 04:03:011966 if (!map->SecurityOriginHasAPIPermission(
1967 source_origin,
1968 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061969 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011970 return false;
1971 }
1972
[email protected]7b54ca02012-03-02 18:06:531973 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1974 // return a recently installed Extension even if this CanCreateWindow call
1975 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011976 // because the permission check above would have caused an early return
1977 // already. We must use the full URL to find hosted apps, though, and not
1978 // just the origin.
[email protected]be9915fb2013-07-18 09:28:551979 const Extension* extension =
1980 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:291981 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011982 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:231983
1984 return true;
[email protected]9f3fba52011-06-08 20:37:191985 }
[email protected]056efdc2013-04-06 00:14:531986
1987 // No new browser window (popup or tab) in app mode.
1988 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1989 chrome::IsRunningInForcedAppMode()) {
1990 return false;
1991 }
1992
[email protected]d2bac6b2013-08-13 03:42:361993 if (g_browser_process->prerender_tracker() &&
1994 g_browser_process->prerender_tracker()->TryCancelOnIOThread(
1995 render_process_id,
1996 opener_id,
1997 prerender::FINAL_STATUS_CREATE_NEW_WINDOW)) {
1998 return false;
1999 }
2000
[email protected]190e5e22013-07-27 05:59:232001 if (is_guest)
2002 return true;
2003
[email protected]190e5e22013-07-27 05:59:232004 HostContentSettingsMap* content_settings =
2005 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
[email protected]916615b2013-09-11 18:19:442006 BlockedWindowParams blocked_params(target_url,
2007 referrer,
2008 disposition,
2009 features,
2010 user_gesture,
2011 opener_suppressed,
2012 render_process_id,
2013 opener_id);
[email protected]190e5e22013-07-27 05:59:232014
[email protected]7f53dff2013-08-05 10:45:502015 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch(
2016 switches::kDisablePopupBlocking)) {
[email protected]931bc922013-09-11 21:42:572017 if (content_settings->GetContentSetting(opener_top_level_frame_url,
2018 opener_top_level_frame_url,
[email protected]190e5e22013-07-27 05:59:232019 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]916615b2013-09-11 18:19:442020 std::string()) !=
[email protected]190e5e22013-07-27 05:59:232021 CONTENT_SETTING_ALLOW) {
[email protected]916615b2013-09-11 18:19:442022 BrowserThread::PostTask(BrowserThread::UI,
2023 FROM_HERE,
2024 base::Bind(&HandleBlockedPopupOnUIThread,
2025 blocked_params));
2026 return false;
[email protected]190e5e22013-07-27 05:59:232027 }
[email protected]916615b2013-09-11 18:19:442028 }
[email protected]190e5e22013-07-27 05:59:232029
[email protected]916615b2013-09-11 18:19:442030#if defined(OS_ANDROID)
2031 if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) {
[email protected]190e5e22013-07-27 05:59:232032 BrowserThread::PostTask(BrowserThread::UI,
2033 FROM_HERE,
[email protected]916615b2013-09-11 18:19:442034 base::Bind(&HandleSingleTabModeBlockOnUIThread,
2035 blocked_params));
[email protected]190e5e22013-07-27 05:59:232036 return false;
2037 }
[email protected]916615b2013-09-11 18:19:442038#endif
[email protected]190e5e22013-07-27 05:59:232039
[email protected]9f3fba52011-06-08 20:37:192040 return true;
2041}
2042
2043std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202044 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192045 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2046 // Check if it's an extension-created worker, in which case we want to use
2047 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202048 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192049 const Extension* extension =
2050 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2051 return extension ? extension->name() : std::string();
2052}
2053
[email protected]99907362012-01-11 05:41:402054void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2055 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172056}
2057
[email protected]7a06d282013-05-03 04:39:332058// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022059content::SpeechRecognitionManagerDelegate*
2060 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002061#if defined(ENABLE_INPUT_SPEECH)
2062 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322063#else
[email protected]855e18b2013-07-08 21:02:002064 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2065 // need the base delegate without the bubble UI.
2066 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322067#endif
[email protected]66cfec62012-02-24 17:57:512068}
2069
[email protected]ae6e9912011-07-27 01:18:282070net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2071 return g_browser_process->net_log();
2072}
2073
[email protected]32538d92011-08-25 00:09:232074AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2075 return new ChromeAccessTokenStore();
2076}
2077
[email protected]dbae6b02011-06-29 23:51:412078bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012079 return true;
[email protected]dbae6b02011-06-29 23:51:412080}
2081
[email protected]64d69de42012-02-06 00:19:542082void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322083 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062084 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582085 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062086 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062087
[email protected]f3986f82012-01-03 20:00:062088 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542089 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062090 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542091 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062092 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542093 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062094 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542095 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062096 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542097 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062098 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542099 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032100 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2101 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:062102
[email protected]64d69de42012-02-06 00:19:542103 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402104 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542105 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402106 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542107 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402108 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542109 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402110 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062111
[email protected]ddf72142012-05-22 04:52:402112 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062113
[email protected]64d69de42012-02-06 00:19:542114 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402115 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542116 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062117 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542118 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062119 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2120 const DictionaryValue* inspector_settings =
2121 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2122 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182123 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2124 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062125 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182126 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542127 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182128 std::make_pair(iter.key(), value));
2129 }
[email protected]f3986f82012-01-03 20:00:062130 }
2131 }
[email protected]64d69de42012-02-06 00:19:542132 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062133
[email protected]ddf72142012-05-22 04:52:402134 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542135 web_prefs->javascript_enabled = false;
2136 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2137 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402138 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542139 web_prefs->plugins_enabled = false;
2140 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2141 web_prefs->java_enabled = false;
2142 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402143 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062144
[email protected]64d69de42012-02-06 00:19:542145 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2146 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062147
[email protected]64d69de42012-02-06 00:19:542148 web_prefs->memory_info_enabled =
2149 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2150 web_prefs->allow_displaying_insecure_content =
2151 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2152 web_prefs->allow_running_insecure_content =
2153 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322154#if defined(OS_ANDROID)
2155 web_prefs->font_scale_factor =
2156 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2157 web_prefs->force_enable_zoom =
2158 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2159#endif
[email protected]5c915252013-05-07 13:15:392160
[email protected]af4256d52013-06-04 20:39:072161#if defined(OS_ANDROID)
2162 web_prefs->password_echo_enabled =
2163 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2164#else
[email protected]9d06d88d2012-02-23 22:37:082165 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072166#endif
2167
[email protected]5c915252013-05-07 13:15:392168#if defined(OS_CHROMEOS)
2169 // Enable password echo during OOBE when keyboard driven flag is set.
2170 if (chromeos::UserManager::IsInitialized() &&
2171 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
[email protected]c94ac692013-07-27 00:50:102172 !chromeos::StartupUtils::IsOobeCompleted() &&
2173 chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation()) {
2174 web_prefs->password_echo_enabled = true;
[email protected]5c915252013-05-07 13:15:392175 }
2176#endif
[email protected]f3986f82012-01-03 20:00:062177
[email protected]46f8e742013-05-03 18:37:142178#if defined(OS_ANDROID)
2179 web_prefs->user_style_sheet_enabled = false;
2180#else
[email protected]64d69de42012-02-06 00:19:542181 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152182 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362183 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152184 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542185 web_prefs->user_style_sheet_enabled = true;
2186 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152187 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542188 } else {
2189 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062190 }
[email protected]46f8e742013-05-03 18:37:142191#endif
[email protected]f3986f82012-01-03 20:00:062192
[email protected]cfadadd2013-04-03 04:43:022193 web_prefs->asynchronous_spell_checking_enabled = true;
2194 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572195
[email protected]64d69de42012-02-06 00:19:542196 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062197 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542198 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062199 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542200 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062201 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2202
2203 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542204 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062205 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542206 web_prefs->default_encoding);
2207 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402208 prefs->ClearPref(prefs::kDefaultCharset);
2209 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062210 }
[email protected]64d69de42012-02-06 00:19:542211 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062212
[email protected]299d7f12012-05-23 05:31:152213 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232214 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132215 ExtensionService* service =
2216 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062217 if (service) {
[email protected]1bc28312012-11-08 08:31:532218 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2219 const Extension* extension = service->extensions()->GetByID(url.host());
2220 // Ensure that we are only granting extension preferences to URLs with
2221 // the correct scheme. Without this check, chrome-guest:// schemes used by
2222 // webview tags as well as hosts that happen to match the id of an
2223 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422224 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532225 extension_webkit_preferences::SetPreferences(
2226 extension, view_type, web_prefs);
2227 }
[email protected]f3986f82012-01-03 20:00:062228 }
2229
[email protected]cb2edf22013-04-01 20:25:232230 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542231 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232232 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062233 // Disable all kinds of acceleration for background pages.
2234 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542235 web_prefs->force_compositing_mode = false;
2236 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062237 }
[email protected]2e21fe292012-03-02 22:52:322238
2239#if defined(FILE_MANAGER_EXTENSION)
2240 // Override the default of suppressing HW compositing for WebUI pages for the
2241 // file manager, which is implemented using WebUI but wants HW acceleration
2242 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532243 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]2de96a52013-08-14 01:18:092244 url.host() == file_manager::kFileManagerAppId) {
[email protected]2e21fe292012-03-02 22:52:322245 web_prefs->accelerated_compositing_enabled = true;
2246 web_prefs->accelerated_2d_canvas_enabled = true;
2247 }
2248#endif
[email protected]181a95ee2011-07-12 19:26:362249}
2250
2251void ChromeContentBrowserClient::UpdateInspectorSetting(
2252 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062253 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582254 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062255 DictionaryPrefUpdate update(
2256 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2257 prefs::kWebKitInspectorSettings);
2258 DictionaryValue* inspector_settings = update.Get();
2259 inspector_settings->SetWithoutPathExpansion(key,
2260 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362261}
2262
[email protected]b8148ac2011-07-13 22:03:252263void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2264 BrowserURLHandler* handler) {
2265 // Add the default URL handlers.
2266 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2267 BrowserURLHandler::null_handler());
2268 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2269 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2270
[email protected]b3adbd02011-11-30 22:23:272271 // about: handler. Must come before chrome: handler, since it will
2272 // rewrite about: urls to chrome: URLs and then expect chrome: to
2273 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252274 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2275 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032276
2277 // Handler to rewrite chrome://newtab for InstantExtended.
2278 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2279 &chrome::HandleNewTabURLReverseRewrite);
2280
[email protected]b8148ac2011-07-13 22:03:252281 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242282 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252283}
2284
2285void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372286 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582287 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472288 BrowsingDataRemover* remover =
2289 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552290 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2291 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252292 // BrowsingDataRemover takes care of deleting itself when done.
2293}
2294
2295void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372296 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582297 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472298 BrowsingDataRemover* remover =
2299 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232300 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552301 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252302 // BrowsingDataRemover takes care of deleting itself when done.
2303}
2304
[email protected]650b2d52013-02-10 03:41:452305base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:492306 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:322307}
2308
[email protected]c9b6eb62011-10-18 20:49:392309std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2310 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2311}
2312
[email protected]b7631cc2012-09-15 05:08:382313void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2314 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542315#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382316 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2317 scoped_ptr<ppapi::host::HostFactory>(
2318 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542319#endif
[email protected]b7631cc2012-09-15 05:08:382320}
2321
[email protected]0c7193742012-11-07 19:05:032322content::BrowserPpapiHost*
2323 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2324 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132325 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032326 while (!iter.Done()) {
2327 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2328 if (host->process() &&
2329 host->process()->GetData().id == plugin_process_id) {
2330 // Found the plugin.
2331 return host->browser_ppapi_host();
2332 }
2333 ++iter;
2334 }
2335 return NULL;
2336}
2337
[email protected]7b38b192013-03-23 18:39:312338bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2339 content::BrowserContext* browser_context, const GURL& site_url) {
2340 if (CommandLine::ForCurrentProcess()->HasSwitch(
2341 switches::kEnableBrowserPluginForAllViewTypes))
2342 return true;
2343
[email protected]22aa4f82013-09-24 17:01:442344 if (content::HasWebUIScheme(site_url))
2345 return true;
2346
[email protected]7b38b192013-03-23 18:39:312347 Profile* profile = Profile::FromBrowserContext(browser_context);
2348 ExtensionService* service =
2349 extensions::ExtensionSystem::Get(profile)->extension_service();
2350 if (!service)
2351 return false;
2352
[email protected]be9915fb2013-07-18 09:28:552353 const Extension* extension =
2354 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312355 if (!extension)
2356 return false;
2357
[email protected]c2d2f102013-04-29 16:42:582358 return extension->HasAPIPermission(APIPermission::kWebView) ||
2359 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312360}
2361
[email protected]38cd8f7f2012-06-15 22:06:072362bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582363 content::BrowserContext* browser_context,
2364 const GURL& url,
[email protected]dda54822013-06-15 01:26:392365 bool private_api,
[email protected]8b92ed182013-09-21 04:47:122366 const content::SocketPermissionRequest* params) {
[email protected]93f72062013-05-29 20:29:402367#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372368 Profile* profile = Profile::FromBrowserContext(browser_context);
2369 const ExtensionSet* extension_set = NULL;
2370 if (profile) {
2371 extension_set = extensions::ExtensionSystem::Get(profile)->
2372 extension_service()->extensions();
2373 }
[email protected]dda54822013-06-15 01:26:392374
2375 if (private_api) {
2376 // Access to private socket APIs is controlled by the whitelist.
2377 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2378 allowed_socket_origins_)) {
2379 return true;
2380 }
2381 } else {
2382 // Access to public socket APIs is controlled by extension permissions.
2383 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2384 extension_set) {
2385 const Extension* extension = extension_set->GetByID(url.host());
2386 if (extension) {
[email protected]8b92ed182013-09-21 04:47:122387 if (params) {
2388 extensions::SocketPermission::CheckParam check_params(
2389 params->type, params->host, params->port);
2390 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2391 extension, extensions::APIPermission::kSocket,
2392 &check_params)) {
2393 return true;
2394 }
2395 } else {
2396 if (extensions::PermissionsData::HasAPIPermission(
2397 extension, extensions::APIPermission::kSocket)) {
2398 return true;
2399 }
[email protected]dda54822013-06-15 01:26:392400 }
2401 }
2402 }
2403 }
2404
2405 // Allow both public and private APIs if the command line says so.
2406 return IsHostAllowedByCommandLine(url, extension_set,
2407 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402408#else
[email protected]a658d452012-03-02 12:45:292409 return false;
[email protected]93f72062013-05-29 20:29:402410#endif
[email protected]e461da2f2012-02-16 19:06:402411}
2412
[email protected]a28e3302013-02-03 03:50:432413ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2414 WebContents* web_contents) {
2415 return new ChromeSelectFilePolicy(web_contents);
2416}
2417
[email protected]7d9424702013-04-14 13:14:162418void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2419 std::vector<std::string>* additional_allowed_schemes) {
2420 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2421 additional_allowed_schemes);
2422 additional_allowed_schemes->push_back(kChromeUIScheme);
2423 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2424}
2425
[email protected]f19bbf62013-07-09 01:22:322426void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312427 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532428 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322429 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532430#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032431 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322432 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032433 storage_partition_path,
2434 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322435 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532436#endif
[email protected]b40015c2013-06-26 08:13:312437#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312438 fileapi::ExternalMountPoints* external_mount_points =
2439 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312440 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322441 chromeos::FileSystemBackend* backend =
2442 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312443 new drive::FileSystemBackendDelegate(browser_context),
2444 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312445 external_mount_points,
2446 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322447 backend->AddSystemMountPoints();
2448 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2449 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312450#endif
[email protected]445b7db2013-08-02 04:58:272451
[email protected]e86e2be2013-08-30 11:20:392452 additional_backends->push_back(
2453 new sync_file_system::SyncFileSystemBackend(
2454 Profile::FromBrowserContext(browser_context)));
[email protected]02250952013-04-24 23:52:532455}
2456
[email protected]e60c0232011-11-11 19:56:352457#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182458void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2459 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382460 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082461 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392462#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452463 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392464 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2465 DCHECK(!data_path.empty());
2466
2467 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452468 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392469 data_path.AppendASCII("chrome_100_percent.pak");
[email protected]5db2b7492013-08-23 05:33:092470 base::PlatformFile f =
2471 base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
[email protected]29699c22012-10-03 23:57:392472 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372473 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392474 FileDescriptor(f, true)));
2475
2476 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452477 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392478 GetLocaleFilePath(locale, false);
2479 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2480 DCHECK(f != base::kInvalidPlatformFileValue);
2481 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2482 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382483
[email protected]650b2d52013-02-10 03:41:452484 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372485 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2486 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2487 DCHECK(f != base::kInvalidPlatformFileValue);
2488 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2489 FileDescriptor(f, true)));
2490
[email protected]82174aa2013-01-22 21:53:432491 if (IsCrashReporterEnabled()) {
2492 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2493 if (f == base::kInvalidPlatformFileValue) {
2494 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2495 "be disabled for this process.";
2496 } else {
2497 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2498 FileDescriptor(f, true)));
2499 }
[email protected]40da3e0c2012-10-24 22:03:382500 }
[email protected]40da3e0c2012-10-24 22:03:382501
2502#else
2503 int crash_signal_fd = GetCrashSignalFD(command_line);
2504 if (crash_signal_fd >= 0) {
2505 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2506 FileDescriptor(crash_signal_fd,
2507 false)));
2508 }
[email protected]29699c22012-10-03 23:57:392509#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302510}
[email protected]e60c0232011-11-11 19:56:352511#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302512
[email protected]4a65826d2011-08-25 16:04:012513#if defined(OS_WIN)
2514const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2515 return chrome::kBrowserResourcesDll;
2516}
[email protected]34f48682013-03-20 00:30:182517
2518void ChromeContentBrowserClient::PreSpawnRenderer(
2519 sandbox::TargetPolicy* policy,
2520 bool* success) {
2521 // This code is duplicated in nacl_exe_win_64.cc.
2522 // Allow the server side of a pipe restricted to the "chrome.nacl."
2523 // namespace so that it cannot impersonate other system or other chrome
2524 // service pipes.
2525 sandbox::ResultCode result = policy->AddRule(
2526 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2527 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2528 L"\\\\.\\pipe\\chrome.nacl.*");
2529 if (result != sandbox::SBOX_ALL_OK) {
2530 *success = false;
2531 return;
2532 }
2533
2534 // Renderers need to send named pipe handles and shared memory
2535 // segment handles to NaCl loader processes.
2536 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2537 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2538 L"File");
2539 if (result != sandbox::SBOX_ALL_OK) {
2540 *success = false;
2541 return;
2542 }
2543}
[email protected]4a65826d2011-08-25 16:04:012544#endif
2545
[email protected]37a72af2011-06-13 05:42:012546#if defined(USE_NSS)
2547crypto::CryptoModuleBlockingPasswordDelegate*
2548 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2549 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292550 return chrome::NewCryptoModuleBlockingDialogDelegate(
2551 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012552}
2553#endif
2554
[email protected]a6868c22013-10-09 02:50:292555bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2556 content::BrowserContext* browser_context,
2557 const GURL& url) {
2558#if defined(ENABLE_PLUGINS)
2559 Profile* profile = Profile::FromBrowserContext(browser_context);
2560 const ExtensionSet* extension_set = NULL;
2561 if (profile) {
2562 extension_set = extensions::ExtensionSystem::Get(profile)->
2563 extension_service()->extensions();
2564 }
2565 // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved
2566 // from the renderer to the browser.
2567 return IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2568 allowed_file_handle_origins_) ||
2569 IsHostAllowedByCommandLine(url, extension_set,
2570 switches::kAllowNaClFileHandleAPI);
2571#else
2572 return false;
2573#endif
2574}
2575
[email protected]d977f9c2011-03-14 16:10:262576} // namespace chrome