blob: d30780ff9665b7babdb50627a0489cfd595b4620 [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]5e5f55e262c52013-09-12 00:27:1944#include "chrome/browser/extensions/process_map.h"
[email protected]eb4832a2012-12-08 01:57:5245#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2346#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1247#include "chrome/browser/google/google_util.h"
[email protected]0533cc6d2013-06-27 22:44:0548#include "chrome/browser/guestview/adview/adview_guest.h"
49#include "chrome/browser/guestview/guestview_constants.h"
50#include "chrome/browser/guestview/webview/webview_guest.h"
[email protected]11158e2d2013-02-01 02:31:5651#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0452#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]01e59752013-06-18 00:17:3553#include "chrome/browser/nacl_host/nacl_host_message_filter.h"
[email protected]0c7193742012-11-07 19:05:0354#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2855#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0456#include "chrome/browser/notifications/desktop_notification_service.h"
57#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4258#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5659#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0660#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]190e5e22013-07-27 05:59:2361#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4162#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5063#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0764#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4165#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1466#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0367#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1468#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3269#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0670#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1471#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3872#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4373#include "chrome/browser/search/instant_service.h"
74#include "chrome/browser/search/instant_service_factory.h"
75#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1476#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0277#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3378#include "chrome/browser/speech/tts_message_filter.h"
[email protected]3b455502012-12-11 18:22:5879#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0380#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5281#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]180c66a62013-08-05 12:01:3682#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:4583#include "chrome/browser/tab_contents/tab_util.h"
[email protected]916615b2013-09-11 18:19:4484#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
[email protected]40aa8bb2013-08-23 20:28:2385#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
[email protected]a28e3302013-02-03 03:50:4386#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2587#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4488#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5089#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0690#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1591#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2792#include "chrome/browser/validation_message_message_filter.h"
[email protected]b80f68432011-05-02 17:22:3093#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0194#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1495#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3096#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2997#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0498#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3899#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:44100#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:43101#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:29102#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]dda54822013-06-15 01:26:39103#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]157cc902012-11-02 06:31:58104#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]9a60d1602013-09-11 04:09:12105#include "chrome/common/extensions/web_accessible_resources_handler.h"
[email protected]f1933792011-06-14 00:49:34106#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37107#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12108#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38109#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09110#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53111#include "chromeos/chromeos_constants.h"
[email protected]d5d383252013-07-04 14:44:32112#include "components/nacl/common/nacl_process_type.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]cb2edf22013-04-01 20:25:23129#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42130#include "extensions/common/constants.h"
[email protected]49d9b142013-07-19 08:50:27131#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39132#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23133#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53134#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58135#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34136#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06137#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57138#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38139#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39140#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08141#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24142#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31143#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18144#include "webkit/common/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:26145
[email protected]b48c9182011-10-26 18:03:30146#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38147#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18148#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38149#elif defined(OS_MACOSX)
150#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56151#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30152#elif defined(OS_CHROMEOS)
153#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]f19bbf62013-07-09 01:22:32154#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h"
155#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39156#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49157#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10158#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44159#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26160#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30161#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09162#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38163#include "chrome/browser/android/crash_dump_manager.h"
[email protected]916615b2013-09-11 18:19:44164#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
[email protected]81054f812012-08-30 00:47:09165#include "chrome/browser/chrome_browser_main_android.h"
[email protected]2b12c322013-09-19 06:53:56166#include "chrome/browser/media/encrypted_media_message_filter_android.h"
[email protected]29699c22012-10-03 23:57:39167#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30168#elif defined(OS_POSIX)
169#include "chrome/browser/chrome_browser_main_posix.h"
170#endif
171
[email protected]6653c192012-04-10 22:52:44172#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30173#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12174#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43175#endif
[email protected]b80f68432011-05-02 17:22:30176
[email protected]1e87df32012-09-12 04:53:19177#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
178#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
179#endif
180
[email protected]29699c22012-10-03 23:57:39181#if defined(OS_ANDROID)
182#include "ui/base/ui_base_paths.h"
183#endif
184
[email protected]37a72af2011-06-13 05:42:01185#if defined(USE_NSS)
186#include "chrome/browser/ui/crypto_module_password_dialog.h"
187#endif
188
[email protected]d5bcd06f2013-04-21 08:07:24189#if !defined(OS_CHROMEOS)
190#include "chrome/browser/signin/signin_manager.h"
191#include "chrome/browser/signin/signin_manager_factory.h"
192#endif
193
[email protected]02250952013-04-24 23:52:53194#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32195#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53196#endif
197
[email protected]6ef98b5a2013-05-31 23:58:31198#if defined(ENABLE_WEBRTC)
199#include "chrome/browser/media/webrtc_logging_handler_host.h"
200#endif
201
[email protected]855e18b2013-07-08 21:02:00202#if defined(ENABLE_INPUT_SPEECH)
203#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
204#endif
205
[email protected]02a3dc122013-06-13 15:07:53206#if defined(FILE_MANAGER_EXTENSION)
[email protected]473c9a4f2013-09-05 03:09:46207#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]02a3dc122013-06-13 15:07:53208#endif
209
[email protected]e8b6ca02013-07-10 18:00:51210#if defined(TOOLKIT_GTK)
211#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
212#endif
213
214#if defined(TOOLKIT_VIEWS)
215#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
216#endif
217
218#if defined(USE_ASH)
219#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
220#endif
221
222#if defined(USE_AURA)
223#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
224#endif
225
226#if defined(USE_X11)
227#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
228#endif
229
[email protected]c6ce08072013-07-31 07:48:53230#if defined(ENABLE_SPELLCHECK)
231#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
232#endif
233
[email protected]190e5e22013-07-27 05:59:23234using WebKit::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08235using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47236using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03237using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39238using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31239using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59240using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08241using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00242using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11243using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33244using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13245using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06246using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34247using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40248using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38249using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39250
[email protected]c5dbef02011-05-13 05:06:09251namespace {
252
[email protected]eabbfb12013-04-05 23:28:35253// Cached version of the locale so we can return the locale on the I/O
254// thread.
255base::LazyInstance<std::string> g_io_thread_application_locale;
256
[email protected]93f72062013-05-29 20:29:40257#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40258const char* kPredefinedAllowedSocketOrigins[] = {
259 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18260 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45261 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
262 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
263 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
264 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35265 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54266 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
267 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
268 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
269 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
270 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
271 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38272 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58273 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29274 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42275 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
276 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
277 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
278 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
279 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
280 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40281};
[email protected]93f72062013-05-29 20:29:40282#endif
[email protected]e461da2f2012-02-16 19:06:40283
[email protected]f8f93eb2012-09-25 03:06:24284// Returns a copy of the given url with its host set to given host and path set
285// to given path. Other parts of the url will be the same.
286GURL ReplaceURLHostAndPath(const GURL& url,
287 const std::string& host,
288 const std::string& path) {
289 url_canon::Replacements<char> replacements;
290 replacements.SetHost(host.c_str(),
291 url_parse::Component(0, host.length()));
292 replacements.SetPath(path.c_str(),
293 url_parse::Component(0, path.length()));
294 return url.ReplaceComponents(replacements);
295}
296
297// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
298GURL AddUberHost(const GURL& url) {
299 const std::string uber_host = chrome::kChromeUIUberHost;
300 const std::string new_path = url.host() + url.path();
301
302 return ReplaceURLHostAndPath(url, uber_host, new_path);
303}
304
[email protected]045bf7c2012-09-28 20:27:36305// If url->host() is "chrome" and url->path() has characters other than the
306// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
307// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24308bool RemoveUberHost(GURL* url) {
309 if (url->host() != chrome::kChromeUIUberHost)
310 return false;
311
[email protected]045bf7c2012-09-28 20:27:36312 if (url->path().empty() || url->path() == "/")
313 return false;
314
[email protected]f8f93eb2012-09-25 03:06:24315 const std::string old_path = url->path();
316
317 const std::string::size_type separator = old_path.find('/', 1);
318 std::string new_host;
319 std::string new_path;
320 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36321 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24322 } else {
323 new_host = old_path.substr(1, separator - 1);
324 new_path = old_path.substr(separator);
325 }
326
[email protected]44e8add2013-06-13 17:29:15327 // Do not allow URLs with paths empty before the first slash since we can't
328 // have an empty host. (e.g "foo://chrome//")
329 if (new_host.empty())
330 return false;
331
[email protected]f8f93eb2012-09-25 03:06:24332 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
333
[email protected]44e8add2013-06-13 17:29:15334 DCHECK(url->is_valid());
335
[email protected]f8f93eb2012-09-25 03:06:24336 return true;
337}
338
[email protected]b8148ac2011-07-13 22:03:25339// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42340bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24341 // Do not handle special URLs such as "about:foo"
342 if (!url->host().empty()) {
343 const GURL chrome_url = AddUberHost(*url);
344
345 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
346 // be called.
347 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
348 browser_context, chrome_url))
349 return true;
350 }
351
[email protected]863f70a2012-01-27 02:05:50352 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
353 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25354 return false;
355
[email protected]fe69558d2012-03-12 11:34:49356#if defined(OS_CHROMEOS)
357 // Special case : in ChromeOS in Guest mode bookmarks and history are
358 // disabled for security reasons. New tab page explains the reasons, so
359 // we redirect user to new tab page.
360 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
361 if (url->SchemeIs(chrome::kChromeUIScheme) &&
362 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
363 url->DomainIs(chrome::kChromeUIHistoryHost))) {
364 // Rewrite with new tab URL
365 *url = GURL(chrome::kChromeUINewTabURL);
366 }
367 }
368#endif
369
[email protected]b8148ac2011-07-13 22:03:25370 // Special case the new tab page. In older versions of Chrome, the new tab
371 // page was hosted at chrome-internal:<blah>. This might be in people's saved
372 // sessions or bookmarks, so we say any URL with that scheme triggers the new
373 // tab page.
374 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
375 // Rewrite it with the proper new tab URL.
376 *url = GURL(chrome::kChromeUINewTabURL);
377 }
378
379 return true;
380}
381
[email protected]f8f93eb2012-09-25 03:06:24382// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
383// "chrome://foo/".
384bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
385 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
386 return false;
387
388 return RemoveUberHost(url);
389}
390
[email protected]8d3132f62011-10-12 07:13:42391// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
392// below. Extension, and isolated apps require different privileges to be
393// granted to their RenderProcessHosts. This classification allows us to make
394// sure URLs are served by hosts with the right set of privileges.
395enum RenderProcessHostPrivilege {
396 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45397 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42398 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45399 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42400};
401
402RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
403 const GURL& url,
404 ExtensionService* service) {
405 // Default to a normal renderer cause it is lower privileged. This should only
406 // occur if the URL on a site instance is either malformed, or uninitialized.
407 // If it is malformed, then there is no need for better privileges anyways.
408 // If it is uninitialized, but eventually settles on being an a scheme other
409 // than normal webrenderer, the navigation logic will correct us out of band
410 // anyways.
411 if (!url.is_valid())
412 return PRIV_NORMAL;
413
[email protected]885c0e92012-11-13 20:27:42414 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44415 const Extension* extension =
416 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43417 if (extension &&
418 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42419 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45420 if (extension && extension->is_hosted_app())
421 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42422
423 return PRIV_EXTENSION;
424 }
425
426 return PRIV_NORMAL;
427}
428
429RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30430 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46431 extensions::ProcessMap* process_map,
432 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46433 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30434 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46435 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21436 return PRIV_NORMAL;
437
[email protected]6f371442011-11-09 06:45:46438 for (std::set<std::string>::iterator iter = extension_ids.begin();
439 iter != extension_ids.end(); ++iter) {
440 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43441 if (extension &&
442 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42443 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45444 if (extension && extension->is_hosted_app())
445 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42446 }
447
[email protected]676f6ab2011-10-19 20:23:21448 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42449}
450
[email protected]6786bf402011-12-03 15:19:45451bool CertMatchesFilter(const net::X509Certificate& cert,
452 const base::DictionaryValue& filter) {
453 // TODO(markusheintz): This is the minimal required filter implementation.
454 // Implement a better matcher.
455
456 // An empty filter matches any client certificate since no requirements are
457 // specified at all.
458 if (filter.empty())
459 return true;
460
461 std::string common_name;
462 if (filter.GetString("ISSUER.CN", &common_name) &&
463 (cert.issuer().common_name == common_name)) {
464 return true;
465 }
466 return false;
467}
468
[email protected]f3986f82012-01-03 20:00:06469// Fills |map| with the per-script font prefs under path |map_name|.
470void FillFontFamilyMap(const PrefService* prefs,
471 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53472 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06473 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
474 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
475 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
476 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23477 if (!font_family.empty())
478 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06479 }
480}
481
[email protected]a1733df2012-06-22 11:24:18482#if defined(OS_POSIX) && !defined(OS_MACOSX)
483int GetCrashSignalFD(const CommandLine& command_line) {
484 if (command_line.HasSwitch(switches::kExtensionProcess)) {
485 ExtensionCrashHandlerHostLinux* crash_handler =
486 ExtensionCrashHandlerHostLinux::GetInstance();
487 return crash_handler->GetDeathSignalSocket();
488 }
489
490 std::string process_type =
491 command_line.GetSwitchValueASCII(switches::kProcessType);
492
493 if (process_type == switches::kRendererProcess)
494 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
495
496 if (process_type == switches::kPluginProcess)
497 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
498
499 if (process_type == switches::kPpapiPluginProcess)
500 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
501
502 if (process_type == switches::kGpuProcess)
503 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
504
505 return -1;
506}
507#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
508
[email protected]d5bcd06f2013-04-21 08:07:24509#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30510GURL GetEffectiveURLForSignin(const GURL& url) {
511 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
512
513 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03514 // Copy the path because the argument to SetPathStr must outlive
515 // the Replacements object.
516 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30517 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03518 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30519 effective_url = effective_url.ReplaceComponents(replacements);
520 return effective_url;
521}
[email protected]d5bcd06f2013-04-21 08:07:24522#endif
[email protected]970c63e2013-03-07 00:25:30523
[email protected]eabbfb12013-04-05 23:28:35524void SetApplicationLocaleOnIOThread(const std::string& locale) {
525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
526 g_io_thread_application_locale.Get() = locale;
527}
528
[email protected]916615b2013-09-11 18:19:44529void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) {
530 WebContents* tab = tab_util::GetWebContentsByID(params.render_process_id(),
531 params.opener_id());
[email protected]190e5e22013-07-27 05:59:23532 if (!tab)
533 return;
534
[email protected]190e5e22013-07-27 05:59:23535 PopupBlockerTabHelper* popup_helper =
536 PopupBlockerTabHelper::FromWebContents(tab);
537 if (!popup_helper)
538 return;
[email protected]916615b2013-09-11 18:19:44539 popup_helper->AddBlockedPopup(params);
[email protected]190e5e22013-07-27 05:59:23540}
[email protected]190e5e22013-07-27 05:59:23541
[email protected]916615b2013-09-11 18:19:44542#if defined(OS_ANDROID)
543void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) {
544 WebContents* web_contents =
545 tab_util::GetWebContentsByID(params.render_process_id(),
546 params.opener_id());
547 if (!web_contents)
548 return;
549
550 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params);
551}
552#endif // defined(OS_ANDROID)
553
[email protected]9dbfff12011-07-01 19:37:07554} // namespace
[email protected]c5dbef02011-05-13 05:06:09555
[email protected]d977f9c2011-03-14 16:10:26556namespace chrome {
557
[email protected]e461da2f2012-02-16 19:06:40558ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40559#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40560 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
561 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40562#endif
[email protected]1deace22013-05-22 06:14:46563
564 permissions_policy_delegate_.reset(
565 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40566}
567
568ChromeContentBrowserClient::~ChromeContentBrowserClient() {
569}
570
[email protected]bca18382012-06-25 19:15:23571// static
[email protected]37ca3fe02013-07-05 15:32:44572void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34573 user_prefs::PrefRegistrySyncable* registry) {
574 registry->RegisterBooleanPref(
575 prefs::kDisable3DAPIs,
576 false,
577 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
578 registry->RegisterBooleanPref(
579 prefs::kEnableHyperlinkAuditing,
580 true,
581 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
582 registry->RegisterBooleanPref(
583 prefs::kEnableMemoryInfo,
584 false,
585 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23586}
587
[email protected]eabbfb12013-04-05 23:28:35588// static
589void ChromeContentBrowserClient::SetApplicationLocale(
590 const std::string& locale) {
591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
592
593 // This object is guaranteed to outlive all threads so we don't have to
594 // worry about the lack of refcounting and can just post as Unretained.
595 //
596 // The common case is that this function is called early in Chrome startup
597 // before any threads are created (it will also be called later if the user
598 // changes the pref). In this case, there will be no threads created and
599 // posting will fail. When there are no threads, we can just set the string
600 // without worrying about threadsafety.
601 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
602 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
603 g_io_thread_application_locale.Get() = locale;
604 }
605}
606
[email protected]50462bf02011-11-21 19:13:31607content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
608 const content::MainFunctionParams& parameters) {
609 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30610 // Construct the Main browser parts based on the OS type.
611#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31612 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04613#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31614 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30615#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22616 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26617#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31618 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14619#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09620 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30621#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31622 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04623#else
[email protected]b48c9182011-10-26 18:03:30624 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31625 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30626#endif
627
[email protected]7e75e4a2013-05-17 17:20:03628 chrome::AddProfilesExtraParts(main_parts);
629
[email protected]c7480942011-11-08 19:18:27630 // Construct additional browser parts. Stages are called in the order in
631 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22632#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51633 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04634#endif
[email protected]c7480942011-11-08 19:18:27635
636#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51637 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27638#endif
639
[email protected]dc04be7c2012-03-15 23:57:49640#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51641 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49642#endif
643
[email protected]e050ef142012-03-21 01:04:24644#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51645 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
646#endif
647
648#if defined(USE_X11)
649 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24650#endif
651
[email protected]95132f52013-04-12 02:19:04652 chrome::AddMetricsExtraParts(main_parts);
653
[email protected]50462bf02011-11-21 19:13:31654 return main_parts;
[email protected]f967b722011-09-07 00:58:04655}
656
[email protected]e94bbcb2012-09-07 05:33:57657std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19658 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57659 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53660 std::string partition_id;
661
662 // The partition ID for webview guest processes is the string value of its
663 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
664 if (site.SchemeIs(chrome::kGuestScheme))
665 partition_id = site.spec();
666
[email protected]056efdc2013-04-06 00:14:53667 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53668 return partition_id;
669}
670
671bool ChromeContentBrowserClient::IsValidStoragePartitionId(
672 content::BrowserContext* browser_context,
673 const std::string& partition_id) {
674 // The default ID is empty and is always valid.
675 if (partition_id.empty())
676 return true;
677
678 return GURL(partition_id).is_valid();
679}
680
681void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
682 content::BrowserContext* browser_context,
683 const GURL& site,
[email protected]14acc642012-11-17 12:20:10684 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53685 std::string* partition_domain,
686 std::string* partition_name,
687 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10688 // Default to the browser-wide storage partition and override based on |site|
689 // below.
690 partition_domain->clear();
691 partition_name->clear();
692 *in_memory = false;
693
[email protected]1bc28312012-11-08 08:31:53694 // For the webview tag, we create special guest processes, which host the
695 // tag content separately from the main application that embeds the tag.
696 // A webview tag can specify both the partition name and whether the storage
697 // for that partition should be persisted. Each tag gets a SiteInstance with
698 // a specially formatted URL, based on the application it is hosted by and
699 // the partition requested by it. The format for that URL is:
700 // chrome-guest://partition_domain/persist?partition_name
701 if (site.SchemeIs(chrome::kGuestScheme)) {
702 // Since guest URLs are only used for packaged apps, there must be an app
703 // id in the URL.
704 CHECK(site.has_host());
705 *partition_domain = site.host();
706 // Since persistence is optional, the path must either be empty or the
707 // literal string.
708 *in_memory = (site.path() != "/persist");
709 // The partition name is user supplied value, which we have encoded when the
710 // URL was created, so it needs to be decoded.
711 *partition_name = net::UnescapeURLComponent(site.query(),
712 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10713 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
714 // If |can_be_default| is false, the caller is stating that the |site|
715 // should be parsed as if it had isolated storage. In particular it is
716 // important to NOT check ExtensionService for the is_storage_isolated()
717 // attribute because this code path is run during Extension uninstall
718 // to do cleanup after the Extension has already been unloaded from the
719 // ExtensionService.
720 bool is_isolated = !can_be_default;
721 if (can_be_default) {
722 const Extension* extension = NULL;
723 Profile* profile = Profile::FromBrowserContext(browser_context);
724 ExtensionService* extension_service =
725 extensions::ExtensionSystem::Get(profile)->extension_service();
726 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55727 extension =
728 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43729 if (extension &&
730 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10731 is_isolated = true;
732 }
733 }
734 }
[email protected]1bc28312012-11-08 08:31:53735
[email protected]14acc642012-11-17 12:20:10736 if (is_isolated) {
737 CHECK(site.has_host());
738 // For extensions with isolated storage, the the host of the |site| is
739 // the |partition_domain|. The |in_memory| and |partition_name| are only
740 // used in guest schemes so they are cleared here.
741 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53742 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10743 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53744 }
[email protected]d1198fd2012-08-13 22:50:19745 }
746
[email protected]14acc642012-11-17 12:20:10747 // Assert that if |can_be_default| is false, the code above must have found a
748 // non-default partition. If this fails, the caller has a serious logic
749 // error about which StoragePartition they expect to be in and it is not
750 // safe to continue.
751 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44752}
753
[email protected]38b098f2012-03-14 21:11:57754content::WebContentsViewDelegate*
755 ChromeContentBrowserClient::GetWebContentsViewDelegate(
756 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27757 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32758}
759
[email protected]738f57a2013-06-29 21:06:54760void ChromeContentBrowserClient::GuestWebContentsCreated(
761 WebContents* guest_web_contents,
762 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22763 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54764 scoped_ptr<base::DictionaryValue> extra_params) {
765 if (opener_web_contents) {
766 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
767 if (!guest) {
768 NOTREACHED();
769 return;
770 }
771
[email protected]50c827d2013-09-13 21:36:09772 // Create a new GuestView of the same type as the opener.
773 *guest_delegate =
774 GuestView::Create(guest_web_contents, guest->GetViewType());
[email protected]738f57a2013-06-29 21:06:54775 return;
776 }
777
778 if (!extra_params) {
779 NOTREACHED();
780 return;
781 }
782 std::string api_type;
[email protected]90547d72013-08-06 05:57:27783 extra_params->GetString(guestview::kParameterApi, &api_type);
[email protected]738f57a2013-06-29 21:06:54784
[email protected]50c827d2013-09-13 21:36:09785 *guest_delegate =
786 GuestView::Create(guest_web_contents,
787 GuestView::GetViewTypeFromString(api_type));
[email protected]738f57a2013-06-29 21:06:54788}
789
[email protected]44295a12013-06-05 08:45:46790void ChromeContentBrowserClient::GuestWebContentsAttached(
791 WebContents* guest_web_contents,
792 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53793 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06794 Profile* profile = Profile::FromBrowserContext(
795 embedder_web_contents->GetBrowserContext());
796 ExtensionService* service =
797 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54798 if (!service) {
799 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06800 return;
[email protected]738f57a2013-06-29 21:06:54801 }
[email protected]44703cc72013-01-24 04:56:06802 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
[email protected]be9915fb2013-07-18 09:28:55803 const Extension* extension =
804 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]738f57a2013-06-29 21:06:54805 if (!extension) {
[email protected]efd6fb02013-08-05 04:44:06806 // It's ok to return here, since we could be running a browser plugin
807 // outside an extension, and don't need to attach a
808 // BrowserPluginGuestDelegate in that case;
809 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
[email protected]738f57a2013-06-29 21:06:54810 return;
[email protected]18699372013-06-25 20:42:55811 }
[email protected]738f57a2013-06-29 21:06:54812
813 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
814 if (!guest) {
815 NOTREACHED();
816 return;
817 }
[email protected]9934a5e2013-08-22 00:07:56818 guest->Attach(embedder_web_contents, extension->id(), extra_params);
[email protected]44703cc72013-01-24 04:56:06819}
820
[email protected]f3b1a082011-11-18 00:34:30821void ChromeContentBrowserClient::RenderProcessHostCreated(
822 content::RenderProcessHost* host) {
823 int id = host->GetID();
824 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41825 net::URLRequestContextGetter* context =
826 profile->GetRequestContextForRenderProcess(id);
827
[email protected]f3b1a082011-11-18 00:34:30828 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41829 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55830#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30831 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55832#endif
[email protected]658677f2012-06-09 06:04:02833#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08834 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03835#endif
[email protected]f3b1a082011-11-18 00:34:30836 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02837 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53838#if defined(ENABLE_SPELLCHECK)
[email protected]f3b1a082011-11-18 00:34:30839 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53840#endif
[email protected]7ceb99012011-12-21 08:05:56841#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21842 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56843#endif
[email protected]43535512013-02-20 20:41:41844 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
845 id, profile, context));
[email protected]2736c032012-05-11 18:06:07846 host->GetChannel()->AddFilter(
847 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27848 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33849 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31850#if defined(ENABLE_WEBRTC)
851 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
852#endif
[email protected]01e59752013-06-18 00:17:35853#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03854 ExtensionInfoMap* extension_info_map =
855 extensions::ExtensionSystem::Get(profile)->info_map();
856 host->GetChannel()->AddFilter(new NaClHostMessageFilter(
857 id, profile->IsOffTheRecord(),
858 profile->GetPath(), extension_info_map,
859 context));
[email protected]01e59752013-06-18 00:17:35860#endif
[email protected]2b12c322013-09-19 06:53:56861#if defined(OS_ANDROID)
862 host->GetChannel()->AddFilter(new EncryptedMediaMessageFilterAndroid());
863#endif
[email protected]3e69bc82011-05-26 23:22:38864
[email protected]2ccf45c2011-08-19 23:35:50865 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
866 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07867
868 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56869
870 RendererContentSettingRules rules;
871 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
872 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14873}
874
[email protected]3d7474ff2011-07-27 17:47:37875GURL ChromeContentBrowserClient::GetEffectiveURL(
876 content::BrowserContext* browser_context, const GURL& url) {
877 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52878 if (!profile)
879 return url;
880
[email protected]b3cb3a32013-07-31 01:32:29881 // If the input |url| should be assigned to the Instant renderer, make its
882 // effective URL distinct from other URLs on the search provider's domain.
883 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
884 return chrome::GetEffectiveURLForInstant(url, profile);
885
[email protected]d5bcd06f2013-04-21 08:07:24886#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30887 // If the input |url| should be assigned to the Signin renderer, make its
888 // effective URL distinct from other URLs on the signin service's domain.
889 // Note that the signin renderer will be allowed to sign the user in to
890 // Chrome.
891 if (SigninManager::IsWebBasedSigninFlowURL(url))
892 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24893#endif
[email protected]970c63e2013-03-07 00:25:30894
[email protected]c5dec6292013-01-25 04:54:52895 // If the input |url| is part of an installed app, the effective URL is an
896 // extension URL with the ID of that extension as the host. This has the
897 // effect of grouping apps together in a common SiteInstance.
898 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13899 extensions::ExtensionSystem::Get(profile)->extension_service();
900 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08901 return url;
902
[email protected]06bdd2b2012-11-30 18:47:13903 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55904 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08905 if (!extension)
906 return url;
907
[email protected]15877ca2011-11-18 22:40:52908 // Bookmark apps do not use the hosted app process model, and should be
909 // treated as normal URLs.
910 if (extension->from_bookmark())
911 return url;
912
[email protected]36fb2c7c2011-04-04 15:49:08913 // If the URL is part of an extension's web extent, convert it to an
914 // extension URL.
915 return extension->GetResourceURL(url.path());
916}
917
[email protected]056ad2a2011-07-12 02:13:55918bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37919 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52920 // Non-extension, non-Instant URLs should generally use
921 // process-per-site-instance. Because we expect to use the effective URL,
922 // URLs for hosted apps (apart from bookmark apps) should have an extension
923 // scheme by now.
924
925 Profile* profile = Profile::FromBrowserContext(browser_context);
926 if (!profile)
927 return false;
928
[email protected]df113a12013-07-24 04:56:08929 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52930 return true;
931
[email protected]d5bcd06f2013-04-21 08:07:24932#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30933 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
934 return true;
[email protected]d5bcd06f2013-04-21 08:07:24935#endif
[email protected]970c63e2013-03-07 00:25:30936
[email protected]885c0e92012-11-13 20:27:42937 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55938 return false;
939
[email protected]c5dec6292013-01-25 04:54:52940 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13941 extensions::ExtensionSystem::Get(profile)->extension_service();
942 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55943 return false;
944
[email protected]be9915fb2013-07-18 09:28:55945 const Extension* extension =
946 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:55947 if (!extension)
948 return false;
949
950 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53951 // permission, or that does not allow JavaScript access to the background
952 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55953 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40954 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06955 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29956 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53957 return false;
958 }
959 }
[email protected]056ad2a2011-07-12 02:13:55960
[email protected]7b54ca02012-03-02 18:06:53961 // Hosted apps that have script access to their background page must use
962 // process per site, since all instances can make synchronous calls to the
963 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55964 return true;
965}
966
[email protected]672c8c12013-03-07 12:30:06967// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41968void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
969 std::vector<std::string>* additional_schemes) {
970 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06971}
972
[email protected]6bd30072013-02-08 18:17:11973net::URLRequestContextGetter*
974ChromeContentBrowserClient::CreateRequestContext(
975 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06976 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11977 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06978 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11979}
980
981net::URLRequestContextGetter*
982ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
983 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40984 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11985 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06986 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11987 Profile* profile = Profile::FromBrowserContext(browser_context);
988 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06989 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11990}
991
[email protected]46fb9442011-12-09 17:57:47992bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
993 return ProfileIOData::IsHandledURL(url);
994}
995
[email protected]c4365fa42013-05-14 01:08:24996bool ChromeContentBrowserClient::CanCommitURL(
997 content::RenderProcessHost* process_host,
998 const GURL& url) {
999 // We need to let most extension URLs commit in any process, since this can
1000 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1001 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1002 // cannot be loaded in iframes and should never be requested outside its
1003 // process.
1004 Profile* profile =
1005 Profile::FromBrowserContext(process_host->GetBrowserContext());
1006 ExtensionService* service =
1007 extensions::ExtensionSystem::Get(profile)->extension_service();
1008 if (!service)
1009 return true;
1010 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551011 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241012 if (new_extension &&
1013 new_extension->is_hosted_app() &&
1014 new_extension->id() == extension_misc::kWebStoreAppId &&
1015 !service->process_map()->Contains(new_extension->id(),
1016 process_host->GetID())) {
1017 return false;
1018 }
1019
1020 return true;
1021}
1022
[email protected]9a60d1602013-09-11 04:09:121023bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1024 content::SiteInstance* site_instance, const GURL& url) {
1025 GURL from_url = site_instance->GetSiteURL();
1026 // Do not allow pages from the web or other extensions navigate to
1027 // non-web-accessible extension resources.
1028 if (url.SchemeIs(extensions::kExtensionScheme) &&
1029 (from_url.SchemeIsHTTPOrHTTPS() ||
1030 from_url.SchemeIs(extensions::kExtensionScheme))) {
1031 Profile* profile = Profile::FromBrowserContext(
1032 site_instance->GetProcess()->GetBrowserContext());
1033 ExtensionService* service =
1034 extensions::ExtensionSystem::Get(profile)->extension_service();
1035 if (!service)
1036 return true;
1037 const Extension* extension =
1038 service->extensions()->GetExtensionOrAppByURL(url);
1039 if (!extension)
1040 return true;
1041 const Extension* from_extension =
1042 service->extensions()->GetExtensionOrAppByURL(
1043 site_instance->GetSiteURL());
1044 if (from_extension && from_extension->id() == extension->id())
1045 return true;
1046
1047 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1048 extension, url.path()))
1049 return false;
1050 }
1051 return true;
1052}
1053
[email protected]2a5221b2011-09-27 23:07:311054bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301055 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311056 const GURL& site_url) {
1057 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301058 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521059 // This may be NULL during tests. In that case, just assume any site can
1060 // share any host.
1061 if (!profile)
1062 return true;
1063
[email protected]d43f99fe2013-04-03 00:20:141064 // Instant URLs should only be in the instant process and instant process
1065 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521066 InstantService* instant_service =
1067 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141068 if (instant_service) {
1069 bool is_instant_process = instant_service->IsInstantProcess(
1070 process_host->GetID());
1071 bool should_be_in_instant_process =
1072 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1073 if (is_instant_process || should_be_in_instant_process)
1074 return is_instant_process && should_be_in_instant_process;
1075 }
[email protected]c5dec6292013-01-25 04:54:521076
[email protected]d5bcd06f2013-04-21 08:07:241077#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301078 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1079 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1080 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241081#endif
[email protected]970c63e2013-03-07 00:25:301082
[email protected]06bdd2b2012-11-30 18:47:131083 ExtensionService* service =
1084 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461085 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311086
[email protected]ffa97602011-11-17 17:55:521087 // Don't allow the Task Manager to share a process with anything else.
1088 // Otherwise it can affect the renderers it is observing.
1089 // Note: we could create another RenderProcessHostPrivilege bucket for
1090 // this to allow multiple chrome://tasks instances to share, but that's
1091 // a very unlikely case without serious consequences.
1092 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1093 return false;
1094
[email protected]8d3132f62011-10-12 07:13:421095 // These may be NULL during tests. In that case, just assume any site can
1096 // share any host.
[email protected]6f371442011-11-09 06:45:461097 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311098 return true;
1099
[email protected]eec0b33c2011-12-05 22:09:451100 // Otherwise, just make sure the process privilege matches the privilege
1101 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571102 RenderProcessHostPrivilege privilege_required =
1103 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451104 return GetProcessPrivilege(process_host, process_map, service) ==
1105 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311106}
1107
[email protected]76411f412012-02-22 18:56:061108// This function is trying to limit the amount of processes used by extensions
1109// with background pages. It uses a globally set percentage of processes to
1110// run such extensions and if the limit is exceeded, it returns true, to
1111// indicate to the content module to group extensions together.
1112bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1113 content::BrowserContext* browser_context, const GURL& url) {
1114 // It has to be a valid URL for us to check for an extension.
1115 if (!url.is_valid())
1116 return false;
1117
1118 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191119 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131120 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061121 if (!service)
1122 return false;
1123
1124 // We have to have a valid extension with background page to proceed.
1125 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551126 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061127 if (!extension)
1128 return false;
[email protected]9367eabc2013-03-01 01:29:291129 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061130 return false;
1131
1132 std::set<int> process_ids;
1133 size_t max_process_count =
1134 content::RenderProcessHost::GetMaxRendererProcessCount();
1135
1136 // Go through all profiles to ensure we have total count of extension
1137 // processes containing background pages, otherwise one profile can
1138 // starve the other.
1139 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1140 GetLoadedProfiles();
1141 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031142 ExtensionProcessManager* epm =
1143 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321144 for (ExtensionProcessManager::const_iterator iter =
1145 epm->background_hosts().begin();
1146 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131147 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321148 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061149 }
1150 }
1151
1152 if (process_ids.size() >
1153 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1154 return true;
1155 }
1156
1157 return false;
1158}
1159
[email protected]6f371442011-11-09 06:45:461160void ChromeContentBrowserClient::SiteInstanceGotProcess(
1161 SiteInstance* site_instance) {
1162 CHECK(site_instance->HasProcess());
1163
1164 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021165 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521166 if (!profile)
1167 return;
1168
1169 // Remember the ID of the Instant process to signal the renderer process
1170 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031171 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321172 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521173 InstantService* instant_service =
1174 InstantServiceFactory::GetForProfile(profile);
1175 if (instant_service)
1176 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1177 }
1178
[email protected]d5bcd06f2013-04-21 08:07:241179#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301180 // We only expect there to be one signin process as we use process-per-site
1181 // for signin URLs. The signin process will be cleared from SigninManager
1182 // when the renderer is destroyed.
1183 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1184 SigninManager* signin_manager =
1185 SigninManagerFactory::GetForProfile(profile);
1186 if (signin_manager)
1187 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461188 BrowserThread::PostTask(
1189 BrowserThread::IO, FROM_HERE,
1190 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1191 extensions::ExtensionSystem::Get(profile)->info_map(),
1192 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301193 }
[email protected]d5bcd06f2013-04-21 08:07:241194#endif
[email protected]970c63e2013-03-07 00:25:301195
[email protected]06bdd2b2012-11-30 18:47:131196 ExtensionService* service =
1197 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461198 if (!service)
1199 return;
1200
[email protected]be9915fb2013-07-18 09:28:551201 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1202 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461203 if (!extension)
1204 return;
1205
[email protected]6bc04fd82011-12-04 02:29:351206 service->process_map()->Insert(extension->id(),
1207 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331208 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461209 BrowserThread::PostTask(
1210 BrowserThread::IO, FROM_HERE,
1211 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591212 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461213 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351214 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331215 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461216}
1217
1218void ChromeContentBrowserClient::SiteInstanceDeleting(
1219 SiteInstance* site_instance) {
1220 if (!site_instance->HasProcess())
1221 return;
1222
1223 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021224 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131225 ExtensionService* service =
1226 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461227 if (!service)
1228 return;
1229
[email protected]be9915fb2013-07-18 09:28:551230 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1231 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461232 if (!extension)
1233 return;
1234
[email protected]6bc04fd82011-12-04 02:29:351235 service->process_map()->Remove(extension->id(),
1236 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331237 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461238 BrowserThread::PostTask(
1239 BrowserThread::IO, FROM_HERE,
1240 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591241 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461242 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351243 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331244 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461245}
1246
[email protected]f05763972012-06-06 18:17:261247bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141248 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081249 const GURL& current_url,
1250 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261251 if (current_url.is_empty()) {
1252 // Always choose a new process when navigating to extension URLs. The
1253 // process grouping logic will combine all of a given extension's pages
1254 // into the same process.
[email protected]885c0e92012-11-13 20:27:421255 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261256 return true;
[email protected]e3daf3c2011-10-05 21:17:081257
[email protected]f05763972012-06-06 18:17:261258 return false;
1259 }
1260
1261 // Also, we must switch if one is an extension and the other is not the exact
1262 // same extension.
[email protected]885c0e92012-11-13 20:27:421263 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1264 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261265 if (current_url.GetOrigin() != new_url.GetOrigin())
1266 return true;
1267 }
1268
[email protected]e9841fbd2013-02-22 23:12:141269 // The checks below only matter if we can retrieve which extensions are
1270 // installed.
1271 Profile* profile =
1272 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1273 ExtensionService* service =
1274 extensions::ExtensionSystem::Get(profile)->extension_service();
1275 if (!service)
1276 return false;
1277
1278 // We must swap if the URL is for an extension and we are not using an
1279 // extension process.
1280 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551281 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141282 // Ignore all hosted apps except the Chrome Web Store, since they do not
1283 // require their own BrowsingInstance (e.g., postMessage is ok).
1284 if (new_extension &&
1285 new_extension->is_hosted_app() &&
1286 new_extension->id() != extension_misc::kWebStoreAppId)
1287 new_extension = NULL;
1288 if (new_extension &&
1289 site_instance->HasProcess() &&
1290 !service->process_map()->Contains(new_extension->id(),
1291 site_instance->GetProcess()->GetID()))
1292 return true;
1293
[email protected]f05763972012-06-06 18:17:261294 return false;
[email protected]e3daf3c2011-10-05 21:17:081295}
1296
[email protected]395045c2012-05-22 15:04:381297bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1298 content::ResourceContext* resource_context, const GURL& current_url,
1299 const GURL& new_url) {
1300 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1301 return extensions::CrossesExtensionProcessBoundary(
1302 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551303 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381304}
1305
[email protected]3d831992013-07-04 01:13:291306bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1307 return !url.SchemeIs(chrome::kChromeNativeScheme);
1308}
1309
[email protected]763ec4ca2011-04-29 15:48:121310std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1311 const std::string& alias_name) {
1312 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1313}
1314
[email protected]b80f68432011-05-02 17:22:301315void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1316 CommandLine* command_line, int child_process_id) {
[email protected]97425082013-07-16 03:10:071317#if defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301318 if (IsCrashReporterEnabled()) {
1319 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1320 child_process_logging::GetClientId());
1321 }
[email protected]97425082013-07-16 03:10:071322#elif defined(OS_POSIX)
1323 if (IsCrashReporterEnabled()) {
1324 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1325 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1326 }
1327
[email protected]b80f68432011-05-02 17:22:301328#endif // OS_MACOSX
1329
[email protected]f1933792011-06-14 00:49:341330 if (logging::DialogsAreSuppressed())
1331 command_line->AppendSwitch(switches::kNoErrorDialogs);
1332
[email protected]b80f68432011-05-02 17:22:301333 std::string process_type =
1334 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171335 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321336
[email protected]7c9b6f92013-09-10 18:11:351337 static const char* const kCommonSwitchNames[] = {
1338 switches::kChromeFrame,
1339 switches::kUserDataDir, // Make logs go to the right file.
1340 };
1341 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1342 arraysize(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:321343
[email protected]718eab62011-10-05 21:16:521344 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:301345#if defined(OS_CHROMEOS)
1346 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441347 browser_command_line.GetSwitchValueASCII(
1348 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301349 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441350 command_line->AppendSwitchASCII(
1351 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301352#endif
1353
[email protected]f3b1a082011-11-18 00:34:301354 content::RenderProcessHost* process =
1355 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371356 if (process) {
1357 Profile* profile = Profile::FromBrowserContext(
1358 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131359 ExtensionService* extension_service =
1360 extensions::ExtensionSystem::Get(profile)->extension_service();
1361 if (extension_service) {
1362 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001363 if (process_map && process_map->Contains(process->GetID()))
1364 command_line->AppendSwitch(switches::kExtensionProcess);
1365 }
[email protected]b80f68432011-05-02 17:22:301366
[email protected]a8d851f82011-12-21 00:32:371367 PrefService* prefs = profile->GetPrefs();
1368 // Currently this pref is only registered if applied via a policy.
1369 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1370 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1371 // Turn this policy into a command line switch.
1372 command_line->AppendSwitch(switches::kDisable3DAPIs);
1373 }
[email protected]718eab62011-10-05 21:16:521374
[email protected]a8d851f82011-12-21 00:32:371375 // Disable client-side phishing detection in the renderer if it is
1376 // disabled in the Profile preferences or the browser process.
1377 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1378 !g_browser_process->safe_browsing_detection_service()) {
1379 command_line->AppendSwitch(
1380 switches::kDisableClientSidePhishingDetection);
1381 }
[email protected]0045b0f42012-07-26 11:52:081382
1383 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211384 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521385
1386 InstantService* instant_service =
1387 InstantServiceFactory::GetForProfile(profile);
1388 if (instant_service &&
1389 instant_service->IsInstantProcess(process->GetID()))
1390 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301391
[email protected]d5bcd06f2013-04-21 08:07:241392#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301393 SigninManager* signin_manager =
1394 SigninManagerFactory::GetForProfile(profile);
1395 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1396 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241397#endif
[email protected]47c7ec82012-01-18 03:29:211398 }
[email protected]4287a3d2011-06-13 23:56:511399
[email protected]16dc42452013-04-09 04:37:191400 if (message_center::IsRichNotificationEnabled())
1401 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191402
[email protected]47c7ec82012-01-18 03:29:211403 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511404 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171405 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481406 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171407 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]49d9b142013-07-19 08:50:271408 extensions::switches::kAllowLegacyExtensionManifests,
1409 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511410 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271411 extensions::switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511412 switches::kAllowHTTPBackgroundPage,
[email protected]9d450492013-06-13 23:08:371413 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1414 // to browser.
1415 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511416 switches::kAppsCheckoutURL,
1417 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311418 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511419 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501420 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531421 switches::kDisableExtensionsResourceWhitelist,
[email protected]83c85262013-08-22 21:13:461422 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111423 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531424 switches::kEnableAdview,
1425 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441426 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211427 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511428 switches::kEnableIPCFuzzing,
1429 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451430 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481431 switches::kEnablePasswordGeneration,
[email protected]4287a3d2011-06-13 23:56:511432 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511433 switches::kMemoryProfiling,
1434 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371435 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371436 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511437 switches::kPpapiFlashArgs,
1438 switches::kPpapiFlashInProcess,
1439 switches::kPpapiFlashPath,
1440 switches::kPpapiFlashVersion,
1441 switches::kProfilingAtStart,
1442 switches::kProfilingFile,
1443 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371444 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511445 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291446 switches::kSpdyProxyAuthOrigin,
[email protected]cbcf3b5b2013-08-06 17:14:191447 switches::kTranslateSecurityOrigin,
[email protected]a446534d2012-02-09 00:07:381448 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511449 };
1450
1451 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1452 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171453 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381454 static const char* const kSwitchNames[] = {
[email protected]c8d02992013-07-31 22:16:511455 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271456 extensions::switches::kExtensionsOnChromeURLs,
[email protected]eb653f82012-05-24 02:31:351457 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381458 switches::kWhitelistedExtensionID,
1459 };
1460
1461 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1462 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511463 } else if (process_type == switches::kPluginProcess) {
1464 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441465#if defined(OS_CHROMEOS)
1466 chromeos::switches::kLoginProfile,
1467#endif
[email protected]4287a3d2011-06-13 23:56:511468 switches::kMemoryProfiling,
1469 switches::kSilentDumpOnDCHECK,
[email protected]4287a3d2011-06-13 23:56:511470 };
1471
1472 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1473 arraysize(kSwitchNames));
1474 } else if (process_type == switches::kZygoteProcess) {
1475 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511476 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501477 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511478 switches::kPpapiFlashInProcess,
1479 switches::kPpapiFlashPath,
1480 switches::kPpapiFlashVersion,
1481 };
1482
1483 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1484 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111485 } else if (process_type == switches::kGpuProcess) {
1486 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1487 // because GPU is expected to be unreliable.
1488 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1489 !command_line->HasSwitch(switches::kDisableBreakpad))
1490 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301491 }
[email protected]6f08af82011-09-15 01:19:031492
1493 // The command line switch kEnableBenchmarking needs to be specified along
1494 // with the kEnableStatsTable switch to ensure that the stats table global
1495 // is initialized correctly.
1496 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1497 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301498}
1499
1500std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431501 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351502 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301503 return g_browser_process->GetApplicationLocale();
1504}
1505
[email protected]597a867b2011-11-18 18:31:201506std::string ChromeContentBrowserClient::GetAcceptLangs(
1507 content::BrowserContext* context) {
1508 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371509 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081510}
1511
[email protected]9ec0f452012-05-31 15:58:531512gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221513 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531514 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081515}
1516
[email protected]a2176792011-05-08 19:30:491517bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091518 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191519 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201520 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201522 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051523 return io_data->GetCookieSettings()->
1524 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491525}
1526
[email protected]ed24fad2011-05-10 22:44:011527bool ChromeContentBrowserClient::AllowGetCookie(
1528 const GURL& url,
1529 const GURL& first_party,
1530 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201531 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011532 int render_process_id,
1533 int render_view_id) {
1534 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 bool allow = io_data->GetCookieSettings()->
1537 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011538
[email protected]8093a542011-05-13 07:29:321539 BrowserThread::PostTask(
1540 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031541 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431542 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011543 return allow;
1544}
1545
1546bool ChromeContentBrowserClient::AllowSetCookie(
1547 const GURL& url,
1548 const GURL& first_party,
1549 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201550 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011551 int render_process_id,
1552 int render_view_id,
1553 net::CookieOptions* options) {
1554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201555 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051556 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1557 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1558
[email protected]8093a542011-05-13 07:29:321559 BrowserThread::PostTask(
1560 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031561 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431562 render_view_id, url, first_party, cookie_line, *options,
1563 !allow));
[email protected]ed24fad2011-05-10 22:44:011564 return allow;
1565}
1566
[email protected]d5a19162011-06-30 18:51:541567bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201568 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201570 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431571 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1572 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261573
[email protected]bf510ed2012-06-05 08:31:431574 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1575 // Could we even support per-origin settings?
1576 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541577}
1578
[email protected]5c5a88e2011-11-12 00:45:351579bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351580 const GURL& url,
1581 const string16& name,
1582 const string16& display_name,
1583 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201584 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481585 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351586 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201587 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351588 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1589 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1590
[email protected]62151052012-02-01 18:40:481591 // Record access to database for potential display in UI.
1592 std::vector<std::pair<int, int> >::const_iterator i;
1593 for (i = render_views.begin(); i != render_views.end(); ++i) {
1594 BrowserThread::PostTask(
1595 BrowserThread::UI, FROM_HERE,
1596 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1597 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351598 }
1599
1600 return allow;
1601}
1602
1603bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351604 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201605 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481606 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201608 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351609 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1610 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1611
[email protected]62151052012-02-01 18:40:481612 // Record access to file system for potential display in UI.
1613 std::vector<std::pair<int, int> >::const_iterator i;
1614 for (i = render_views.begin(); i != render_views.end(); ++i) {
1615 BrowserThread::PostTask(
1616 BrowserThread::UI, FROM_HERE,
1617 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1618 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351619 }
1620
1621 return allow;
1622}
1623
[email protected]7c5ff9a2012-03-02 07:42:491624bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1625 const GURL& url,
1626 const string16& name,
1627 content::ResourceContext* context,
1628 const std::vector<std::pair<int, int> >& render_views) {
1629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1630 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1631 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1632 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1633
1634 // Record access to IndexedDB for potential display in UI.
1635 std::vector<std::pair<int, int> >::const_iterator i;
1636 for (i = render_views.begin(); i != render_views.end(); ++i) {
1637 BrowserThread::PostTask(
1638 BrowserThread::UI, FROM_HERE,
1639 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1640 i->first, i->second, url, name, !allow));
1641 }
1642
1643 return allow;
1644}
1645
[email protected]33ad6ce92013-08-27 14:39:081646net::URLRequestContext*
1647ChromeContentBrowserClient::OverrideRequestContextForURL(
1648 const GURL& url, content::ResourceContext* context) {
1649 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1650 if (url.SchemeIs(extensions::kExtensionScheme)) {
1651 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1652 return io_data->extensions_request_context();
1653 }
1654
1655 return NULL;
1656}
1657
[email protected]317f96c92011-05-31 06:53:411658QuotaPermissionContext*
1659ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1660 return new ChromeQuotaPermissionContext();
1661}
1662
[email protected]848dd042011-06-04 18:24:031663void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171664 int render_process_id,
1665 int render_view_id,
1666 int cert_error,
1667 const net::SSLInfo& ssl_info,
1668 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021669 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031670 bool overridable,
[email protected]d9be47702012-05-16 03:41:221671 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171672 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001673 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021674 if (resource_type != ResourceType::MAIN_FRAME) {
1675 // A sub-resource has a certificate error. The user doesn't really
1676 // have a context for making the right decision, so block the
1677 // request hard, without an info bar to allow showing the insecure
1678 // content.
[email protected]8c965c22013-05-23 19:28:001679 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021680 return;
1681 }
1682
[email protected]f9034cf2011-07-21 12:43:411683 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131684 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171685 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411686 if (!tab) {
1687 NOTREACHED();
1688 return;
1689 }
1690 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501691 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301692 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011693 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1694 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411695 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171696 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411697 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001698 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411699 return;
1700 }
1701 }
1702
[email protected]1e87df32012-09-12 04:53:191703#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231704 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1705 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1706 if (captive_portal_tab_helper)
1707 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191708#endif
1709
[email protected]f9034cf2011-07-21 12:43:411710 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221711 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1712 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031713}
1714
[email protected]c99c442e2011-08-24 11:37:301715void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451716 int render_process_id,
1717 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401718 const net::HttpNetworkSession* network_session,
1719 net::SSLCertRequestInfo* cert_request_info,
1720 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131721 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451722 render_process_id, render_view_id);
1723 if (!tab) {
1724 NOTREACHED();
1725 return;
1726 }
1727
[email protected]6786bf402011-12-03 15:19:451728 GURL requesting_url("https://" + cert_request_info->host_and_port);
1729 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1730 << cert_request_info->host_and_port;
1731
[email protected]627e0512011-12-21 22:55:301732 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451733 scoped_ptr<Value> filter(
1734 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1735 requesting_url,
1736 requesting_url,
1737 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1738 std::string(), NULL));
1739
1740 if (filter.get()) {
1741 // Try to automatically select a client certificate.
1742 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1743 DictionaryValue* filter_dict =
1744 static_cast<DictionaryValue*>(filter.get());
1745
1746 const std::vector<scoped_refptr<net::X509Certificate> >&
1747 all_client_certs = cert_request_info->client_certs;
1748 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091749 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451750 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091751 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451752 return;
1753 }
1754 }
1755 } else {
1756 NOTREACHED();
1757 }
1758 }
1759
[email protected]11feec322012-09-18 03:58:521760 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1761 if (!ssl_tab_helper) {
1762 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451763 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141764 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401765 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451766 return;
1767 }
[email protected]11feec322012-09-18 03:58:521768 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401769 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451770}
1771
[email protected]3b455502012-12-11 18:22:581772void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451773 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581774 net::CertificateMimeType cert_type,
1775 const void* cert_data,
1776 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451777 int render_process_id,
1778 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581779 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1780 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451781}
1782
[email protected]dc73a7b2012-03-25 15:27:181783content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561784 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181785}
1786
[email protected]941623e2011-06-07 23:06:041787void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1788 const GURL& source_origin,
1789 int callback_context,
1790 int render_process_id,
1791 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111792#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021793 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1794 WebContents* contents =
1795 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1796 if (!contents) {
[email protected]941623e2011-06-07 23:06:041797 NOTREACHED();
1798 return;
1799 }
1800
[email protected]d0d9c3ee2012-06-19 03:07:021801 // Skip showing the infobar if the request comes from an extension, and that
1802 // extension has the 'notify' permission. (If the extension does not have the
1803 // permission, the user will still be prompted.)
1804 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011805 ExtensionInfoMap* extension_info_map =
1806 extensions::ExtensionSystem::Get(profile)->info_map();
1807 DesktopNotificationService* notification_service =
1808 DesktopNotificationServiceFactory::GetForProfile(profile);
1809 const Extension* extension = NULL;
1810 if (extension_info_map) {
1811 ExtensionSet extensions;
1812 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1813 source_origin, render_process_id,
1814 extensions::APIPermission::kNotification, &extensions);
1815 for (ExtensionSet::const_iterator iter = extensions.begin();
1816 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381817 if (notification_service->IsNotifierEnabled(NotifierId(
1818 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361819 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011820 break;
1821 }
1822 }
1823 }
[email protected]eb4832a2012-12-08 01:57:521824 RenderViewHost* rvh =
1825 RenderViewHost::FromID(render_process_id, render_view_id);
1826 if (IsExtensionWithPermissionOrSuggestInConsole(
1827 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021828 if (rvh)
1829 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1830 return;
1831 }
1832
[email protected]c7cd5942013-04-30 03:31:011833 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021834 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111835#else
1836 NOTIMPLEMENTED();
1837#endif
[email protected]941623e2011-06-07 23:06:041838}
1839
1840WebKit::WebNotificationPresenter::Permission
1841 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021842 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201843 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021844 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111845#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041846 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481847 // Sometimes a notification may be invoked during the shutdown.
1848 // See http://crbug.com/256638
1849 if (browser_shutdown::IsTryingToQuit())
1850 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
1851
[email protected]df02aca2012-02-09 21:03:201852 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041853
[email protected]c7cd5942013-04-30 03:31:011854 DesktopNotificationService* notification_service =
1855 io_data->GetNotificationService();
1856 if (notification_service) {
1857 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1858 ExtensionSet extensions;
1859 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1860 source_origin, render_process_id,
1861 extensions::APIPermission::kNotification, &extensions);
1862 for (ExtensionSet::const_iterator iter = extensions.begin();
1863 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381864 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
1865 if (notification_service->IsNotifierEnabled(notifier_id))
[email protected]c7cd5942013-04-30 03:31:011866 return WebKit::WebNotificationPresenter::PermissionAllowed;
1867 }
1868
1869 return notification_service->HasPermission(source_origin);
1870 }
1871
1872 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111873#else
1874 return WebKit::WebNotificationPresenter::PermissionAllowed;
1875#endif
[email protected]941623e2011-06-07 23:06:041876}
1877
1878void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171879 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041880 int render_process_id,
1881 int render_view_id,
1882 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111883#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041884 RenderViewHost* rvh = RenderViewHost::FromID(
1885 render_process_id, render_view_id);
1886 if (!rvh) {
1887 NOTREACHED();
1888 return;
1889 }
1890
[email protected]9f76c1e2012-03-05 15:15:581891 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301892 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041893 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371894 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041895 service->ShowDesktopNotification(
1896 params, render_process_id, render_view_id,
1897 worker ? DesktopNotificationService::WorkerNotification :
1898 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111899#else
1900 NOTIMPLEMENTED();
1901#endif
[email protected]941623e2011-06-07 23:06:041902}
1903
1904void ChromeContentBrowserClient::CancelDesktopNotification(
1905 int render_process_id,
1906 int render_view_id,
1907 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111908#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041909 RenderViewHost* rvh = RenderViewHost::FromID(
1910 render_process_id, render_view_id);
1911 if (!rvh) {
1912 NOTREACHED();
1913 return;
1914 }
1915
[email protected]9f76c1e2012-03-05 15:15:581916 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301917 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041918 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371919 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041920 service->CancelDesktopNotification(
1921 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111922#else
1923 NOTIMPLEMENTED();
1924#endif
[email protected]941623e2011-06-07 23:06:041925}
1926
[email protected]9f3fba52011-06-08 20:37:191927bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351928 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:571929 const GURL& opener_top_level_frame_url,
[email protected]34eec7ffe32011-11-02 23:49:021930 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191931 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:231932 const GURL& target_url,
1933 const content::Referrer& referrer,
1934 WindowOpenDisposition disposition,
1935 const WebWindowFeatures& features,
1936 bool user_gesture,
1937 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:201938 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011939 int render_process_id,
[email protected]190e5e22013-07-27 05:59:231940 bool is_guest,
1941 int opener_id,
[email protected]03b6d552012-03-29 04:03:011942 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191943 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011944
1945 *no_javascript_access = false;
1946
[email protected]5e5f55e262c52013-09-12 00:27:191947 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1948 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1949
[email protected]9f3fba52011-06-08 20:37:191950 // If the opener is trying to create a background window but doesn't have
1951 // the appropriate permission, fail the attempt.
[email protected]6940eef82013-09-11 11:58:411952 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]03b6d552012-03-29 04:03:011953 if (!map->SecurityOriginHasAPIPermission(
1954 source_origin,
1955 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061956 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011957 return false;
1958 }
1959
[email protected]7b54ca02012-03-02 18:06:531960 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1961 // return a recently installed Extension even if this CanCreateWindow call
1962 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011963 // because the permission check above would have caused an early return
1964 // already. We must use the full URL to find hosted apps, though, and not
1965 // just the origin.
[email protected]be9915fb2013-07-18 09:28:551966 const Extension* extension =
1967 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:291968 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011969 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:231970
1971 return true;
[email protected]9f3fba52011-06-08 20:37:191972 }
[email protected]056efdc2013-04-06 00:14:531973
1974 // No new browser window (popup or tab) in app mode.
1975 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1976 chrome::IsRunningInForcedAppMode()) {
1977 return false;
1978 }
1979
[email protected]d2bac6b2013-08-13 03:42:361980 if (g_browser_process->prerender_tracker() &&
1981 g_browser_process->prerender_tracker()->TryCancelOnIOThread(
1982 render_process_id,
1983 opener_id,
1984 prerender::FINAL_STATUS_CREATE_NEW_WINDOW)) {
1985 return false;
1986 }
1987
[email protected]190e5e22013-07-27 05:59:231988 if (is_guest)
1989 return true;
1990
[email protected]5e5f55e262c52013-09-12 00:27:191991 // Exempt extension processes from popup blocking.
1992 if (map->process_map().Contains(render_process_id))
1993 return true;
1994
[email protected]190e5e22013-07-27 05:59:231995 HostContentSettingsMap* content_settings =
1996 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
[email protected]916615b2013-09-11 18:19:441997 BlockedWindowParams blocked_params(target_url,
1998 referrer,
1999 disposition,
2000 features,
2001 user_gesture,
2002 opener_suppressed,
2003 render_process_id,
2004 opener_id);
[email protected]190e5e22013-07-27 05:59:232005
[email protected]7f53dff2013-08-05 10:45:502006 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch(
2007 switches::kDisablePopupBlocking)) {
[email protected]931bc922013-09-11 21:42:572008 if (content_settings->GetContentSetting(opener_top_level_frame_url,
2009 opener_top_level_frame_url,
[email protected]190e5e22013-07-27 05:59:232010 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]916615b2013-09-11 18:19:442011 std::string()) !=
[email protected]190e5e22013-07-27 05:59:232012 CONTENT_SETTING_ALLOW) {
[email protected]916615b2013-09-11 18:19:442013 BrowserThread::PostTask(BrowserThread::UI,
2014 FROM_HERE,
2015 base::Bind(&HandleBlockedPopupOnUIThread,
2016 blocked_params));
2017 return false;
[email protected]190e5e22013-07-27 05:59:232018 }
[email protected]916615b2013-09-11 18:19:442019 }
[email protected]190e5e22013-07-27 05:59:232020
[email protected]916615b2013-09-11 18:19:442021#if defined(OS_ANDROID)
2022 if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) {
[email protected]190e5e22013-07-27 05:59:232023 BrowserThread::PostTask(BrowserThread::UI,
2024 FROM_HERE,
[email protected]916615b2013-09-11 18:19:442025 base::Bind(&HandleSingleTabModeBlockOnUIThread,
2026 blocked_params));
[email protected]190e5e22013-07-27 05:59:232027 return false;
2028 }
[email protected]916615b2013-09-11 18:19:442029#endif
[email protected]190e5e22013-07-27 05:59:232030
[email protected]9f3fba52011-06-08 20:37:192031 return true;
2032}
2033
2034std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202035 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192036 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2037 // Check if it's an extension-created worker, in which case we want to use
2038 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202039 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192040 const Extension* extension =
2041 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2042 return extension ? extension->name() : std::string();
2043}
2044
[email protected]99907362012-01-11 05:41:402045void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2046 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172047}
2048
[email protected]7a06d282013-05-03 04:39:332049// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022050content::SpeechRecognitionManagerDelegate*
2051 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002052#if defined(ENABLE_INPUT_SPEECH)
2053 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322054#else
[email protected]855e18b2013-07-08 21:02:002055 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2056 // need the base delegate without the bubble UI.
2057 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322058#endif
[email protected]66cfec62012-02-24 17:57:512059}
2060
[email protected]ae6e9912011-07-27 01:18:282061net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2062 return g_browser_process->net_log();
2063}
2064
[email protected]32538d92011-08-25 00:09:232065AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2066 return new ChromeAccessTokenStore();
2067}
2068
[email protected]dbae6b02011-06-29 23:51:412069bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012070 return true;
[email protected]dbae6b02011-06-29 23:51:412071}
2072
[email protected]64d69de42012-02-06 00:19:542073void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322074 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062075 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582076 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062077 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062078
[email protected]f3986f82012-01-03 20:00:062079 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542080 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062081 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542082 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062083 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542084 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062085 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542086 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062087 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542088 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062089 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542090 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032091 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2092 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:062093
[email protected]64d69de42012-02-06 00:19:542094 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402095 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542096 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402097 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542098 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402099 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542100 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402101 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062102
[email protected]ddf72142012-05-22 04:52:402103 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062104
[email protected]64d69de42012-02-06 00:19:542105 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402106 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542107 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062108 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542109 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062110 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2111 const DictionaryValue* inspector_settings =
2112 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2113 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182114 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2115 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062116 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182117 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542118 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182119 std::make_pair(iter.key(), value));
2120 }
[email protected]f3986f82012-01-03 20:00:062121 }
2122 }
[email protected]64d69de42012-02-06 00:19:542123 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062124
[email protected]ddf72142012-05-22 04:52:402125 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542126 web_prefs->javascript_enabled = false;
2127 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2128 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402129 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542130 web_prefs->plugins_enabled = false;
2131 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2132 web_prefs->java_enabled = false;
2133 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402134 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062135
[email protected]64d69de42012-02-06 00:19:542136 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2137 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062138
[email protected]64d69de42012-02-06 00:19:542139 web_prefs->memory_info_enabled =
2140 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2141 web_prefs->allow_displaying_insecure_content =
2142 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2143 web_prefs->allow_running_insecure_content =
2144 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322145#if defined(OS_ANDROID)
2146 web_prefs->font_scale_factor =
2147 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2148 web_prefs->force_enable_zoom =
2149 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2150#endif
[email protected]5c915252013-05-07 13:15:392151
[email protected]af4256d52013-06-04 20:39:072152#if defined(OS_ANDROID)
2153 web_prefs->password_echo_enabled =
2154 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2155#else
[email protected]9d06d88d2012-02-23 22:37:082156 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072157#endif
2158
[email protected]5c915252013-05-07 13:15:392159#if defined(OS_CHROMEOS)
2160 // Enable password echo during OOBE when keyboard driven flag is set.
2161 if (chromeos::UserManager::IsInitialized() &&
2162 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
[email protected]c94ac692013-07-27 00:50:102163 !chromeos::StartupUtils::IsOobeCompleted() &&
2164 chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation()) {
2165 web_prefs->password_echo_enabled = true;
[email protected]5c915252013-05-07 13:15:392166 }
2167#endif
[email protected]f3986f82012-01-03 20:00:062168
[email protected]46f8e742013-05-03 18:37:142169#if defined(OS_ANDROID)
2170 web_prefs->user_style_sheet_enabled = false;
2171#else
[email protected]64d69de42012-02-06 00:19:542172 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152173 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362174 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152175 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542176 web_prefs->user_style_sheet_enabled = true;
2177 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152178 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542179 } else {
2180 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062181 }
[email protected]46f8e742013-05-03 18:37:142182#endif
[email protected]f3986f82012-01-03 20:00:062183
[email protected]cfadadd2013-04-03 04:43:022184 web_prefs->asynchronous_spell_checking_enabled = true;
2185 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572186
[email protected]64d69de42012-02-06 00:19:542187 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062188 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542189 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062190 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542191 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062192 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2193
2194 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542195 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062196 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542197 web_prefs->default_encoding);
2198 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402199 prefs->ClearPref(prefs::kDefaultCharset);
2200 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062201 }
[email protected]64d69de42012-02-06 00:19:542202 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062203
[email protected]299d7f12012-05-23 05:31:152204 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232205 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132206 ExtensionService* service =
2207 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062208 if (service) {
[email protected]1bc28312012-11-08 08:31:532209 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2210 const Extension* extension = service->extensions()->GetByID(url.host());
2211 // Ensure that we are only granting extension preferences to URLs with
2212 // the correct scheme. Without this check, chrome-guest:// schemes used by
2213 // webview tags as well as hosts that happen to match the id of an
2214 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422215 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532216 extension_webkit_preferences::SetPreferences(
2217 extension, view_type, web_prefs);
2218 }
[email protected]f3986f82012-01-03 20:00:062219 }
2220
[email protected]cb2edf22013-04-01 20:25:232221 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542222 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232223 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062224 // Disable all kinds of acceleration for background pages.
2225 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542226 web_prefs->force_compositing_mode = false;
2227 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062228 }
[email protected]2e21fe292012-03-02 22:52:322229
2230#if defined(FILE_MANAGER_EXTENSION)
2231 // Override the default of suppressing HW compositing for WebUI pages for the
2232 // file manager, which is implemented using WebUI but wants HW acceleration
2233 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532234 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]2de96a52013-08-14 01:18:092235 url.host() == file_manager::kFileManagerAppId) {
[email protected]2e21fe292012-03-02 22:52:322236 web_prefs->accelerated_compositing_enabled = true;
2237 web_prefs->accelerated_2d_canvas_enabled = true;
2238 }
2239#endif
[email protected]181a95ee2011-07-12 19:26:362240}
2241
2242void ChromeContentBrowserClient::UpdateInspectorSetting(
2243 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062244 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582245 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062246 DictionaryPrefUpdate update(
2247 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2248 prefs::kWebKitInspectorSettings);
2249 DictionaryValue* inspector_settings = update.Get();
2250 inspector_settings->SetWithoutPathExpansion(key,
2251 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362252}
2253
[email protected]b8148ac2011-07-13 22:03:252254void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2255 BrowserURLHandler* handler) {
2256 // Add the default URL handlers.
2257 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2258 BrowserURLHandler::null_handler());
2259 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2260 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2261
[email protected]b3adbd02011-11-30 22:23:272262 // about: handler. Must come before chrome: handler, since it will
2263 // rewrite about: urls to chrome: URLs and then expect chrome: to
2264 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252265 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2266 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032267
2268 // Handler to rewrite chrome://newtab for InstantExtended.
2269 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2270 &chrome::HandleNewTabURLReverseRewrite);
2271
[email protected]b8148ac2011-07-13 22:03:252272 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242273 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252274}
2275
2276void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372277 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582278 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472279 BrowsingDataRemover* remover =
2280 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552281 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2282 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252283 // BrowsingDataRemover takes care of deleting itself when done.
2284}
2285
2286void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372287 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582288 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472289 BrowsingDataRemover* remover =
2290 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232291 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552292 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252293 // BrowsingDataRemover takes care of deleting itself when done.
2294}
2295
[email protected]650b2d52013-02-10 03:41:452296base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:492297 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:322298}
2299
[email protected]c9b6eb62011-10-18 20:49:392300std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2301 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2302}
2303
[email protected]b7631cc2012-09-15 05:08:382304void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2305 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542306#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382307 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2308 scoped_ptr<ppapi::host::HostFactory>(
2309 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542310#endif
[email protected]b7631cc2012-09-15 05:08:382311}
2312
[email protected]0c7193742012-11-07 19:05:032313content::BrowserPpapiHost*
2314 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2315 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132316 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032317 while (!iter.Done()) {
2318 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2319 if (host->process() &&
2320 host->process()->GetData().id == plugin_process_id) {
2321 // Found the plugin.
2322 return host->browser_ppapi_host();
2323 }
2324 ++iter;
2325 }
2326 return NULL;
2327}
2328
[email protected]7b38b192013-03-23 18:39:312329bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2330 content::BrowserContext* browser_context, const GURL& site_url) {
2331 if (CommandLine::ForCurrentProcess()->HasSwitch(
2332 switches::kEnableBrowserPluginForAllViewTypes))
2333 return true;
2334
2335 Profile* profile = Profile::FromBrowserContext(browser_context);
2336 ExtensionService* service =
2337 extensions::ExtensionSystem::Get(profile)->extension_service();
2338 if (!service)
2339 return false;
2340
[email protected]be9915fb2013-07-18 09:28:552341 const Extension* extension =
2342 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312343 if (!extension)
2344 return false;
2345
[email protected]c2d2f102013-04-29 16:42:582346 return extension->HasAPIPermission(APIPermission::kWebView) ||
2347 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312348}
2349
[email protected]38cd8f7f2012-06-15 22:06:072350bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582351 content::BrowserContext* browser_context,
2352 const GURL& url,
[email protected]dda54822013-06-15 01:26:392353 bool private_api,
[email protected]157cc902012-11-02 06:31:582354 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402355#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372356 Profile* profile = Profile::FromBrowserContext(browser_context);
2357 const ExtensionSet* extension_set = NULL;
2358 if (profile) {
2359 extension_set = extensions::ExtensionSystem::Get(profile)->
2360 extension_service()->extensions();
2361 }
[email protected]dda54822013-06-15 01:26:392362
2363 if (private_api) {
2364 // Access to private socket APIs is controlled by the whitelist.
2365 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2366 allowed_socket_origins_)) {
2367 return true;
2368 }
2369 } else {
2370 // Access to public socket APIs is controlled by extension permissions.
2371 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2372 extension_set) {
2373 const Extension* extension = extension_set->GetByID(url.host());
2374 if (extension) {
2375 extensions::SocketPermission::CheckParam check_params(
2376 params.type, params.host, params.port);
2377 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2378 extension, extensions::APIPermission::kSocket, &check_params)) {
2379 return true;
2380 }
2381 }
2382 }
2383 }
2384
2385 // Allow both public and private APIs if the command line says so.
2386 return IsHostAllowedByCommandLine(url, extension_set,
2387 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402388#else
[email protected]a658d452012-03-02 12:45:292389 return false;
[email protected]93f72062013-05-29 20:29:402390#endif
[email protected]e461da2f2012-02-16 19:06:402391}
2392
[email protected]a28e3302013-02-03 03:50:432393ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2394 WebContents* web_contents) {
2395 return new ChromeSelectFilePolicy(web_contents);
2396}
2397
[email protected]7d9424702013-04-14 13:14:162398void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2399 std::vector<std::string>* additional_allowed_schemes) {
2400 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2401 additional_allowed_schemes);
2402 additional_allowed_schemes->push_back(kChromeUIScheme);
2403 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2404}
2405
[email protected]f19bbf62013-07-09 01:22:322406void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312407 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532408 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322409 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532410#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032411 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322412 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032413 storage_partition_path,
2414 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322415 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532416#endif
[email protected]b40015c2013-06-26 08:13:312417#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312418 fileapi::ExternalMountPoints* external_mount_points =
2419 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312420 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322421 chromeos::FileSystemBackend* backend =
2422 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312423 new drive::FileSystemBackendDelegate(browser_context),
2424 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312425 external_mount_points,
2426 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322427 backend->AddSystemMountPoints();
2428 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2429 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312430#endif
[email protected]445b7db2013-08-02 04:58:272431
[email protected]e86e2be2013-08-30 11:20:392432 additional_backends->push_back(
2433 new sync_file_system::SyncFileSystemBackend(
2434 Profile::FromBrowserContext(browser_context)));
[email protected]02250952013-04-24 23:52:532435}
2436
[email protected]e60c0232011-11-11 19:56:352437#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182438void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2439 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382440 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082441 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392442#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452443 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392444 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2445 DCHECK(!data_path.empty());
2446
2447 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452448 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392449 data_path.AppendASCII("chrome_100_percent.pak");
[email protected]5db2b7492013-08-23 05:33:092450 base::PlatformFile f =
2451 base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
[email protected]29699c22012-10-03 23:57:392452 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372453 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392454 FileDescriptor(f, true)));
2455
2456 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452457 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392458 GetLocaleFilePath(locale, false);
2459 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2460 DCHECK(f != base::kInvalidPlatformFileValue);
2461 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2462 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382463
[email protected]650b2d52013-02-10 03:41:452464 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372465 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2466 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2467 DCHECK(f != base::kInvalidPlatformFileValue);
2468 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2469 FileDescriptor(f, true)));
2470
[email protected]82174aa2013-01-22 21:53:432471 if (IsCrashReporterEnabled()) {
2472 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2473 if (f == base::kInvalidPlatformFileValue) {
2474 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2475 "be disabled for this process.";
2476 } else {
2477 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2478 FileDescriptor(f, true)));
2479 }
[email protected]40da3e0c2012-10-24 22:03:382480 }
[email protected]40da3e0c2012-10-24 22:03:382481
2482#else
2483 int crash_signal_fd = GetCrashSignalFD(command_line);
2484 if (crash_signal_fd >= 0) {
2485 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2486 FileDescriptor(crash_signal_fd,
2487 false)));
2488 }
[email protected]29699c22012-10-03 23:57:392489#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302490}
[email protected]e60c0232011-11-11 19:56:352491#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302492
[email protected]4a65826d2011-08-25 16:04:012493#if defined(OS_WIN)
2494const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2495 return chrome::kBrowserResourcesDll;
2496}
[email protected]34f48682013-03-20 00:30:182497
2498void ChromeContentBrowserClient::PreSpawnRenderer(
2499 sandbox::TargetPolicy* policy,
2500 bool* success) {
2501 // This code is duplicated in nacl_exe_win_64.cc.
2502 // Allow the server side of a pipe restricted to the "chrome.nacl."
2503 // namespace so that it cannot impersonate other system or other chrome
2504 // service pipes.
2505 sandbox::ResultCode result = policy->AddRule(
2506 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2507 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2508 L"\\\\.\\pipe\\chrome.nacl.*");
2509 if (result != sandbox::SBOX_ALL_OK) {
2510 *success = false;
2511 return;
2512 }
2513
2514 // Renderers need to send named pipe handles and shared memory
2515 // segment handles to NaCl loader processes.
2516 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2517 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2518 L"File");
2519 if (result != sandbox::SBOX_ALL_OK) {
2520 *success = false;
2521 return;
2522 }
2523}
[email protected]4a65826d2011-08-25 16:04:012524#endif
2525
[email protected]37a72af2011-06-13 05:42:012526#if defined(USE_NSS)
2527crypto::CryptoModuleBlockingPasswordDelegate*
2528 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2529 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292530 return chrome::NewCryptoModuleBlockingDialogDelegate(
2531 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012532}
2533#endif
2534
[email protected]d977f9c2011-03-14 16:10:262535} // namespace chrome