blob: cc25256fd186c80dd54aad7c7a644b3ab181c0ae [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]eabbfb12013-04-05 23:28:3513#include "base/lazy_instance.h"
[email protected]29699c22012-10-03 23:57:3914#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5715#include "base/prefs/pref_service.h"
[email protected]e7463412013-06-10 22:53:4616#include "base/strings/string_number_conversions.h"
[email protected]135cb802013-06-09 16:44:2017#include "base/strings/utf_string_conversions.h"
[email protected]30a306f42013-06-10 03:09:0318#include "base/threading/sequenced_worker_pool.h"
[email protected]b80f68432011-05-02 17:22:3019#include "chrome/app/breakpad_mac.h"
[email protected]056efdc2013-04-06 00:14:5320#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]b8148ac2011-07-13 22:03:2521#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3022#include "chrome/browser/browser_process.h"
[email protected]5c129792013-07-10 02:08:4823#include "chrome/browser/browser_shutdown.h"
[email protected]b0cb5e82012-07-19 19:22:4724#include "chrome/browser/browsing_data/browsing_data_helper.h"
25#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1226#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4127#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4128#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5629#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0530#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4531#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3232#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0833#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4934#include "chrome/browser/download/download_prefs.h"
[email protected]2b33dcd02012-03-18 01:34:1635#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]1deace22013-05-22 06:14:4636#include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
[email protected]76411f412012-02-22 18:56:0637#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0438#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3339#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2640#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0841#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2542#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0643#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5244#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2345#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1246#include "chrome/browser/google/google_util.h"
[email protected]0533cc6d2013-06-27 22:44:0547#include "chrome/browser/guestview/adview/adview_guest.h"
48#include "chrome/browser/guestview/guestview_constants.h"
49#include "chrome/browser/guestview/webview/webview_guest.h"
[email protected]11158e2d2013-02-01 02:31:5650#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0451#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]01e59752013-06-18 00:17:3552#include "chrome/browser/nacl_host/nacl_host_message_filter.h"
[email protected]0c7193742012-11-07 19:05:0353#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2854#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0455#include "chrome/browser/notifications/desktop_notification_service.h"
56#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4257#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5658#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0659#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]190e5e22013-07-27 05:59:2360#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4161#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5062#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0763#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4164#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1465#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0366#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1467#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3268#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0669#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1470#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3871#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4372#include "chrome/browser/search/instant_service.h"
73#include "chrome/browser/search/instant_service_factory.h"
74#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1475#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0276#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3377#include "chrome/browser/speech/tts_message_filter.h"
[email protected]3b455502012-12-11 18:22:5878#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0379#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5280#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]180c66a62013-08-05 12:01:3681#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:4582#include "chrome/browser/tab_contents/tab_util.h"
[email protected]916615b2013-09-11 18:19:4483#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
[email protected]40aa8bb2013-08-23 20:28:2384#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
[email protected]a28e3302013-02-03 03:50:4385#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2586#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4487#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5088#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0689#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1590#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2791#include "chrome/browser/validation_message_message_filter.h"
[email protected]4a65826d2011-08-25 16:04:0192#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1493#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3094#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2995#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0496#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3897#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4498#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4399#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:29100#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]dda54822013-06-15 01:26:39101#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]157cc902012-11-02 06:31:58102#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]9a60d1602013-09-11 04:09:12103#include "chrome/common/extensions/web_accessible_resources_handler.h"
[email protected]f1933792011-06-14 00:49:34104#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37105#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12106#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38107#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09108#include "chrome/common/url_constants.h"
[email protected]264c0acac2013-10-01 13:33:30109#include "chrome/installer/util/google_update_settings.h"
[email protected]e8f3f9982013-05-10 20:59:53110#include "chromeos/chromeos_constants.h"
[email protected]d5d383252013-07-04 14:44:32111#include "components/nacl/common/nacl_process_type.h"
[email protected]75fee372013-03-06 00:42:44112#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43113#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30114#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38115#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03116#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31117#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03118#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59119#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:30120#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33121#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05122#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33123#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19124#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10125#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43126#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18127#include "content/public/common/content_descriptors.h"
[email protected]22aa4f82013-09-24 17:01:44128#include "content/public/common/url_utils.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]a220b5932013-09-21 03:47:44172#if defined(OS_POSIX) && !defined(OS_MACOSX)
[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) ||
[email protected]b9171622013-10-01 22:05:23363#if defined(ENABLE_ENHANCED_BOOKMARKS)
364 url->DomainIs(chrome::kChromeUIEnhancedBookmarksHost) ||
365#endif
[email protected]fe69558d2012-03-12 11:34:49366 url->DomainIs(chrome::kChromeUIHistoryHost))) {
367 // Rewrite with new tab URL
368 *url = GURL(chrome::kChromeUINewTabURL);
369 }
370 }
371#endif
372
[email protected]b8148ac2011-07-13 22:03:25373 // Special case the new tab page. In older versions of Chrome, the new tab
374 // page was hosted at chrome-internal:<blah>. This might be in people's saved
375 // sessions or bookmarks, so we say any URL with that scheme triggers the new
376 // tab page.
377 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
378 // Rewrite it with the proper new tab URL.
379 *url = GURL(chrome::kChromeUINewTabURL);
380 }
381
382 return true;
383}
384
[email protected]f8f93eb2012-09-25 03:06:24385// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
386// "chrome://foo/".
387bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
388 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
389 return false;
390
391 return RemoveUberHost(url);
392}
393
[email protected]8d3132f62011-10-12 07:13:42394// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
395// below. Extension, and isolated apps require different privileges to be
396// granted to their RenderProcessHosts. This classification allows us to make
397// sure URLs are served by hosts with the right set of privileges.
398enum RenderProcessHostPrivilege {
399 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45400 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42401 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45402 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42403};
404
405RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
406 const GURL& url,
407 ExtensionService* service) {
408 // Default to a normal renderer cause it is lower privileged. This should only
409 // occur if the URL on a site instance is either malformed, or uninitialized.
410 // If it is malformed, then there is no need for better privileges anyways.
411 // If it is uninitialized, but eventually settles on being an a scheme other
412 // than normal webrenderer, the navigation logic will correct us out of band
413 // anyways.
414 if (!url.is_valid())
415 return PRIV_NORMAL;
416
[email protected]885c0e92012-11-13 20:27:42417 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44418 const Extension* extension =
419 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43420 if (extension &&
421 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42422 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45423 if (extension && extension->is_hosted_app())
424 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42425
426 return PRIV_EXTENSION;
427 }
428
429 return PRIV_NORMAL;
430}
431
432RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30433 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46434 extensions::ProcessMap* process_map,
435 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46436 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30437 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46438 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21439 return PRIV_NORMAL;
440
[email protected]6f371442011-11-09 06:45:46441 for (std::set<std::string>::iterator iter = extension_ids.begin();
442 iter != extension_ids.end(); ++iter) {
443 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43444 if (extension &&
445 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42446 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45447 if (extension && extension->is_hosted_app())
448 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42449 }
450
[email protected]676f6ab2011-10-19 20:23:21451 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42452}
453
[email protected]6786bf402011-12-03 15:19:45454bool CertMatchesFilter(const net::X509Certificate& cert,
455 const base::DictionaryValue& filter) {
456 // TODO(markusheintz): This is the minimal required filter implementation.
457 // Implement a better matcher.
458
459 // An empty filter matches any client certificate since no requirements are
460 // specified at all.
461 if (filter.empty())
462 return true;
463
464 std::string common_name;
465 if (filter.GetString("ISSUER.CN", &common_name) &&
466 (cert.issuer().common_name == common_name)) {
467 return true;
468 }
469 return false;
470}
471
[email protected]f3986f82012-01-03 20:00:06472// Fills |map| with the per-script font prefs under path |map_name|.
473void FillFontFamilyMap(const PrefService* prefs,
474 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53475 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06476 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
477 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
478 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
479 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23480 if (!font_family.empty())
481 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06482 }
483}
484
[email protected]a1733df2012-06-22 11:24:18485#if defined(OS_POSIX) && !defined(OS_MACOSX)
486int GetCrashSignalFD(const CommandLine& command_line) {
487 if (command_line.HasSwitch(switches::kExtensionProcess)) {
488 ExtensionCrashHandlerHostLinux* crash_handler =
489 ExtensionCrashHandlerHostLinux::GetInstance();
490 return crash_handler->GetDeathSignalSocket();
491 }
492
493 std::string process_type =
494 command_line.GetSwitchValueASCII(switches::kProcessType);
495
496 if (process_type == switches::kRendererProcess)
497 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
498
499 if (process_type == switches::kPluginProcess)
500 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
501
502 if (process_type == switches::kPpapiPluginProcess)
503 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
504
505 if (process_type == switches::kGpuProcess)
506 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
507
508 return -1;
509}
510#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
511
[email protected]d5bcd06f2013-04-21 08:07:24512#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30513GURL GetEffectiveURLForSignin(const GURL& url) {
514 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
515
516 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03517 // Copy the path because the argument to SetPathStr must outlive
518 // the Replacements object.
519 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30520 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03521 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30522 effective_url = effective_url.ReplaceComponents(replacements);
523 return effective_url;
524}
[email protected]d5bcd06f2013-04-21 08:07:24525#endif
[email protected]970c63e2013-03-07 00:25:30526
[email protected]eabbfb12013-04-05 23:28:35527void SetApplicationLocaleOnIOThread(const std::string& locale) {
528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
529 g_io_thread_application_locale.Get() = locale;
530}
531
[email protected]916615b2013-09-11 18:19:44532void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) {
533 WebContents* tab = tab_util::GetWebContentsByID(params.render_process_id(),
534 params.opener_id());
[email protected]190e5e22013-07-27 05:59:23535 if (!tab)
536 return;
537
[email protected]190e5e22013-07-27 05:59:23538 PopupBlockerTabHelper* popup_helper =
539 PopupBlockerTabHelper::FromWebContents(tab);
540 if (!popup_helper)
541 return;
[email protected]916615b2013-09-11 18:19:44542 popup_helper->AddBlockedPopup(params);
[email protected]190e5e22013-07-27 05:59:23543}
[email protected]190e5e22013-07-27 05:59:23544
[email protected]916615b2013-09-11 18:19:44545#if defined(OS_ANDROID)
546void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) {
547 WebContents* web_contents =
548 tab_util::GetWebContentsByID(params.render_process_id(),
549 params.opener_id());
550 if (!web_contents)
551 return;
552
553 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params);
554}
555#endif // defined(OS_ANDROID)
556
[email protected]9dbfff12011-07-01 19:37:07557} // namespace
[email protected]c5dbef02011-05-13 05:06:09558
[email protected]d977f9c2011-03-14 16:10:26559namespace chrome {
560
[email protected]e461da2f2012-02-16 19:06:40561ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40562#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40563 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
564 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40565#endif
[email protected]1deace22013-05-22 06:14:46566
567 permissions_policy_delegate_.reset(
568 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40569}
570
571ChromeContentBrowserClient::~ChromeContentBrowserClient() {
572}
573
[email protected]bca18382012-06-25 19:15:23574// static
[email protected]37ca3fe02013-07-05 15:32:44575void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34576 user_prefs::PrefRegistrySyncable* registry) {
577 registry->RegisterBooleanPref(
578 prefs::kDisable3DAPIs,
579 false,
580 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
581 registry->RegisterBooleanPref(
582 prefs::kEnableHyperlinkAuditing,
583 true,
584 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
585 registry->RegisterBooleanPref(
586 prefs::kEnableMemoryInfo,
587 false,
588 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23589}
590
[email protected]eabbfb12013-04-05 23:28:35591// static
592void ChromeContentBrowserClient::SetApplicationLocale(
593 const std::string& locale) {
594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
595
596 // This object is guaranteed to outlive all threads so we don't have to
597 // worry about the lack of refcounting and can just post as Unretained.
598 //
599 // The common case is that this function is called early in Chrome startup
600 // before any threads are created (it will also be called later if the user
601 // changes the pref). In this case, there will be no threads created and
602 // posting will fail. When there are no threads, we can just set the string
603 // without worrying about threadsafety.
604 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
605 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
606 g_io_thread_application_locale.Get() = locale;
607 }
608}
609
[email protected]50462bf02011-11-21 19:13:31610content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
611 const content::MainFunctionParams& parameters) {
612 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30613 // Construct the Main browser parts based on the OS type.
614#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31615 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04616#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31617 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30618#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22619 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26620#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31621 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14622#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09623 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30624#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31625 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04626#else
[email protected]b48c9182011-10-26 18:03:30627 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31628 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30629#endif
630
[email protected]7e75e4a2013-05-17 17:20:03631 chrome::AddProfilesExtraParts(main_parts);
632
[email protected]c7480942011-11-08 19:18:27633 // Construct additional browser parts. Stages are called in the order in
634 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22635#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51636 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04637#endif
[email protected]c7480942011-11-08 19:18:27638
639#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51640 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27641#endif
642
[email protected]dc04be7c2012-03-15 23:57:49643#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51644 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49645#endif
646
[email protected]e050ef142012-03-21 01:04:24647#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51648 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
649#endif
650
651#if defined(USE_X11)
652 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24653#endif
654
[email protected]95132f52013-04-12 02:19:04655 chrome::AddMetricsExtraParts(main_parts);
656
[email protected]50462bf02011-11-21 19:13:31657 return main_parts;
[email protected]f967b722011-09-07 00:58:04658}
659
[email protected]e94bbcb2012-09-07 05:33:57660std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19661 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57662 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53663 std::string partition_id;
664
665 // The partition ID for webview guest processes is the string value of its
666 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
667 if (site.SchemeIs(chrome::kGuestScheme))
668 partition_id = site.spec();
669
[email protected]056efdc2013-04-06 00:14:53670 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53671 return partition_id;
672}
673
674bool ChromeContentBrowserClient::IsValidStoragePartitionId(
675 content::BrowserContext* browser_context,
676 const std::string& partition_id) {
677 // The default ID is empty and is always valid.
678 if (partition_id.empty())
679 return true;
680
681 return GURL(partition_id).is_valid();
682}
683
684void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
685 content::BrowserContext* browser_context,
686 const GURL& site,
[email protected]14acc642012-11-17 12:20:10687 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53688 std::string* partition_domain,
689 std::string* partition_name,
690 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10691 // Default to the browser-wide storage partition and override based on |site|
692 // below.
693 partition_domain->clear();
694 partition_name->clear();
695 *in_memory = false;
696
[email protected]1bc28312012-11-08 08:31:53697 // For the webview tag, we create special guest processes, which host the
698 // tag content separately from the main application that embeds the tag.
699 // A webview tag can specify both the partition name and whether the storage
700 // for that partition should be persisted. Each tag gets a SiteInstance with
701 // a specially formatted URL, based on the application it is hosted by and
702 // the partition requested by it. The format for that URL is:
703 // chrome-guest://partition_domain/persist?partition_name
704 if (site.SchemeIs(chrome::kGuestScheme)) {
705 // Since guest URLs are only used for packaged apps, there must be an app
706 // id in the URL.
707 CHECK(site.has_host());
708 *partition_domain = site.host();
709 // Since persistence is optional, the path must either be empty or the
710 // literal string.
711 *in_memory = (site.path() != "/persist");
712 // The partition name is user supplied value, which we have encoded when the
713 // URL was created, so it needs to be decoded.
714 *partition_name = net::UnescapeURLComponent(site.query(),
715 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10716 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
717 // If |can_be_default| is false, the caller is stating that the |site|
718 // should be parsed as if it had isolated storage. In particular it is
719 // important to NOT check ExtensionService for the is_storage_isolated()
720 // attribute because this code path is run during Extension uninstall
721 // to do cleanup after the Extension has already been unloaded from the
722 // ExtensionService.
723 bool is_isolated = !can_be_default;
724 if (can_be_default) {
725 const Extension* extension = NULL;
726 Profile* profile = Profile::FromBrowserContext(browser_context);
727 ExtensionService* extension_service =
728 extensions::ExtensionSystem::Get(profile)->extension_service();
729 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55730 extension =
731 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43732 if (extension &&
733 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10734 is_isolated = true;
735 }
736 }
737 }
[email protected]1bc28312012-11-08 08:31:53738
[email protected]14acc642012-11-17 12:20:10739 if (is_isolated) {
740 CHECK(site.has_host());
741 // For extensions with isolated storage, the the host of the |site| is
742 // the |partition_domain|. The |in_memory| and |partition_name| are only
743 // used in guest schemes so they are cleared here.
744 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53745 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10746 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53747 }
[email protected]d1198fd2012-08-13 22:50:19748 }
749
[email protected]14acc642012-11-17 12:20:10750 // Assert that if |can_be_default| is false, the code above must have found a
751 // non-default partition. If this fails, the caller has a serious logic
752 // error about which StoragePartition they expect to be in and it is not
753 // safe to continue.
754 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44755}
756
[email protected]38b098f2012-03-14 21:11:57757content::WebContentsViewDelegate*
758 ChromeContentBrowserClient::GetWebContentsViewDelegate(
759 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27760 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32761}
762
[email protected]738f57a2013-06-29 21:06:54763void ChromeContentBrowserClient::GuestWebContentsCreated(
764 WebContents* guest_web_contents,
765 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22766 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54767 scoped_ptr<base::DictionaryValue> extra_params) {
768 if (opener_web_contents) {
769 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
770 if (!guest) {
771 NOTREACHED();
772 return;
773 }
774
[email protected]50c827d2013-09-13 21:36:09775 // Create a new GuestView of the same type as the opener.
776 *guest_delegate =
777 GuestView::Create(guest_web_contents, guest->GetViewType());
[email protected]738f57a2013-06-29 21:06:54778 return;
779 }
780
781 if (!extra_params) {
782 NOTREACHED();
783 return;
784 }
785 std::string api_type;
[email protected]90547d72013-08-06 05:57:27786 extra_params->GetString(guestview::kParameterApi, &api_type);
[email protected]738f57a2013-06-29 21:06:54787
[email protected]50c827d2013-09-13 21:36:09788 *guest_delegate =
789 GuestView::Create(guest_web_contents,
790 GuestView::GetViewTypeFromString(api_type));
[email protected]738f57a2013-06-29 21:06:54791}
792
[email protected]44295a12013-06-05 08:45:46793void ChromeContentBrowserClient::GuestWebContentsAttached(
794 WebContents* guest_web_contents,
795 WebContents* embedder_web_contents,
[email protected]22aa4f82013-09-24 17:01:44796 const GURL& embedder_frame_url,
[email protected]5715566a2013-06-25 00:04:53797 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06798 Profile* profile = Profile::FromBrowserContext(
799 embedder_web_contents->GetBrowserContext());
800 ExtensionService* service =
801 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54802 if (!service) {
803 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06804 return;
[email protected]738f57a2013-06-29 21:06:54805 }
[email protected]22aa4f82013-09-24 17:01:44806
[email protected]c4927882013-09-26 04:19:09807 // We usually require BrowserPlugins to be hosted by a storage isolated
808 // extension. We treat WebUI pages as a special case if they host the
809 // BrowserPlugin in a component extension iframe. In that case, we use the
[email protected]22aa4f82013-09-24 17:01:44810 // iframe's URL to determine the extension.
811 const GURL& embedder_site_url =
812 embedder_web_contents->GetSiteInstance()->GetSiteURL();
813 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
814 content::HasWebUIScheme(embedder_site_url) ?
815 embedder_frame_url : embedder_site_url);
[email protected]738f57a2013-06-29 21:06:54816 if (!extension) {
[email protected]efd6fb02013-08-05 04:44:06817 // It's ok to return here, since we could be running a browser plugin
818 // outside an extension, and don't need to attach a
819 // BrowserPluginGuestDelegate in that case;
820 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
[email protected]738f57a2013-06-29 21:06:54821 return;
[email protected]18699372013-06-25 20:42:55822 }
[email protected]738f57a2013-06-29 21:06:54823
824 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
825 if (!guest) {
826 NOTREACHED();
827 return;
828 }
[email protected]9934a5e2013-08-22 00:07:56829 guest->Attach(embedder_web_contents, extension->id(), extra_params);
[email protected]44703cc72013-01-24 04:56:06830}
831
[email protected]f3b1a082011-11-18 00:34:30832void ChromeContentBrowserClient::RenderProcessHostCreated(
833 content::RenderProcessHost* host) {
834 int id = host->GetID();
835 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41836 net::URLRequestContextGetter* context =
837 profile->GetRequestContextForRenderProcess(id);
838
[email protected]ba780c12013-10-01 17:07:06839 host->AddFilter(new ChromeRenderMessageFilter(id, profile, context));
[email protected]ebd71962012-12-20 02:56:55840#if defined(ENABLE_PLUGINS)
[email protected]ba780c12013-10-01 17:07:06841 host->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55842#endif
[email protected]658677f2012-06-09 06:04:02843#if defined(ENABLE_PRINTING)
[email protected]ba780c12013-10-01 17:07:06844 host->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03845#endif
[email protected]ba780c12013-10-01 17:07:06846 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53847#if defined(ENABLE_SPELLCHECK)
[email protected]ba780c12013-10-01 17:07:06848 host->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53849#endif
[email protected]7ceb99012011-12-21 08:05:56850#if defined(OS_MACOSX)
[email protected]ba780c12013-10-01 17:07:06851 host->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56852#endif
[email protected]ba780c12013-10-01 17:07:06853 host->AddFilter(new ChromeNetBenchmarkingMessageFilter(
[email protected]43535512013-02-20 20:41:41854 id, profile, context));
[email protected]ba780c12013-10-01 17:07:06855 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
856 host->AddFilter(new ValidationMessageMessageFilter(id));
857 host->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31858#if defined(ENABLE_WEBRTC)
[email protected]ba780c12013-10-01 17:07:06859 host->AddFilter(new WebRtcLoggingHandlerHost());
[email protected]6ef98b5a2013-05-31 23:58:31860#endif
[email protected]01e59752013-06-18 00:17:35861#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03862 ExtensionInfoMap* extension_info_map =
863 extensions::ExtensionSystem::Get(profile)->info_map();
[email protected]ba780c12013-10-01 17:07:06864 host->AddFilter(new NaClHostMessageFilter(
[email protected]14230ca2013-06-26 23:33:03865 id, profile->IsOffTheRecord(),
866 profile->GetPath(), extension_info_map,
867 context));
[email protected]01e59752013-06-18 00:17:35868#endif
[email protected]2b12c322013-09-19 06:53:56869#if defined(OS_ANDROID)
[email protected]ba780c12013-10-01 17:07:06870 host->AddFilter(new EncryptedMediaMessageFilterAndroid());
[email protected]2b12c322013-09-19 06:53:56871#endif
[email protected]3e69bc82011-05-26 23:22:38872
[email protected]2ccf45c2011-08-19 23:35:50873 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
874 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07875
876 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56877
878 RendererContentSettingRules rules;
879 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
880 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14881}
882
[email protected]3d7474ff2011-07-27 17:47:37883GURL ChromeContentBrowserClient::GetEffectiveURL(
884 content::BrowserContext* browser_context, const GURL& url) {
885 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52886 if (!profile)
887 return url;
888
[email protected]b3cb3a32013-07-31 01:32:29889 // If the input |url| should be assigned to the Instant renderer, make its
890 // effective URL distinct from other URLs on the search provider's domain.
891 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
892 return chrome::GetEffectiveURLForInstant(url, profile);
893
[email protected]d5bcd06f2013-04-21 08:07:24894#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30895 // If the input |url| should be assigned to the Signin renderer, make its
896 // effective URL distinct from other URLs on the signin service's domain.
897 // Note that the signin renderer will be allowed to sign the user in to
898 // Chrome.
899 if (SigninManager::IsWebBasedSigninFlowURL(url))
900 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24901#endif
[email protected]970c63e2013-03-07 00:25:30902
[email protected]c5dec6292013-01-25 04:54:52903 // If the input |url| is part of an installed app, the effective URL is an
904 // extension URL with the ID of that extension as the host. This has the
905 // effect of grouping apps together in a common SiteInstance.
906 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13907 extensions::ExtensionSystem::Get(profile)->extension_service();
908 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08909 return url;
910
[email protected]06bdd2b2012-11-30 18:47:13911 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55912 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08913 if (!extension)
914 return url;
915
[email protected]15877ca2011-11-18 22:40:52916 // Bookmark apps do not use the hosted app process model, and should be
917 // treated as normal URLs.
918 if (extension->from_bookmark())
919 return url;
920
[email protected]36fb2c7c2011-04-04 15:49:08921 // If the URL is part of an extension's web extent, convert it to an
922 // extension URL.
923 return extension->GetResourceURL(url.path());
924}
925
[email protected]056ad2a2011-07-12 02:13:55926bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37927 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52928 // Non-extension, non-Instant URLs should generally use
929 // process-per-site-instance. Because we expect to use the effective URL,
930 // URLs for hosted apps (apart from bookmark apps) should have an extension
931 // scheme by now.
932
933 Profile* profile = Profile::FromBrowserContext(browser_context);
934 if (!profile)
935 return false;
936
[email protected]df113a12013-07-24 04:56:08937 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52938 return true;
939
[email protected]d5bcd06f2013-04-21 08:07:24940#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30941 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
942 return true;
[email protected]d5bcd06f2013-04-21 08:07:24943#endif
[email protected]970c63e2013-03-07 00:25:30944
[email protected]885c0e92012-11-13 20:27:42945 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55946 return false;
947
[email protected]c5dec6292013-01-25 04:54:52948 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13949 extensions::ExtensionSystem::Get(profile)->extension_service();
950 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55951 return false;
952
[email protected]be9915fb2013-07-18 09:28:55953 const Extension* extension =
954 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:55955 if (!extension)
956 return false;
957
958 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53959 // permission, or that does not allow JavaScript access to the background
960 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55961 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40962 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06963 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29964 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53965 return false;
966 }
967 }
[email protected]056ad2a2011-07-12 02:13:55968
[email protected]7b54ca02012-03-02 18:06:53969 // Hosted apps that have script access to their background page must use
970 // process per site, since all instances can make synchronous calls to the
971 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55972 return true;
973}
974
[email protected]672c8c12013-03-07 12:30:06975// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41976void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
977 std::vector<std::string>* additional_schemes) {
978 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06979}
980
[email protected]6bd30072013-02-08 18:17:11981net::URLRequestContextGetter*
982ChromeContentBrowserClient::CreateRequestContext(
983 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06984 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11985 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06986 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11987}
988
989net::URLRequestContextGetter*
990ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
991 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40992 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11993 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06994 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11995 Profile* profile = Profile::FromBrowserContext(browser_context);
996 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06997 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11998}
999
[email protected]46fb9442011-12-09 17:57:471000bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1001 return ProfileIOData::IsHandledURL(url);
1002}
1003
[email protected]c4365fa42013-05-14 01:08:241004bool ChromeContentBrowserClient::CanCommitURL(
1005 content::RenderProcessHost* process_host,
1006 const GURL& url) {
1007 // We need to let most extension URLs commit in any process, since this can
1008 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1009 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1010 // cannot be loaded in iframes and should never be requested outside its
1011 // process.
1012 Profile* profile =
1013 Profile::FromBrowserContext(process_host->GetBrowserContext());
1014 ExtensionService* service =
1015 extensions::ExtensionSystem::Get(profile)->extension_service();
1016 if (!service)
1017 return true;
1018 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551019 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241020 if (new_extension &&
1021 new_extension->is_hosted_app() &&
1022 new_extension->id() == extension_misc::kWebStoreAppId &&
1023 !service->process_map()->Contains(new_extension->id(),
1024 process_host->GetID())) {
1025 return false;
1026 }
1027
1028 return true;
1029}
1030
[email protected]9a60d1602013-09-11 04:09:121031bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1032 content::SiteInstance* site_instance, const GURL& url) {
1033 GURL from_url = site_instance->GetSiteURL();
1034 // Do not allow pages from the web or other extensions navigate to
1035 // non-web-accessible extension resources.
1036 if (url.SchemeIs(extensions::kExtensionScheme) &&
1037 (from_url.SchemeIsHTTPOrHTTPS() ||
1038 from_url.SchemeIs(extensions::kExtensionScheme))) {
1039 Profile* profile = Profile::FromBrowserContext(
1040 site_instance->GetProcess()->GetBrowserContext());
1041 ExtensionService* service =
1042 extensions::ExtensionSystem::Get(profile)->extension_service();
1043 if (!service)
1044 return true;
1045 const Extension* extension =
1046 service->extensions()->GetExtensionOrAppByURL(url);
1047 if (!extension)
1048 return true;
1049 const Extension* from_extension =
1050 service->extensions()->GetExtensionOrAppByURL(
1051 site_instance->GetSiteURL());
1052 if (from_extension && from_extension->id() == extension->id())
1053 return true;
1054
1055 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1056 extension, url.path()))
1057 return false;
1058 }
1059 return true;
1060}
1061
[email protected]2a5221b2011-09-27 23:07:311062bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301063 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311064 const GURL& site_url) {
1065 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301066 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521067 // This may be NULL during tests. In that case, just assume any site can
1068 // share any host.
1069 if (!profile)
1070 return true;
1071
[email protected]d43f99fe2013-04-03 00:20:141072 // Instant URLs should only be in the instant process and instant process
1073 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521074 InstantService* instant_service =
1075 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141076 if (instant_service) {
1077 bool is_instant_process = instant_service->IsInstantProcess(
1078 process_host->GetID());
1079 bool should_be_in_instant_process =
1080 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1081 if (is_instant_process || should_be_in_instant_process)
1082 return is_instant_process && should_be_in_instant_process;
1083 }
[email protected]c5dec6292013-01-25 04:54:521084
[email protected]d5bcd06f2013-04-21 08:07:241085#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301086 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1087 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1088 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241089#endif
[email protected]970c63e2013-03-07 00:25:301090
[email protected]06bdd2b2012-11-30 18:47:131091 ExtensionService* service =
1092 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461093 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311094
[email protected]ffa97602011-11-17 17:55:521095 // Don't allow the Task Manager to share a process with anything else.
1096 // Otherwise it can affect the renderers it is observing.
1097 // Note: we could create another RenderProcessHostPrivilege bucket for
1098 // this to allow multiple chrome://tasks instances to share, but that's
1099 // a very unlikely case without serious consequences.
1100 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1101 return false;
1102
[email protected]8d3132f62011-10-12 07:13:421103 // These may be NULL during tests. In that case, just assume any site can
1104 // share any host.
[email protected]6f371442011-11-09 06:45:461105 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311106 return true;
1107
[email protected]eec0b33c2011-12-05 22:09:451108 // Otherwise, just make sure the process privilege matches the privilege
1109 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571110 RenderProcessHostPrivilege privilege_required =
1111 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451112 return GetProcessPrivilege(process_host, process_map, service) ==
1113 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311114}
1115
[email protected]76411f412012-02-22 18:56:061116// This function is trying to limit the amount of processes used by extensions
1117// with background pages. It uses a globally set percentage of processes to
1118// run such extensions and if the limit is exceeded, it returns true, to
1119// indicate to the content module to group extensions together.
1120bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1121 content::BrowserContext* browser_context, const GURL& url) {
1122 // It has to be a valid URL for us to check for an extension.
1123 if (!url.is_valid())
1124 return false;
1125
1126 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191127 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131128 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061129 if (!service)
1130 return false;
1131
1132 // We have to have a valid extension with background page to proceed.
1133 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551134 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061135 if (!extension)
1136 return false;
[email protected]9367eabc2013-03-01 01:29:291137 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061138 return false;
1139
1140 std::set<int> process_ids;
1141 size_t max_process_count =
1142 content::RenderProcessHost::GetMaxRendererProcessCount();
1143
1144 // Go through all profiles to ensure we have total count of extension
1145 // processes containing background pages, otherwise one profile can
1146 // starve the other.
1147 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1148 GetLoadedProfiles();
1149 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031150 ExtensionProcessManager* epm =
1151 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321152 for (ExtensionProcessManager::const_iterator iter =
1153 epm->background_hosts().begin();
1154 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131155 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321156 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061157 }
1158 }
1159
1160 if (process_ids.size() >
1161 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1162 return true;
1163 }
1164
1165 return false;
1166}
1167
[email protected]6f371442011-11-09 06:45:461168void ChromeContentBrowserClient::SiteInstanceGotProcess(
1169 SiteInstance* site_instance) {
1170 CHECK(site_instance->HasProcess());
1171
1172 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021173 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521174 if (!profile)
1175 return;
1176
1177 // Remember the ID of the Instant process to signal the renderer process
1178 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031179 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321180 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521181 InstantService* instant_service =
1182 InstantServiceFactory::GetForProfile(profile);
1183 if (instant_service)
1184 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1185 }
1186
[email protected]d5bcd06f2013-04-21 08:07:241187#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301188 // We only expect there to be one signin process as we use process-per-site
1189 // for signin URLs. The signin process will be cleared from SigninManager
1190 // when the renderer is destroyed.
1191 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1192 SigninManager* signin_manager =
1193 SigninManagerFactory::GetForProfile(profile);
1194 if (signin_manager)
1195 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461196 BrowserThread::PostTask(
1197 BrowserThread::IO, FROM_HERE,
1198 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1199 extensions::ExtensionSystem::Get(profile)->info_map(),
1200 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301201 }
[email protected]d5bcd06f2013-04-21 08:07:241202#endif
[email protected]970c63e2013-03-07 00:25:301203
[email protected]06bdd2b2012-11-30 18:47:131204 ExtensionService* service =
1205 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461206 if (!service)
1207 return;
1208
[email protected]be9915fb2013-07-18 09:28:551209 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1210 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461211 if (!extension)
1212 return;
1213
[email protected]6bc04fd82011-12-04 02:29:351214 service->process_map()->Insert(extension->id(),
1215 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331216 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461217 BrowserThread::PostTask(
1218 BrowserThread::IO, FROM_HERE,
1219 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591220 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461221 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351222 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331223 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461224}
1225
1226void ChromeContentBrowserClient::SiteInstanceDeleting(
1227 SiteInstance* site_instance) {
1228 if (!site_instance->HasProcess())
1229 return;
1230
1231 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021232 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131233 ExtensionService* service =
1234 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461235 if (!service)
1236 return;
1237
[email protected]be9915fb2013-07-18 09:28:551238 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1239 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461240 if (!extension)
1241 return;
1242
[email protected]6bc04fd82011-12-04 02:29:351243 service->process_map()->Remove(extension->id(),
1244 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331245 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461246 BrowserThread::PostTask(
1247 BrowserThread::IO, FROM_HERE,
1248 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591249 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461250 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351251 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331252 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461253}
1254
[email protected]f05763972012-06-06 18:17:261255bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141256 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081257 const GURL& current_url,
1258 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261259 if (current_url.is_empty()) {
1260 // Always choose a new process when navigating to extension URLs. The
1261 // process grouping logic will combine all of a given extension's pages
1262 // into the same process.
[email protected]885c0e92012-11-13 20:27:421263 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261264 return true;
[email protected]e3daf3c2011-10-05 21:17:081265
[email protected]f05763972012-06-06 18:17:261266 return false;
1267 }
1268
1269 // Also, we must switch if one is an extension and the other is not the exact
1270 // same extension.
[email protected]885c0e92012-11-13 20:27:421271 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1272 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261273 if (current_url.GetOrigin() != new_url.GetOrigin())
1274 return true;
1275 }
1276
[email protected]e9841fbd2013-02-22 23:12:141277 // The checks below only matter if we can retrieve which extensions are
1278 // installed.
1279 Profile* profile =
1280 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1281 ExtensionService* service =
1282 extensions::ExtensionSystem::Get(profile)->extension_service();
1283 if (!service)
1284 return false;
1285
1286 // We must swap if the URL is for an extension and we are not using an
1287 // extension process.
1288 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551289 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141290 // Ignore all hosted apps except the Chrome Web Store, since they do not
1291 // require their own BrowsingInstance (e.g., postMessage is ok).
1292 if (new_extension &&
1293 new_extension->is_hosted_app() &&
1294 new_extension->id() != extension_misc::kWebStoreAppId)
1295 new_extension = NULL;
1296 if (new_extension &&
1297 site_instance->HasProcess() &&
1298 !service->process_map()->Contains(new_extension->id(),
1299 site_instance->GetProcess()->GetID()))
1300 return true;
1301
[email protected]f05763972012-06-06 18:17:261302 return false;
[email protected]e3daf3c2011-10-05 21:17:081303}
1304
[email protected]395045c2012-05-22 15:04:381305bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1306 content::ResourceContext* resource_context, const GURL& current_url,
1307 const GURL& new_url) {
1308 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1309 return extensions::CrossesExtensionProcessBoundary(
1310 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551311 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381312}
1313
[email protected]3d831992013-07-04 01:13:291314bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1315 return !url.SchemeIs(chrome::kChromeNativeScheme);
1316}
1317
[email protected]763ec4ca2011-04-29 15:48:121318std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1319 const std::string& alias_name) {
1320 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1321}
1322
[email protected]b80f68432011-05-02 17:22:301323void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1324 CommandLine* command_line, int child_process_id) {
[email protected]264c0acac2013-10-01 13:33:301325#if defined(OS_POSIX)
[email protected]b80f68432011-05-02 17:22:301326 if (IsCrashReporterEnabled()) {
[email protected]264c0acac2013-10-01 13:33:301327 std::string enable_crash_reporter;
1328 GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter);
1329#if !defined(OS_MACOSX)
1330 enable_crash_reporter += "," + base::GetLinuxDistro();
1331#endif
[email protected]b80f68432011-05-02 17:22:301332 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
[email protected]264c0acac2013-10-01 13:33:301333 enable_crash_reporter);
[email protected]b80f68432011-05-02 17:22:301334 }
[email protected]264c0acac2013-10-01 13:33:301335#endif // OS_POSIX
[email protected]b80f68432011-05-02 17:22:301336
[email protected]f1933792011-06-14 00:49:341337 if (logging::DialogsAreSuppressed())
1338 command_line->AppendSwitch(switches::kNoErrorDialogs);
1339
[email protected]b80f68432011-05-02 17:22:301340 std::string process_type =
1341 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171342 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321343
[email protected]7c9b6f92013-09-10 18:11:351344 static const char* const kCommonSwitchNames[] = {
1345 switches::kChromeFrame,
1346 switches::kUserDataDir, // Make logs go to the right file.
1347 };
1348 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1349 arraysize(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:321350
[email protected]718eab62011-10-05 21:16:521351 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:301352#if defined(OS_CHROMEOS)
1353 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441354 browser_command_line.GetSwitchValueASCII(
1355 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301356 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441357 command_line->AppendSwitchASCII(
1358 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301359#endif
1360
[email protected]f3b1a082011-11-18 00:34:301361 content::RenderProcessHost* process =
1362 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371363 if (process) {
1364 Profile* profile = Profile::FromBrowserContext(
1365 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131366 ExtensionService* extension_service =
1367 extensions::ExtensionSystem::Get(profile)->extension_service();
1368 if (extension_service) {
1369 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001370 if (process_map && process_map->Contains(process->GetID()))
1371 command_line->AppendSwitch(switches::kExtensionProcess);
1372 }
[email protected]b80f68432011-05-02 17:22:301373
[email protected]a8d851f82011-12-21 00:32:371374 PrefService* prefs = profile->GetPrefs();
1375 // Currently this pref is only registered if applied via a policy.
1376 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1377 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1378 // Turn this policy into a command line switch.
1379 command_line->AppendSwitch(switches::kDisable3DAPIs);
1380 }
[email protected]718eab62011-10-05 21:16:521381
[email protected]a8d851f82011-12-21 00:32:371382 // Disable client-side phishing detection in the renderer if it is
1383 // disabled in the Profile preferences or the browser process.
1384 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1385 !g_browser_process->safe_browsing_detection_service()) {
1386 command_line->AppendSwitch(
1387 switches::kDisableClientSidePhishingDetection);
1388 }
[email protected]0045b0f42012-07-26 11:52:081389
1390 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211391 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521392
1393 InstantService* instant_service =
1394 InstantServiceFactory::GetForProfile(profile);
1395 if (instant_service &&
1396 instant_service->IsInstantProcess(process->GetID()))
1397 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301398
[email protected]d5bcd06f2013-04-21 08:07:241399#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301400 SigninManager* signin_manager =
1401 SigninManagerFactory::GetForProfile(profile);
1402 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1403 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241404#endif
[email protected]47c7ec82012-01-18 03:29:211405 }
[email protected]4287a3d2011-06-13 23:56:511406
[email protected]16dc42452013-04-09 04:37:191407 if (message_center::IsRichNotificationEnabled())
1408 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191409
[email protected]47c7ec82012-01-18 03:29:211410 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511411 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171412 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481413 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171414 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]49d9b142013-07-19 08:50:271415 extensions::switches::kAllowLegacyExtensionManifests,
1416 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511417 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271418 extensions::switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511419 switches::kAllowHTTPBackgroundPage,
[email protected]9d450492013-06-13 23:08:371420 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1421 // to browser.
1422 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511423 switches::kAppsCheckoutURL,
1424 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311425 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511426 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501427 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531428 switches::kDisableExtensionsResourceWhitelist,
[email protected]83c85262013-08-22 21:13:461429 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111430 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531431 switches::kEnableAdview,
1432 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441433 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211434 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511435 switches::kEnableIPCFuzzing,
1436 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451437 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481438 switches::kEnablePasswordGeneration,
[email protected]4287a3d2011-06-13 23:56:511439 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511440 switches::kMemoryProfiling,
1441 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371442 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371443 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511444 switches::kPpapiFlashArgs,
1445 switches::kPpapiFlashInProcess,
1446 switches::kPpapiFlashPath,
1447 switches::kPpapiFlashVersion,
1448 switches::kProfilingAtStart,
1449 switches::kProfilingFile,
1450 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371451 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511452 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291453 switches::kSpdyProxyAuthOrigin,
[email protected]cbcf3b5b2013-08-06 17:14:191454 switches::kTranslateSecurityOrigin,
[email protected]a446534d2012-02-09 00:07:381455 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511456 };
1457
1458 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1459 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171460 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381461 static const char* const kSwitchNames[] = {
[email protected]c8d02992013-07-31 22:16:511462 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271463 extensions::switches::kExtensionsOnChromeURLs,
[email protected]eb653f82012-05-24 02:31:351464 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381465 switches::kWhitelistedExtensionID,
1466 };
1467
1468 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1469 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511470 } else if (process_type == switches::kPluginProcess) {
1471 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441472#if defined(OS_CHROMEOS)
1473 chromeos::switches::kLoginProfile,
1474#endif
[email protected]4287a3d2011-06-13 23:56:511475 switches::kMemoryProfiling,
1476 switches::kSilentDumpOnDCHECK,
[email protected]4287a3d2011-06-13 23:56:511477 };
1478
1479 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1480 arraysize(kSwitchNames));
1481 } else if (process_type == switches::kZygoteProcess) {
1482 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511483 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501484 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511485 switches::kPpapiFlashInProcess,
1486 switches::kPpapiFlashPath,
1487 switches::kPpapiFlashVersion,
1488 };
1489
1490 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1491 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111492 } else if (process_type == switches::kGpuProcess) {
1493 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1494 // because GPU is expected to be unreliable.
1495 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1496 !command_line->HasSwitch(switches::kDisableBreakpad))
1497 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301498 }
[email protected]6f08af82011-09-15 01:19:031499
1500 // The command line switch kEnableBenchmarking needs to be specified along
1501 // with the kEnableStatsTable switch to ensure that the stats table global
1502 // is initialized correctly.
1503 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1504 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301505}
1506
1507std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431508 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351509 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301510 return g_browser_process->GetApplicationLocale();
1511}
1512
[email protected]597a867b2011-11-18 18:31:201513std::string ChromeContentBrowserClient::GetAcceptLangs(
1514 content::BrowserContext* context) {
1515 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371516 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081517}
1518
[email protected]9ec0f452012-05-31 15:58:531519gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221520 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531521 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081522}
1523
[email protected]a2176792011-05-08 19:30:491524bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091525 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191526 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201527 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201529 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051530 return io_data->GetCookieSettings()->
1531 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491532}
1533
[email protected]ed24fad2011-05-10 22:44:011534bool ChromeContentBrowserClient::AllowGetCookie(
1535 const GURL& url,
1536 const GURL& first_party,
1537 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201538 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011539 int render_process_id,
1540 int render_view_id) {
1541 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201542 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051543 bool allow = io_data->GetCookieSettings()->
1544 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011545
[email protected]8093a542011-05-13 07:29:321546 BrowserThread::PostTask(
1547 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031548 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431549 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011550 return allow;
1551}
1552
1553bool ChromeContentBrowserClient::AllowSetCookie(
1554 const GURL& url,
1555 const GURL& first_party,
1556 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201557 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011558 int render_process_id,
1559 int render_view_id,
1560 net::CookieOptions* options) {
1561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201562 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051563 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1564 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1565
[email protected]8093a542011-05-13 07:29:321566 BrowserThread::PostTask(
1567 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031568 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431569 render_view_id, url, first_party, cookie_line, *options,
1570 !allow));
[email protected]ed24fad2011-05-10 22:44:011571 return allow;
1572}
1573
[email protected]d5a19162011-06-30 18:51:541574bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201575 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541576 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201577 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431578 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1579 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261580
[email protected]bf510ed2012-06-05 08:31:431581 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1582 // Could we even support per-origin settings?
1583 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541584}
1585
[email protected]5c5a88e2011-11-12 00:45:351586bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351587 const GURL& url,
1588 const string16& name,
1589 const string16& display_name,
1590 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201591 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481592 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201594 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351595 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1596 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1597
[email protected]62151052012-02-01 18:40:481598 // Record access to database for potential display in UI.
1599 std::vector<std::pair<int, int> >::const_iterator i;
1600 for (i = render_views.begin(); i != render_views.end(); ++i) {
1601 BrowserThread::PostTask(
1602 BrowserThread::UI, FROM_HERE,
1603 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1604 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351605 }
1606
1607 return allow;
1608}
1609
1610bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351611 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201612 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481613 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201615 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351616 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1617 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1618
[email protected]62151052012-02-01 18:40:481619 // Record access to file system for potential display in UI.
1620 std::vector<std::pair<int, int> >::const_iterator i;
1621 for (i = render_views.begin(); i != render_views.end(); ++i) {
1622 BrowserThread::PostTask(
1623 BrowserThread::UI, FROM_HERE,
1624 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1625 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351626 }
1627
1628 return allow;
1629}
1630
[email protected]7c5ff9a2012-03-02 07:42:491631bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1632 const GURL& url,
1633 const string16& name,
1634 content::ResourceContext* context,
1635 const std::vector<std::pair<int, int> >& render_views) {
1636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1637 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1638 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1639 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1640
1641 // Record access to IndexedDB for potential display in UI.
1642 std::vector<std::pair<int, int> >::const_iterator i;
1643 for (i = render_views.begin(); i != render_views.end(); ++i) {
1644 BrowserThread::PostTask(
1645 BrowserThread::UI, FROM_HERE,
1646 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1647 i->first, i->second, url, name, !allow));
1648 }
1649
1650 return allow;
1651}
1652
[email protected]33ad6ce92013-08-27 14:39:081653net::URLRequestContext*
1654ChromeContentBrowserClient::OverrideRequestContextForURL(
1655 const GURL& url, content::ResourceContext* context) {
1656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1657 if (url.SchemeIs(extensions::kExtensionScheme)) {
1658 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1659 return io_data->extensions_request_context();
1660 }
1661
1662 return NULL;
1663}
1664
[email protected]317f96c92011-05-31 06:53:411665QuotaPermissionContext*
1666ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1667 return new ChromeQuotaPermissionContext();
1668}
1669
[email protected]848dd042011-06-04 18:24:031670void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171671 int render_process_id,
1672 int render_view_id,
1673 int cert_error,
1674 const net::SSLInfo& ssl_info,
1675 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021676 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031677 bool overridable,
[email protected]d9be47702012-05-16 03:41:221678 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171679 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001680 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021681 if (resource_type != ResourceType::MAIN_FRAME) {
1682 // A sub-resource has a certificate error. The user doesn't really
1683 // have a context for making the right decision, so block the
1684 // request hard, without an info bar to allow showing the insecure
1685 // content.
[email protected]8c965c22013-05-23 19:28:001686 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021687 return;
1688 }
1689
[email protected]f9034cf2011-07-21 12:43:411690 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131691 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171692 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411693 if (!tab) {
1694 NOTREACHED();
1695 return;
1696 }
1697 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501698 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301699 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011700 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1701 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411702 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171703 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411704 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001705 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411706 return;
1707 }
1708 }
1709
[email protected]1e87df32012-09-12 04:53:191710#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231711 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1712 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1713 if (captive_portal_tab_helper)
1714 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191715#endif
1716
[email protected]f9034cf2011-07-21 12:43:411717 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221718 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1719 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031720}
1721
[email protected]c99c442e2011-08-24 11:37:301722void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451723 int render_process_id,
1724 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401725 const net::HttpNetworkSession* network_session,
1726 net::SSLCertRequestInfo* cert_request_info,
1727 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131728 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451729 render_process_id, render_view_id);
1730 if (!tab) {
1731 NOTREACHED();
1732 return;
1733 }
1734
[email protected]6786bf402011-12-03 15:19:451735 GURL requesting_url("https://" + cert_request_info->host_and_port);
1736 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1737 << cert_request_info->host_and_port;
1738
[email protected]627e0512011-12-21 22:55:301739 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451740 scoped_ptr<Value> filter(
1741 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1742 requesting_url,
1743 requesting_url,
1744 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1745 std::string(), NULL));
1746
1747 if (filter.get()) {
1748 // Try to automatically select a client certificate.
1749 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1750 DictionaryValue* filter_dict =
1751 static_cast<DictionaryValue*>(filter.get());
1752
1753 const std::vector<scoped_refptr<net::X509Certificate> >&
1754 all_client_certs = cert_request_info->client_certs;
1755 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091756 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451757 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091758 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451759 return;
1760 }
1761 }
1762 } else {
1763 NOTREACHED();
1764 }
1765 }
1766
[email protected]11feec322012-09-18 03:58:521767 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1768 if (!ssl_tab_helper) {
1769 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451770 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141771 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401772 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451773 return;
1774 }
[email protected]11feec322012-09-18 03:58:521775 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401776 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451777}
1778
[email protected]3b455502012-12-11 18:22:581779void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451780 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581781 net::CertificateMimeType cert_type,
1782 const void* cert_data,
1783 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451784 int render_process_id,
1785 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581786 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1787 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451788}
1789
[email protected]dc73a7b2012-03-25 15:27:181790content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561791 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181792}
1793
[email protected]941623e2011-06-07 23:06:041794void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1795 const GURL& source_origin,
1796 int callback_context,
1797 int render_process_id,
1798 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111799#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021800 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1801 WebContents* contents =
1802 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1803 if (!contents) {
[email protected]941623e2011-06-07 23:06:041804 NOTREACHED();
1805 return;
1806 }
1807
[email protected]d0d9c3ee2012-06-19 03:07:021808 // Skip showing the infobar if the request comes from an extension, and that
1809 // extension has the 'notify' permission. (If the extension does not have the
1810 // permission, the user will still be prompted.)
1811 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011812 ExtensionInfoMap* extension_info_map =
1813 extensions::ExtensionSystem::Get(profile)->info_map();
1814 DesktopNotificationService* notification_service =
1815 DesktopNotificationServiceFactory::GetForProfile(profile);
1816 const Extension* extension = NULL;
1817 if (extension_info_map) {
1818 ExtensionSet extensions;
1819 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1820 source_origin, render_process_id,
1821 extensions::APIPermission::kNotification, &extensions);
1822 for (ExtensionSet::const_iterator iter = extensions.begin();
1823 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381824 if (notification_service->IsNotifierEnabled(NotifierId(
1825 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361826 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011827 break;
1828 }
1829 }
1830 }
[email protected]eb4832a2012-12-08 01:57:521831 RenderViewHost* rvh =
1832 RenderViewHost::FromID(render_process_id, render_view_id);
1833 if (IsExtensionWithPermissionOrSuggestInConsole(
1834 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021835 if (rvh)
1836 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1837 return;
1838 }
1839
[email protected]c7cd5942013-04-30 03:31:011840 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021841 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111842#else
1843 NOTIMPLEMENTED();
1844#endif
[email protected]941623e2011-06-07 23:06:041845}
1846
1847WebKit::WebNotificationPresenter::Permission
1848 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021849 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201850 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021851 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111852#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041853 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481854 // Sometimes a notification may be invoked during the shutdown.
1855 // See http://crbug.com/256638
1856 if (browser_shutdown::IsTryingToQuit())
1857 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
1858
[email protected]df02aca2012-02-09 21:03:201859 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041860
[email protected]c7cd5942013-04-30 03:31:011861 DesktopNotificationService* notification_service =
1862 io_data->GetNotificationService();
1863 if (notification_service) {
1864 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1865 ExtensionSet extensions;
1866 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1867 source_origin, render_process_id,
1868 extensions::APIPermission::kNotification, &extensions);
1869 for (ExtensionSet::const_iterator iter = extensions.begin();
1870 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381871 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
1872 if (notification_service->IsNotifierEnabled(notifier_id))
[email protected]c7cd5942013-04-30 03:31:011873 return WebKit::WebNotificationPresenter::PermissionAllowed;
1874 }
1875
1876 return notification_service->HasPermission(source_origin);
1877 }
1878
1879 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111880#else
1881 return WebKit::WebNotificationPresenter::PermissionAllowed;
1882#endif
[email protected]941623e2011-06-07 23:06:041883}
1884
1885void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171886 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041887 int render_process_id,
1888 int render_view_id,
1889 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111890#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041891 RenderViewHost* rvh = RenderViewHost::FromID(
1892 render_process_id, render_view_id);
1893 if (!rvh) {
1894 NOTREACHED();
1895 return;
1896 }
1897
[email protected]9f76c1e2012-03-05 15:15:581898 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301899 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041900 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371901 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041902 service->ShowDesktopNotification(
1903 params, render_process_id, render_view_id,
1904 worker ? DesktopNotificationService::WorkerNotification :
1905 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111906#else
1907 NOTIMPLEMENTED();
1908#endif
[email protected]941623e2011-06-07 23:06:041909}
1910
1911void ChromeContentBrowserClient::CancelDesktopNotification(
1912 int render_process_id,
1913 int render_view_id,
1914 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111915#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041916 RenderViewHost* rvh = RenderViewHost::FromID(
1917 render_process_id, render_view_id);
1918 if (!rvh) {
1919 NOTREACHED();
1920 return;
1921 }
1922
[email protected]9f76c1e2012-03-05 15:15:581923 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301924 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041925 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371926 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041927 service->CancelDesktopNotification(
1928 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111929#else
1930 NOTIMPLEMENTED();
1931#endif
[email protected]941623e2011-06-07 23:06:041932}
1933
[email protected]9f3fba52011-06-08 20:37:191934bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351935 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:571936 const GURL& opener_top_level_frame_url,
[email protected]34eec7ffe32011-11-02 23:49:021937 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191938 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:231939 const GURL& target_url,
1940 const content::Referrer& referrer,
1941 WindowOpenDisposition disposition,
1942 const WebWindowFeatures& features,
1943 bool user_gesture,
1944 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:201945 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011946 int render_process_id,
[email protected]190e5e22013-07-27 05:59:231947 bool is_guest,
1948 int opener_id,
[email protected]03b6d552012-03-29 04:03:011949 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191950 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011951
1952 *no_javascript_access = false;
1953
[email protected]5e5f55e262c52013-09-12 00:27:191954 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1955 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1956
[email protected]9f3fba52011-06-08 20:37:191957 // If the opener is trying to create a background window but doesn't have
1958 // the appropriate permission, fail the attempt.
[email protected]6940eef82013-09-11 11:58:411959 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]03b6d552012-03-29 04:03:011960 if (!map->SecurityOriginHasAPIPermission(
1961 source_origin,
1962 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061963 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011964 return false;
1965 }
1966
[email protected]7b54ca02012-03-02 18:06:531967 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1968 // return a recently installed Extension even if this CanCreateWindow call
1969 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011970 // because the permission check above would have caused an early return
1971 // already. We must use the full URL to find hosted apps, though, and not
1972 // just the origin.
[email protected]be9915fb2013-07-18 09:28:551973 const Extension* extension =
1974 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:291975 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011976 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:231977
1978 return true;
[email protected]9f3fba52011-06-08 20:37:191979 }
[email protected]056efdc2013-04-06 00:14:531980
1981 // No new browser window (popup or tab) in app mode.
1982 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1983 chrome::IsRunningInForcedAppMode()) {
1984 return false;
1985 }
1986
[email protected]d2bac6b2013-08-13 03:42:361987 if (g_browser_process->prerender_tracker() &&
1988 g_browser_process->prerender_tracker()->TryCancelOnIOThread(
1989 render_process_id,
1990 opener_id,
1991 prerender::FINAL_STATUS_CREATE_NEW_WINDOW)) {
1992 return false;
1993 }
1994
[email protected]190e5e22013-07-27 05:59:231995 if (is_guest)
1996 return true;
1997
[email protected]190e5e22013-07-27 05:59:231998 HostContentSettingsMap* content_settings =
1999 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
[email protected]916615b2013-09-11 18:19:442000 BlockedWindowParams blocked_params(target_url,
2001 referrer,
2002 disposition,
2003 features,
2004 user_gesture,
2005 opener_suppressed,
2006 render_process_id,
2007 opener_id);
[email protected]190e5e22013-07-27 05:59:232008
[email protected]7f53dff2013-08-05 10:45:502009 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch(
2010 switches::kDisablePopupBlocking)) {
[email protected]931bc922013-09-11 21:42:572011 if (content_settings->GetContentSetting(opener_top_level_frame_url,
2012 opener_top_level_frame_url,
[email protected]190e5e22013-07-27 05:59:232013 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]916615b2013-09-11 18:19:442014 std::string()) !=
[email protected]190e5e22013-07-27 05:59:232015 CONTENT_SETTING_ALLOW) {
[email protected]916615b2013-09-11 18:19:442016 BrowserThread::PostTask(BrowserThread::UI,
2017 FROM_HERE,
2018 base::Bind(&HandleBlockedPopupOnUIThread,
2019 blocked_params));
2020 return false;
[email protected]190e5e22013-07-27 05:59:232021 }
[email protected]916615b2013-09-11 18:19:442022 }
[email protected]190e5e22013-07-27 05:59:232023
[email protected]916615b2013-09-11 18:19:442024#if defined(OS_ANDROID)
2025 if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) {
[email protected]190e5e22013-07-27 05:59:232026 BrowserThread::PostTask(BrowserThread::UI,
2027 FROM_HERE,
[email protected]916615b2013-09-11 18:19:442028 base::Bind(&HandleSingleTabModeBlockOnUIThread,
2029 blocked_params));
[email protected]190e5e22013-07-27 05:59:232030 return false;
2031 }
[email protected]916615b2013-09-11 18:19:442032#endif
[email protected]190e5e22013-07-27 05:59:232033
[email protected]9f3fba52011-06-08 20:37:192034 return true;
2035}
2036
2037std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202038 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192039 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2040 // Check if it's an extension-created worker, in which case we want to use
2041 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202042 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192043 const Extension* extension =
2044 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2045 return extension ? extension->name() : std::string();
2046}
2047
[email protected]99907362012-01-11 05:41:402048void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2049 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172050}
2051
[email protected]7a06d282013-05-03 04:39:332052// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022053content::SpeechRecognitionManagerDelegate*
2054 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002055#if defined(ENABLE_INPUT_SPEECH)
2056 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322057#else
[email protected]855e18b2013-07-08 21:02:002058 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2059 // need the base delegate without the bubble UI.
2060 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322061#endif
[email protected]66cfec62012-02-24 17:57:512062}
2063
[email protected]ae6e9912011-07-27 01:18:282064net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2065 return g_browser_process->net_log();
2066}
2067
[email protected]32538d92011-08-25 00:09:232068AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2069 return new ChromeAccessTokenStore();
2070}
2071
[email protected]dbae6b02011-06-29 23:51:412072bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012073 return true;
[email protected]dbae6b02011-06-29 23:51:412074}
2075
[email protected]64d69de42012-02-06 00:19:542076void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322077 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062078 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582079 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062080 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062081
[email protected]f3986f82012-01-03 20:00:062082 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542083 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062084 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542085 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062086 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542087 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062088 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542089 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062090 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542091 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062092 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542093 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032094 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2095 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:062096
[email protected]64d69de42012-02-06 00:19:542097 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402098 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542099 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402100 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542101 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402102 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542103 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402104 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062105
[email protected]ddf72142012-05-22 04:52:402106 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062107
[email protected]64d69de42012-02-06 00:19:542108 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402109 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542110 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062111 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542112 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062113 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2114 const DictionaryValue* inspector_settings =
2115 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2116 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182117 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2118 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062119 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182120 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542121 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182122 std::make_pair(iter.key(), value));
2123 }
[email protected]f3986f82012-01-03 20:00:062124 }
2125 }
[email protected]64d69de42012-02-06 00:19:542126 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062127
[email protected]ddf72142012-05-22 04:52:402128 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542129 web_prefs->javascript_enabled = false;
2130 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2131 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402132 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542133 web_prefs->plugins_enabled = false;
2134 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2135 web_prefs->java_enabled = false;
2136 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402137 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062138
[email protected]64d69de42012-02-06 00:19:542139 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2140 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062141
[email protected]64d69de42012-02-06 00:19:542142 web_prefs->memory_info_enabled =
2143 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2144 web_prefs->allow_displaying_insecure_content =
2145 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2146 web_prefs->allow_running_insecure_content =
2147 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322148#if defined(OS_ANDROID)
2149 web_prefs->font_scale_factor =
2150 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2151 web_prefs->force_enable_zoom =
2152 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2153#endif
[email protected]5c915252013-05-07 13:15:392154
[email protected]af4256d52013-06-04 20:39:072155#if defined(OS_ANDROID)
2156 web_prefs->password_echo_enabled =
2157 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2158#else
[email protected]9d06d88d2012-02-23 22:37:082159 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072160#endif
2161
[email protected]5c915252013-05-07 13:15:392162#if defined(OS_CHROMEOS)
2163 // Enable password echo during OOBE when keyboard driven flag is set.
2164 if (chromeos::UserManager::IsInitialized() &&
2165 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
[email protected]c94ac692013-07-27 00:50:102166 !chromeos::StartupUtils::IsOobeCompleted() &&
2167 chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation()) {
2168 web_prefs->password_echo_enabled = true;
[email protected]5c915252013-05-07 13:15:392169 }
2170#endif
[email protected]f3986f82012-01-03 20:00:062171
[email protected]46f8e742013-05-03 18:37:142172#if defined(OS_ANDROID)
2173 web_prefs->user_style_sheet_enabled = false;
2174#else
[email protected]64d69de42012-02-06 00:19:542175 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152176 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362177 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152178 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542179 web_prefs->user_style_sheet_enabled = true;
2180 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152181 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542182 } else {
2183 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062184 }
[email protected]46f8e742013-05-03 18:37:142185#endif
[email protected]f3986f82012-01-03 20:00:062186
[email protected]cfadadd2013-04-03 04:43:022187 web_prefs->asynchronous_spell_checking_enabled = true;
2188 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572189
[email protected]64d69de42012-02-06 00:19:542190 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062191 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542192 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062193 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542194 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062195 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2196
2197 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542198 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062199 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542200 web_prefs->default_encoding);
2201 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402202 prefs->ClearPref(prefs::kDefaultCharset);
2203 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062204 }
[email protected]64d69de42012-02-06 00:19:542205 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062206
[email protected]299d7f12012-05-23 05:31:152207 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232208 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132209 ExtensionService* service =
2210 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062211 if (service) {
[email protected]1bc28312012-11-08 08:31:532212 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2213 const Extension* extension = service->extensions()->GetByID(url.host());
2214 // Ensure that we are only granting extension preferences to URLs with
2215 // the correct scheme. Without this check, chrome-guest:// schemes used by
2216 // webview tags as well as hosts that happen to match the id of an
2217 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422218 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532219 extension_webkit_preferences::SetPreferences(
2220 extension, view_type, web_prefs);
2221 }
[email protected]f3986f82012-01-03 20:00:062222 }
2223
[email protected]cb2edf22013-04-01 20:25:232224 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542225 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232226 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062227 // Disable all kinds of acceleration for background pages.
2228 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542229 web_prefs->force_compositing_mode = false;
2230 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062231 }
[email protected]2e21fe292012-03-02 22:52:322232
2233#if defined(FILE_MANAGER_EXTENSION)
2234 // Override the default of suppressing HW compositing for WebUI pages for the
2235 // file manager, which is implemented using WebUI but wants HW acceleration
2236 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532237 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]2de96a52013-08-14 01:18:092238 url.host() == file_manager::kFileManagerAppId) {
[email protected]2e21fe292012-03-02 22:52:322239 web_prefs->accelerated_compositing_enabled = true;
2240 web_prefs->accelerated_2d_canvas_enabled = true;
2241 }
2242#endif
[email protected]181a95ee2011-07-12 19:26:362243}
2244
2245void ChromeContentBrowserClient::UpdateInspectorSetting(
2246 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062247 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582248 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062249 DictionaryPrefUpdate update(
2250 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2251 prefs::kWebKitInspectorSettings);
2252 DictionaryValue* inspector_settings = update.Get();
2253 inspector_settings->SetWithoutPathExpansion(key,
2254 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362255}
2256
[email protected]b8148ac2011-07-13 22:03:252257void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2258 BrowserURLHandler* handler) {
2259 // Add the default URL handlers.
2260 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2261 BrowserURLHandler::null_handler());
2262 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2263 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2264
[email protected]b3adbd02011-11-30 22:23:272265 // about: handler. Must come before chrome: handler, since it will
2266 // rewrite about: urls to chrome: URLs and then expect chrome: to
2267 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252268 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2269 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032270
2271 // Handler to rewrite chrome://newtab for InstantExtended.
2272 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2273 &chrome::HandleNewTabURLReverseRewrite);
2274
[email protected]b8148ac2011-07-13 22:03:252275 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242276 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252277}
2278
2279void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372280 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582281 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472282 BrowsingDataRemover* remover =
2283 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552284 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2285 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252286 // BrowsingDataRemover takes care of deleting itself when done.
2287}
2288
2289void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372290 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582291 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472292 BrowsingDataRemover* remover =
2293 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232294 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552295 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252296 // BrowsingDataRemover takes care of deleting itself when done.
2297}
2298
[email protected]650b2d52013-02-10 03:41:452299base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:492300 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:322301}
2302
[email protected]c9b6eb62011-10-18 20:49:392303std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2304 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2305}
2306
[email protected]b7631cc2012-09-15 05:08:382307void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2308 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542309#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382310 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2311 scoped_ptr<ppapi::host::HostFactory>(
2312 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542313#endif
[email protected]b7631cc2012-09-15 05:08:382314}
2315
[email protected]0c7193742012-11-07 19:05:032316content::BrowserPpapiHost*
2317 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2318 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132319 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032320 while (!iter.Done()) {
2321 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2322 if (host->process() &&
2323 host->process()->GetData().id == plugin_process_id) {
2324 // Found the plugin.
2325 return host->browser_ppapi_host();
2326 }
2327 ++iter;
2328 }
2329 return NULL;
2330}
2331
[email protected]7b38b192013-03-23 18:39:312332bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2333 content::BrowserContext* browser_context, const GURL& site_url) {
2334 if (CommandLine::ForCurrentProcess()->HasSwitch(
2335 switches::kEnableBrowserPluginForAllViewTypes))
2336 return true;
2337
[email protected]22aa4f82013-09-24 17:01:442338 if (content::HasWebUIScheme(site_url))
2339 return true;
2340
[email protected]7b38b192013-03-23 18:39:312341 Profile* profile = Profile::FromBrowserContext(browser_context);
2342 ExtensionService* service =
2343 extensions::ExtensionSystem::Get(profile)->extension_service();
2344 if (!service)
2345 return false;
2346
[email protected]be9915fb2013-07-18 09:28:552347 const Extension* extension =
2348 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312349 if (!extension)
2350 return false;
2351
[email protected]c2d2f102013-04-29 16:42:582352 return extension->HasAPIPermission(APIPermission::kWebView) ||
2353 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312354}
2355
[email protected]38cd8f7f2012-06-15 22:06:072356bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582357 content::BrowserContext* browser_context,
2358 const GURL& url,
[email protected]dda54822013-06-15 01:26:392359 bool private_api,
[email protected]8b92ed182013-09-21 04:47:122360 const content::SocketPermissionRequest* params) {
[email protected]93f72062013-05-29 20:29:402361#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372362 Profile* profile = Profile::FromBrowserContext(browser_context);
2363 const ExtensionSet* extension_set = NULL;
2364 if (profile) {
2365 extension_set = extensions::ExtensionSystem::Get(profile)->
2366 extension_service()->extensions();
2367 }
[email protected]dda54822013-06-15 01:26:392368
2369 if (private_api) {
2370 // Access to private socket APIs is controlled by the whitelist.
2371 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2372 allowed_socket_origins_)) {
2373 return true;
2374 }
2375 } else {
2376 // Access to public socket APIs is controlled by extension permissions.
2377 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2378 extension_set) {
2379 const Extension* extension = extension_set->GetByID(url.host());
2380 if (extension) {
[email protected]8b92ed182013-09-21 04:47:122381 if (params) {
2382 extensions::SocketPermission::CheckParam check_params(
2383 params->type, params->host, params->port);
2384 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2385 extension, extensions::APIPermission::kSocket,
2386 &check_params)) {
2387 return true;
2388 }
2389 } else {
2390 if (extensions::PermissionsData::HasAPIPermission(
2391 extension, extensions::APIPermission::kSocket)) {
2392 return true;
2393 }
[email protected]dda54822013-06-15 01:26:392394 }
2395 }
2396 }
2397 }
2398
2399 // Allow both public and private APIs if the command line says so.
2400 return IsHostAllowedByCommandLine(url, extension_set,
2401 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402402#else
[email protected]a658d452012-03-02 12:45:292403 return false;
[email protected]93f72062013-05-29 20:29:402404#endif
[email protected]e461da2f2012-02-16 19:06:402405}
2406
[email protected]a28e3302013-02-03 03:50:432407ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2408 WebContents* web_contents) {
2409 return new ChromeSelectFilePolicy(web_contents);
2410}
2411
[email protected]7d9424702013-04-14 13:14:162412void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2413 std::vector<std::string>* additional_allowed_schemes) {
2414 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2415 additional_allowed_schemes);
2416 additional_allowed_schemes->push_back(kChromeUIScheme);
2417 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2418}
2419
[email protected]f19bbf62013-07-09 01:22:322420void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312421 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532422 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322423 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532424#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032425 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322426 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032427 storage_partition_path,
2428 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322429 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532430#endif
[email protected]b40015c2013-06-26 08:13:312431#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312432 fileapi::ExternalMountPoints* external_mount_points =
2433 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312434 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322435 chromeos::FileSystemBackend* backend =
2436 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312437 new drive::FileSystemBackendDelegate(browser_context),
2438 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312439 external_mount_points,
2440 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322441 backend->AddSystemMountPoints();
2442 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2443 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312444#endif
[email protected]445b7db2013-08-02 04:58:272445
[email protected]e86e2be2013-08-30 11:20:392446 additional_backends->push_back(
2447 new sync_file_system::SyncFileSystemBackend(
2448 Profile::FromBrowserContext(browser_context)));
[email protected]02250952013-04-24 23:52:532449}
2450
[email protected]e60c0232011-11-11 19:56:352451#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182452void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2453 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382454 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082455 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392456#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452457 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392458 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2459 DCHECK(!data_path.empty());
2460
2461 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452462 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392463 data_path.AppendASCII("chrome_100_percent.pak");
[email protected]5db2b7492013-08-23 05:33:092464 base::PlatformFile f =
2465 base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
[email protected]29699c22012-10-03 23:57:392466 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372467 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392468 FileDescriptor(f, true)));
2469
2470 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452471 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392472 GetLocaleFilePath(locale, false);
2473 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2474 DCHECK(f != base::kInvalidPlatformFileValue);
2475 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2476 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382477
[email protected]650b2d52013-02-10 03:41:452478 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372479 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2480 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2481 DCHECK(f != base::kInvalidPlatformFileValue);
2482 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2483 FileDescriptor(f, true)));
2484
[email protected]82174aa2013-01-22 21:53:432485 if (IsCrashReporterEnabled()) {
2486 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2487 if (f == base::kInvalidPlatformFileValue) {
2488 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2489 "be disabled for this process.";
2490 } else {
2491 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2492 FileDescriptor(f, true)));
2493 }
[email protected]40da3e0c2012-10-24 22:03:382494 }
[email protected]40da3e0c2012-10-24 22:03:382495
2496#else
2497 int crash_signal_fd = GetCrashSignalFD(command_line);
2498 if (crash_signal_fd >= 0) {
2499 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2500 FileDescriptor(crash_signal_fd,
2501 false)));
2502 }
[email protected]29699c22012-10-03 23:57:392503#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302504}
[email protected]e60c0232011-11-11 19:56:352505#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302506
[email protected]4a65826d2011-08-25 16:04:012507#if defined(OS_WIN)
2508const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2509 return chrome::kBrowserResourcesDll;
2510}
[email protected]34f48682013-03-20 00:30:182511
2512void ChromeContentBrowserClient::PreSpawnRenderer(
2513 sandbox::TargetPolicy* policy,
2514 bool* success) {
2515 // This code is duplicated in nacl_exe_win_64.cc.
2516 // Allow the server side of a pipe restricted to the "chrome.nacl."
2517 // namespace so that it cannot impersonate other system or other chrome
2518 // service pipes.
2519 sandbox::ResultCode result = policy->AddRule(
2520 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2521 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2522 L"\\\\.\\pipe\\chrome.nacl.*");
2523 if (result != sandbox::SBOX_ALL_OK) {
2524 *success = false;
2525 return;
2526 }
2527
2528 // Renderers need to send named pipe handles and shared memory
2529 // segment handles to NaCl loader processes.
2530 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2531 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2532 L"File");
2533 if (result != sandbox::SBOX_ALL_OK) {
2534 *success = false;
2535 return;
2536 }
2537}
[email protected]4a65826d2011-08-25 16:04:012538#endif
2539
[email protected]37a72af2011-06-13 05:42:012540#if defined(USE_NSS)
2541crypto::CryptoModuleBlockingPasswordDelegate*
2542 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2543 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292544 return chrome::NewCryptoModuleBlockingDialogDelegate(
2545 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012546}
2547#endif
2548
[email protected]d977f9c2011-03-14 16:10:262549} // namespace chrome