blob: e9e3a6219509c8ae3e76f96c5e013572e234aacf [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]056efdc2013-04-06 00:14:5319#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]b8148ac2011-07-13 22:03:2520#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3021#include "chrome/browser/browser_process.h"
[email protected]5c129792013-07-10 02:08:4822#include "chrome/browser/browser_shutdown.h"
[email protected]b0cb5e82012-07-19 19:22:4723#include "chrome/browser/browsing_data/browsing_data_helper.h"
24#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1225#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4126#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4127#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5628#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0529#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4530#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3231#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0832#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4933#include "chrome/browser/download/download_prefs.h"
[email protected]2b33dcd02012-03-18 01:34:1634#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]1deace22013-05-22 06:14:4635#include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
[email protected]76411f412012-02-22 18:56:0636#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0437#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3338#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2639#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0840#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2541#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0642#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5243#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2344#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1245#include "chrome/browser/google/google_util.h"
[email protected]0533cc6d2013-06-27 22:44:0546#include "chrome/browser/guestview/adview/adview_guest.h"
47#include "chrome/browser/guestview/guestview_constants.h"
48#include "chrome/browser/guestview/webview/webview_guest.h"
[email protected]11158e2d2013-02-01 02:31:5649#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0450#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]a2b4c5c2013-10-18 02:06:0751#include "chrome/browser/nacl_host/nacl_browser.h"
52#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
[email protected]01e59752013-06-18 00:17:3553#include "chrome/browser/nacl_host/nacl_host_message_filter.h"
[email protected]0c7193742012-11-07 19:05:0354#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2855#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0456#include "chrome/browser/notifications/desktop_notification_service.h"
57#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4258#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5659#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0660#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]190e5e22013-07-27 05:59:2361#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4162#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5063#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0764#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4165#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1466#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0367#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1468#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3269#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0670#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1471#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3872#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4373#include "chrome/browser/search/instant_service.h"
74#include "chrome/browser/search/instant_service_factory.h"
75#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1476#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0277#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3378#include "chrome/browser/speech/tts_message_filter.h"
[email protected]3b455502012-12-11 18:22:5879#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0380#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5281#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]180c66a62013-08-05 12:01:3682#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:4583#include "chrome/browser/tab_contents/tab_util.h"
[email protected]916615b2013-09-11 18:19:4484#include "chrome/browser/ui/blocked_content/blocked_window_params.h"
[email protected]40aa8bb2013-08-23 20:28:2385#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
[email protected]a28e3302013-02-03 03:50:4386#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2587#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4488#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5089#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0690#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1591#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2792#include "chrome/browser/validation_message_message_filter.h"
[email protected]4a65826d2011-08-25 16:04:0193#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1494#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3095#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2996#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0497#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3898#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4499#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:43100#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:29101#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]dda54822013-06-15 01:26:39102#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]157cc902012-11-02 06:31:58103#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]9a60d1602013-09-11 04:09:12104#include "chrome/common/extensions/web_accessible_resources_handler.h"
[email protected]f1933792011-06-14 00:49:34105#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37106#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12107#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38108#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09109#include "chrome/common/url_constants.h"
[email protected]264c0acac2013-10-01 13:33:30110#include "chrome/installer/util/google_update_settings.h"
[email protected]e8f3f9982013-05-10 20:59:53111#include "chromeos/chromeos_constants.h"
[email protected]d5d383252013-07-04 14:44:32112#include "components/nacl/common/nacl_process_type.h"
[email protected]499e7c52013-10-04 16:03:09113#include "components/translate/common/translate_switches.h"
[email protected]75fee372013-03-06 00:42:44114#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43115#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30116#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38117#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03118#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31119#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03120#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59121#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:30122#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33123#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05124#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33125#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19126#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10127#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43128#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18129#include "content/public/common/content_descriptors.h"
[email protected]22aa4f82013-09-24 17:01:44130#include "content/public/common/url_utils.h"
[email protected]cb2edf22013-04-01 20:25:23131#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42132#include "extensions/common/constants.h"
[email protected]49d9b142013-07-19 08:50:27133#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39134#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23135#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53136#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58137#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34138#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06139#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57140#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38141#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39142#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08143#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24144#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31145#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18146#include "webkit/common/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:26147
[email protected]b48c9182011-10-26 18:03:30148#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38149#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18150#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38151#elif defined(OS_MACOSX)
152#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56153#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]73929052013-10-11 12:22:09154#include "components/breakpad/breakpad_mac.h"
[email protected]b48c9182011-10-26 18:03:30155#elif defined(OS_CHROMEOS)
156#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]f19bbf62013-07-09 01:22:32157#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h"
158#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39159#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49160#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10161#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44162#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26163#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30164#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09165#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38166#include "chrome/browser/android/crash_dump_manager.h"
[email protected]916615b2013-09-11 18:19:44167#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
[email protected]81054f812012-08-30 00:47:09168#include "chrome/browser/chrome_browser_main_android.h"
[email protected]2b12c322013-09-19 06:53:56169#include "chrome/browser/media/encrypted_media_message_filter_android.h"
[email protected]29699c22012-10-03 23:57:39170#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30171#elif defined(OS_POSIX)
172#include "chrome/browser/chrome_browser_main_posix.h"
173#endif
174
[email protected]a220b5932013-09-21 03:47:44175#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:30176#include "base/linux_util.h"
[email protected]73929052013-10-11 12:22:09177#include "chrome/app/breakpad_linux.h"
[email protected]1602cde2012-06-26 15:09:12178#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43179#endif
[email protected]b80f68432011-05-02 17:22:30180
[email protected]1e87df32012-09-12 04:53:19181#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
182#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
183#endif
184
[email protected]29699c22012-10-03 23:57:39185#if defined(OS_ANDROID)
186#include "ui/base/ui_base_paths.h"
187#endif
188
[email protected]37a72af2011-06-13 05:42:01189#if defined(USE_NSS)
190#include "chrome/browser/ui/crypto_module_password_dialog.h"
191#endif
192
[email protected]d5bcd06f2013-04-21 08:07:24193#if !defined(OS_CHROMEOS)
194#include "chrome/browser/signin/signin_manager.h"
195#include "chrome/browser/signin/signin_manager_factory.h"
196#endif
197
[email protected]02250952013-04-24 23:52:53198#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32199#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53200#endif
201
[email protected]6ef98b5a2013-05-31 23:58:31202#if defined(ENABLE_WEBRTC)
203#include "chrome/browser/media/webrtc_logging_handler_host.h"
204#endif
205
[email protected]855e18b2013-07-08 21:02:00206#if defined(ENABLE_INPUT_SPEECH)
207#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
208#endif
209
[email protected]02a3dc122013-06-13 15:07:53210#if defined(FILE_MANAGER_EXTENSION)
[email protected]473c9a4f2013-09-05 03:09:46211#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]02a3dc122013-06-13 15:07:53212#endif
213
[email protected]e8b6ca02013-07-10 18:00:51214#if defined(TOOLKIT_GTK)
215#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
216#endif
217
218#if defined(TOOLKIT_VIEWS)
219#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
220#endif
221
222#if defined(USE_ASH)
223#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
224#endif
225
226#if defined(USE_AURA)
227#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
228#endif
229
230#if defined(USE_X11)
231#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
232#endif
233
[email protected]c6ce08072013-07-31 07:48:53234#if defined(ENABLE_SPELLCHECK)
235#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
236#endif
237
[email protected]190e5e22013-07-27 05:59:23238using WebKit::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08239using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47240using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03241using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39242using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31243using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59244using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08245using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00246using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11247using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33248using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13249using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06250using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34251using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40252using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38253using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39254
[email protected]73929052013-10-11 12:22:09255#if defined(OS_MACOSX)
256using breakpad::IsCrashReporterEnabled;
257#endif
258
[email protected]c5dbef02011-05-13 05:06:09259namespace {
260
[email protected]eabbfb12013-04-05 23:28:35261// Cached version of the locale so we can return the locale on the I/O
262// thread.
263base::LazyInstance<std::string> g_io_thread_application_locale;
264
[email protected]93f72062013-05-29 20:29:40265#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40266const char* kPredefinedAllowedSocketOrigins[] = {
267 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18268 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45269 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
270 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
271 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
272 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35273 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54274 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
275 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
276 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
277 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
278 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
279 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38280 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58281 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29282 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42283 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
284 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
285 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
286 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
287 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
288 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40289};
[email protected]93f72062013-05-29 20:29:40290#endif
[email protected]e461da2f2012-02-16 19:06:40291
[email protected]f8f93eb2012-09-25 03:06:24292// Returns a copy of the given url with its host set to given host and path set
293// to given path. Other parts of the url will be the same.
294GURL ReplaceURLHostAndPath(const GURL& url,
295 const std::string& host,
296 const std::string& path) {
297 url_canon::Replacements<char> replacements;
298 replacements.SetHost(host.c_str(),
299 url_parse::Component(0, host.length()));
300 replacements.SetPath(path.c_str(),
301 url_parse::Component(0, path.length()));
302 return url.ReplaceComponents(replacements);
303}
304
305// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
306GURL AddUberHost(const GURL& url) {
307 const std::string uber_host = chrome::kChromeUIUberHost;
308 const std::string new_path = url.host() + url.path();
309
310 return ReplaceURLHostAndPath(url, uber_host, new_path);
311}
312
[email protected]045bf7c2012-09-28 20:27:36313// If url->host() is "chrome" and url->path() has characters other than the
314// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
315// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24316bool RemoveUberHost(GURL* url) {
317 if (url->host() != chrome::kChromeUIUberHost)
318 return false;
319
[email protected]045bf7c2012-09-28 20:27:36320 if (url->path().empty() || url->path() == "/")
321 return false;
322
[email protected]f8f93eb2012-09-25 03:06:24323 const std::string old_path = url->path();
324
325 const std::string::size_type separator = old_path.find('/', 1);
326 std::string new_host;
327 std::string new_path;
328 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36329 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24330 } else {
331 new_host = old_path.substr(1, separator - 1);
332 new_path = old_path.substr(separator);
333 }
334
[email protected]44e8add2013-06-13 17:29:15335 // Do not allow URLs with paths empty before the first slash since we can't
336 // have an empty host. (e.g "foo://chrome//")
337 if (new_host.empty())
338 return false;
339
[email protected]f8f93eb2012-09-25 03:06:24340 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
341
[email protected]44e8add2013-06-13 17:29:15342 DCHECK(url->is_valid());
343
[email protected]f8f93eb2012-09-25 03:06:24344 return true;
345}
346
[email protected]b8148ac2011-07-13 22:03:25347// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42348bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24349 // Do not handle special URLs such as "about:foo"
350 if (!url->host().empty()) {
351 const GURL chrome_url = AddUberHost(*url);
352
353 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
354 // be called.
355 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
356 browser_context, chrome_url))
357 return true;
358 }
359
[email protected]863f70a2012-01-27 02:05:50360 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
361 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25362 return false;
363
[email protected]fe69558d2012-03-12 11:34:49364#if defined(OS_CHROMEOS)
365 // Special case : in ChromeOS in Guest mode bookmarks and history are
366 // disabled for security reasons. New tab page explains the reasons, so
367 // we redirect user to new tab page.
368 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
369 if (url->SchemeIs(chrome::kChromeUIScheme) &&
370 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
[email protected]b9171622013-10-01 22:05:23371#if defined(ENABLE_ENHANCED_BOOKMARKS)
372 url->DomainIs(chrome::kChromeUIEnhancedBookmarksHost) ||
373#endif
[email protected]fe69558d2012-03-12 11:34:49374 url->DomainIs(chrome::kChromeUIHistoryHost))) {
375 // Rewrite with new tab URL
376 *url = GURL(chrome::kChromeUINewTabURL);
377 }
378 }
379#endif
380
[email protected]b8148ac2011-07-13 22:03:25381 // Special case the new tab page. In older versions of Chrome, the new tab
382 // page was hosted at chrome-internal:<blah>. This might be in people's saved
383 // sessions or bookmarks, so we say any URL with that scheme triggers the new
384 // tab page.
385 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
386 // Rewrite it with the proper new tab URL.
387 *url = GURL(chrome::kChromeUINewTabURL);
388 }
389
390 return true;
391}
392
[email protected]f8f93eb2012-09-25 03:06:24393// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
394// "chrome://foo/".
395bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
396 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
397 return false;
398
399 return RemoveUberHost(url);
400}
401
[email protected]8d3132f62011-10-12 07:13:42402// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
403// below. Extension, and isolated apps require different privileges to be
404// granted to their RenderProcessHosts. This classification allows us to make
405// sure URLs are served by hosts with the right set of privileges.
406enum RenderProcessHostPrivilege {
407 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45408 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42409 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45410 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42411};
412
413RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
414 const GURL& url,
415 ExtensionService* service) {
416 // Default to a normal renderer cause it is lower privileged. This should only
417 // occur if the URL on a site instance is either malformed, or uninitialized.
418 // If it is malformed, then there is no need for better privileges anyways.
419 // If it is uninitialized, but eventually settles on being an a scheme other
420 // than normal webrenderer, the navigation logic will correct us out of band
421 // anyways.
422 if (!url.is_valid())
423 return PRIV_NORMAL;
424
[email protected]885c0e92012-11-13 20:27:42425 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44426 const Extension* extension =
427 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43428 if (extension &&
429 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42430 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45431 if (extension && extension->is_hosted_app())
432 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42433
434 return PRIV_EXTENSION;
435 }
436
437 return PRIV_NORMAL;
438}
439
440RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30441 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46442 extensions::ProcessMap* process_map,
443 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46444 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30445 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46446 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21447 return PRIV_NORMAL;
448
[email protected]6f371442011-11-09 06:45:46449 for (std::set<std::string>::iterator iter = extension_ids.begin();
450 iter != extension_ids.end(); ++iter) {
451 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43452 if (extension &&
453 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42454 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45455 if (extension && extension->is_hosted_app())
456 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42457 }
458
[email protected]676f6ab2011-10-19 20:23:21459 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42460}
461
[email protected]6786bf402011-12-03 15:19:45462bool CertMatchesFilter(const net::X509Certificate& cert,
463 const base::DictionaryValue& filter) {
464 // TODO(markusheintz): This is the minimal required filter implementation.
465 // Implement a better matcher.
466
467 // An empty filter matches any client certificate since no requirements are
468 // specified at all.
469 if (filter.empty())
470 return true;
471
472 std::string common_name;
473 if (filter.GetString("ISSUER.CN", &common_name) &&
474 (cert.issuer().common_name == common_name)) {
475 return true;
476 }
477 return false;
478}
479
[email protected]f3986f82012-01-03 20:00:06480// Fills |map| with the per-script font prefs under path |map_name|.
481void FillFontFamilyMap(const PrefService* prefs,
482 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53483 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]33b79542013-10-18 11:18:45484 // TODO: Get rid of the brute-force scan over possible (font family / script)
485 // combinations - see http://crbug.com/308095.
[email protected]f3986f82012-01-03 20:00:06486 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
487 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
488 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
489 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23490 if (!font_family.empty())
491 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06492 }
493}
494
[email protected]a1733df2012-06-22 11:24:18495#if defined(OS_POSIX) && !defined(OS_MACOSX)
496int GetCrashSignalFD(const CommandLine& command_line) {
497 if (command_line.HasSwitch(switches::kExtensionProcess)) {
498 ExtensionCrashHandlerHostLinux* crash_handler =
499 ExtensionCrashHandlerHostLinux::GetInstance();
500 return crash_handler->GetDeathSignalSocket();
501 }
502
503 std::string process_type =
504 command_line.GetSwitchValueASCII(switches::kProcessType);
505
506 if (process_type == switches::kRendererProcess)
507 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
508
509 if (process_type == switches::kPluginProcess)
510 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
511
512 if (process_type == switches::kPpapiPluginProcess)
513 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
514
515 if (process_type == switches::kGpuProcess)
516 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
517
518 return -1;
519}
520#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
521
[email protected]d5bcd06f2013-04-21 08:07:24522#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30523GURL GetEffectiveURLForSignin(const GURL& url) {
524 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
525
526 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03527 // Copy the path because the argument to SetPathStr must outlive
528 // the Replacements object.
529 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30530 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03531 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30532 effective_url = effective_url.ReplaceComponents(replacements);
533 return effective_url;
534}
[email protected]d5bcd06f2013-04-21 08:07:24535#endif
[email protected]970c63e2013-03-07 00:25:30536
[email protected]eabbfb12013-04-05 23:28:35537void SetApplicationLocaleOnIOThread(const std::string& locale) {
538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
539 g_io_thread_application_locale.Get() = locale;
540}
541
[email protected]916615b2013-09-11 18:19:44542void HandleBlockedPopupOnUIThread(const BlockedWindowParams& params) {
543 WebContents* tab = tab_util::GetWebContentsByID(params.render_process_id(),
544 params.opener_id());
[email protected]190e5e22013-07-27 05:59:23545 if (!tab)
546 return;
547
[email protected]190e5e22013-07-27 05:59:23548 PopupBlockerTabHelper* popup_helper =
549 PopupBlockerTabHelper::FromWebContents(tab);
550 if (!popup_helper)
551 return;
[email protected]916615b2013-09-11 18:19:44552 popup_helper->AddBlockedPopup(params);
[email protected]190e5e22013-07-27 05:59:23553}
[email protected]190e5e22013-07-27 05:59:23554
[email protected]916615b2013-09-11 18:19:44555#if defined(OS_ANDROID)
556void HandleSingleTabModeBlockOnUIThread(const BlockedWindowParams& params) {
557 WebContents* web_contents =
558 tab_util::GetWebContentsByID(params.render_process_id(),
559 params.opener_id());
560 if (!web_contents)
561 return;
562
563 SingleTabModeTabHelper::FromWebContents(web_contents)->HandleOpenUrl(params);
564}
565#endif // defined(OS_ANDROID)
566
[email protected]9dbfff12011-07-01 19:37:07567} // namespace
[email protected]c5dbef02011-05-13 05:06:09568
[email protected]d977f9c2011-03-14 16:10:26569namespace chrome {
570
[email protected]e461da2f2012-02-16 19:06:40571ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40572#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40573 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
574 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40575#endif
[email protected]1deace22013-05-22 06:14:46576
577 permissions_policy_delegate_.reset(
578 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40579}
580
581ChromeContentBrowserClient::~ChromeContentBrowserClient() {
582}
583
[email protected]bca18382012-06-25 19:15:23584// static
[email protected]37ca3fe02013-07-05 15:32:44585void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34586 user_prefs::PrefRegistrySyncable* registry) {
587 registry->RegisterBooleanPref(
588 prefs::kDisable3DAPIs,
589 false,
590 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
591 registry->RegisterBooleanPref(
592 prefs::kEnableHyperlinkAuditing,
593 true,
594 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
595 registry->RegisterBooleanPref(
596 prefs::kEnableMemoryInfo,
597 false,
598 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23599}
600
[email protected]eabbfb12013-04-05 23:28:35601// static
602void ChromeContentBrowserClient::SetApplicationLocale(
603 const std::string& locale) {
604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
605
606 // This object is guaranteed to outlive all threads so we don't have to
607 // worry about the lack of refcounting and can just post as Unretained.
608 //
609 // The common case is that this function is called early in Chrome startup
610 // before any threads are created (it will also be called later if the user
611 // changes the pref). In this case, there will be no threads created and
612 // posting will fail. When there are no threads, we can just set the string
613 // without worrying about threadsafety.
614 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
615 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
616 g_io_thread_application_locale.Get() = locale;
617 }
618}
619
[email protected]50462bf02011-11-21 19:13:31620content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
621 const content::MainFunctionParams& parameters) {
622 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30623 // Construct the Main browser parts based on the OS type.
624#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31625 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04626#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31627 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30628#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22629 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26630#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31631 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14632#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09633 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30634#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31635 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04636#else
[email protected]b48c9182011-10-26 18:03:30637 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31638 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30639#endif
640
[email protected]7e75e4a2013-05-17 17:20:03641 chrome::AddProfilesExtraParts(main_parts);
642
[email protected]c7480942011-11-08 19:18:27643 // Construct additional browser parts. Stages are called in the order in
644 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22645#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51646 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04647#endif
[email protected]c7480942011-11-08 19:18:27648
649#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51650 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27651#endif
652
[email protected]dc04be7c2012-03-15 23:57:49653#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51654 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49655#endif
656
[email protected]e050ef142012-03-21 01:04:24657#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51658 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
659#endif
660
661#if defined(USE_X11)
662 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24663#endif
664
[email protected]95132f52013-04-12 02:19:04665 chrome::AddMetricsExtraParts(main_parts);
666
[email protected]50462bf02011-11-21 19:13:31667 return main_parts;
[email protected]f967b722011-09-07 00:58:04668}
669
[email protected]e94bbcb2012-09-07 05:33:57670std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19671 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57672 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53673 std::string partition_id;
674
675 // The partition ID for webview guest processes is the string value of its
676 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
[email protected]6eb1a11e2013-10-09 00:54:37677 if (site.SchemeIs(content::kGuestScheme))
[email protected]1bc28312012-11-08 08:31:53678 partition_id = site.spec();
679
[email protected]056efdc2013-04-06 00:14:53680 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53681 return partition_id;
682}
683
684bool ChromeContentBrowserClient::IsValidStoragePartitionId(
685 content::BrowserContext* browser_context,
686 const std::string& partition_id) {
687 // The default ID is empty and is always valid.
688 if (partition_id.empty())
689 return true;
690
691 return GURL(partition_id).is_valid();
692}
693
694void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
695 content::BrowserContext* browser_context,
696 const GURL& site,
[email protected]14acc642012-11-17 12:20:10697 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53698 std::string* partition_domain,
699 std::string* partition_name,
700 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10701 // Default to the browser-wide storage partition and override based on |site|
702 // below.
703 partition_domain->clear();
704 partition_name->clear();
705 *in_memory = false;
706
[email protected]1bc28312012-11-08 08:31:53707 // For the webview tag, we create special guest processes, which host the
708 // tag content separately from the main application that embeds the tag.
709 // A webview tag can specify both the partition name and whether the storage
710 // for that partition should be persisted. Each tag gets a SiteInstance with
711 // a specially formatted URL, based on the application it is hosted by and
712 // the partition requested by it. The format for that URL is:
713 // chrome-guest://partition_domain/persist?partition_name
[email protected]6eb1a11e2013-10-09 00:54:37714 if (site.SchemeIs(content::kGuestScheme)) {
[email protected]1bc28312012-11-08 08:31:53715 // Since guest URLs are only used for packaged apps, there must be an app
716 // id in the URL.
717 CHECK(site.has_host());
718 *partition_domain = site.host();
719 // Since persistence is optional, the path must either be empty or the
720 // literal string.
721 *in_memory = (site.path() != "/persist");
722 // The partition name is user supplied value, which we have encoded when the
723 // URL was created, so it needs to be decoded.
724 *partition_name = net::UnescapeURLComponent(site.query(),
725 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10726 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
727 // If |can_be_default| is false, the caller is stating that the |site|
728 // should be parsed as if it had isolated storage. In particular it is
729 // important to NOT check ExtensionService for the is_storage_isolated()
730 // attribute because this code path is run during Extension uninstall
731 // to do cleanup after the Extension has already been unloaded from the
732 // ExtensionService.
733 bool is_isolated = !can_be_default;
734 if (can_be_default) {
735 const Extension* extension = NULL;
736 Profile* profile = Profile::FromBrowserContext(browser_context);
737 ExtensionService* extension_service =
738 extensions::ExtensionSystem::Get(profile)->extension_service();
739 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55740 extension =
741 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43742 if (extension &&
743 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10744 is_isolated = true;
745 }
746 }
747 }
[email protected]1bc28312012-11-08 08:31:53748
[email protected]14acc642012-11-17 12:20:10749 if (is_isolated) {
750 CHECK(site.has_host());
751 // For extensions with isolated storage, the the host of the |site| is
752 // the |partition_domain|. The |in_memory| and |partition_name| are only
753 // used in guest schemes so they are cleared here.
754 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53755 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10756 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53757 }
[email protected]d1198fd2012-08-13 22:50:19758 }
759
[email protected]14acc642012-11-17 12:20:10760 // Assert that if |can_be_default| is false, the code above must have found a
761 // non-default partition. If this fails, the caller has a serious logic
762 // error about which StoragePartition they expect to be in and it is not
763 // safe to continue.
764 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44765}
766
[email protected]38b098f2012-03-14 21:11:57767content::WebContentsViewDelegate*
768 ChromeContentBrowserClient::GetWebContentsViewDelegate(
769 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27770 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32771}
772
[email protected]738f57a2013-06-29 21:06:54773void ChromeContentBrowserClient::GuestWebContentsCreated(
774 WebContents* guest_web_contents,
775 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22776 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54777 scoped_ptr<base::DictionaryValue> extra_params) {
778 if (opener_web_contents) {
779 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
780 if (!guest) {
781 NOTREACHED();
782 return;
783 }
784
[email protected]50c827d2013-09-13 21:36:09785 // Create a new GuestView of the same type as the opener.
786 *guest_delegate =
787 GuestView::Create(guest_web_contents, guest->GetViewType());
[email protected]738f57a2013-06-29 21:06:54788 return;
789 }
790
791 if (!extra_params) {
792 NOTREACHED();
793 return;
794 }
795 std::string api_type;
[email protected]90547d72013-08-06 05:57:27796 extra_params->GetString(guestview::kParameterApi, &api_type);
[email protected]738f57a2013-06-29 21:06:54797
[email protected]50c827d2013-09-13 21:36:09798 *guest_delegate =
799 GuestView::Create(guest_web_contents,
800 GuestView::GetViewTypeFromString(api_type));
[email protected]738f57a2013-06-29 21:06:54801}
802
[email protected]44295a12013-06-05 08:45:46803void ChromeContentBrowserClient::GuestWebContentsAttached(
804 WebContents* guest_web_contents,
805 WebContents* embedder_web_contents,
[email protected]22aa4f82013-09-24 17:01:44806 const GURL& embedder_frame_url,
[email protected]5715566a2013-06-25 00:04:53807 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06808 Profile* profile = Profile::FromBrowserContext(
809 embedder_web_contents->GetBrowserContext());
810 ExtensionService* service =
811 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54812 if (!service) {
813 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06814 return;
[email protected]738f57a2013-06-29 21:06:54815 }
[email protected]22aa4f82013-09-24 17:01:44816
[email protected]c4927882013-09-26 04:19:09817 // We usually require BrowserPlugins to be hosted by a storage isolated
818 // extension. We treat WebUI pages as a special case if they host the
819 // BrowserPlugin in a component extension iframe. In that case, we use the
[email protected]22aa4f82013-09-24 17:01:44820 // iframe's URL to determine the extension.
821 const GURL& embedder_site_url =
822 embedder_web_contents->GetSiteInstance()->GetSiteURL();
823 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
824 content::HasWebUIScheme(embedder_site_url) ?
825 embedder_frame_url : embedder_site_url);
[email protected]738f57a2013-06-29 21:06:54826 if (!extension) {
[email protected]efd6fb02013-08-05 04:44:06827 // It's ok to return here, since we could be running a browser plugin
828 // outside an extension, and don't need to attach a
829 // BrowserPluginGuestDelegate in that case;
830 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
[email protected]738f57a2013-06-29 21:06:54831 return;
[email protected]18699372013-06-25 20:42:55832 }
[email protected]738f57a2013-06-29 21:06:54833
834 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
835 if (!guest) {
836 NOTREACHED();
837 return;
838 }
[email protected]9934a5e2013-08-22 00:07:56839 guest->Attach(embedder_web_contents, extension->id(), extra_params);
[email protected]44703cc72013-01-24 04:56:06840}
841
[email protected]f3b1a082011-11-18 00:34:30842void ChromeContentBrowserClient::RenderProcessHostCreated(
843 content::RenderProcessHost* host) {
844 int id = host->GetID();
845 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41846 net::URLRequestContextGetter* context =
847 profile->GetRequestContextForRenderProcess(id);
848
[email protected]ba780c12013-10-01 17:07:06849 host->AddFilter(new ChromeRenderMessageFilter(id, profile, context));
[email protected]ebd71962012-12-20 02:56:55850#if defined(ENABLE_PLUGINS)
[email protected]ba780c12013-10-01 17:07:06851 host->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55852#endif
[email protected]658677f2012-06-09 06:04:02853#if defined(ENABLE_PRINTING)
[email protected]ba780c12013-10-01 17:07:06854 host->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03855#endif
[email protected]ba780c12013-10-01 17:07:06856 host->AddFilter(new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53857#if defined(ENABLE_SPELLCHECK)
[email protected]ba780c12013-10-01 17:07:06858 host->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53859#endif
[email protected]7ceb99012011-12-21 08:05:56860#if defined(OS_MACOSX)
[email protected]ba780c12013-10-01 17:07:06861 host->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56862#endif
[email protected]ba780c12013-10-01 17:07:06863 host->AddFilter(new ChromeNetBenchmarkingMessageFilter(
[email protected]43535512013-02-20 20:41:41864 id, profile, context));
[email protected]ba780c12013-10-01 17:07:06865 host->AddFilter(new prerender::PrerenderMessageFilter(id, profile));
866 host->AddFilter(new ValidationMessageMessageFilter(id));
867 host->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31868#if defined(ENABLE_WEBRTC)
[email protected]10e5c5e52013-10-03 18:44:06869 WebRtcLoggingHandlerHost* webrtc_logging_handler_host =
870 new WebRtcLoggingHandlerHost();
871 host->AddFilter(webrtc_logging_handler_host);
872 host->SetUserData(host, new base::UserDataAdapter<WebRtcLoggingHandlerHost>(
873 webrtc_logging_handler_host));
[email protected]6ef98b5a2013-05-31 23:58:31874#endif
[email protected]01e59752013-06-18 00:17:35875#if !defined(DISABLE_NACL)
[email protected]ba780c12013-10-01 17:07:06876 host->AddFilter(new NaClHostMessageFilter(
[email protected]14230ca2013-06-26 23:33:03877 id, profile->IsOffTheRecord(),
[email protected]a2b4c5c2013-10-18 02:06:07878 profile->GetPath(),
[email protected]14230ca2013-06-26 23:33:03879 context));
[email protected]01e59752013-06-18 00:17:35880#endif
[email protected]2b12c322013-09-19 06:53:56881#if defined(OS_ANDROID)
[email protected]ba780c12013-10-01 17:07:06882 host->AddFilter(new EncryptedMediaMessageFilterAndroid());
[email protected]2b12c322013-09-19 06:53:56883#endif
[email protected]3e69bc82011-05-26 23:22:38884
[email protected]2ccf45c2011-08-19 23:35:50885 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
886 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07887
888 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56889
890 RendererContentSettingRules rules;
891 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
892 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14893}
894
[email protected]3d7474ff2011-07-27 17:47:37895GURL ChromeContentBrowserClient::GetEffectiveURL(
896 content::BrowserContext* browser_context, const GURL& url) {
897 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52898 if (!profile)
899 return url;
900
[email protected]b3cb3a32013-07-31 01:32:29901 // If the input |url| should be assigned to the Instant renderer, make its
902 // effective URL distinct from other URLs on the search provider's domain.
903 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
904 return chrome::GetEffectiveURLForInstant(url, profile);
905
[email protected]d5bcd06f2013-04-21 08:07:24906#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30907 // If the input |url| should be assigned to the Signin renderer, make its
908 // effective URL distinct from other URLs on the signin service's domain.
909 // Note that the signin renderer will be allowed to sign the user in to
910 // Chrome.
911 if (SigninManager::IsWebBasedSigninFlowURL(url))
912 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24913#endif
[email protected]970c63e2013-03-07 00:25:30914
[email protected]c5dec6292013-01-25 04:54:52915 // If the input |url| is part of an installed app, the effective URL is an
916 // extension URL with the ID of that extension as the host. This has the
917 // effect of grouping apps together in a common SiteInstance.
918 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13919 extensions::ExtensionSystem::Get(profile)->extension_service();
920 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08921 return url;
922
[email protected]06bdd2b2012-11-30 18:47:13923 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55924 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08925 if (!extension)
926 return url;
927
[email protected]15877ca2011-11-18 22:40:52928 // Bookmark apps do not use the hosted app process model, and should be
929 // treated as normal URLs.
930 if (extension->from_bookmark())
931 return url;
932
[email protected]36fb2c7c2011-04-04 15:49:08933 // If the URL is part of an extension's web extent, convert it to an
934 // extension URL.
935 return extension->GetResourceURL(url.path());
936}
937
[email protected]056ad2a2011-07-12 02:13:55938bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37939 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52940 // Non-extension, non-Instant URLs should generally use
941 // process-per-site-instance. Because we expect to use the effective URL,
942 // URLs for hosted apps (apart from bookmark apps) should have an extension
943 // scheme by now.
944
945 Profile* profile = Profile::FromBrowserContext(browser_context);
946 if (!profile)
947 return false;
948
[email protected]df113a12013-07-24 04:56:08949 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52950 return true;
951
[email protected]d5bcd06f2013-04-21 08:07:24952#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30953 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
954 return true;
[email protected]d5bcd06f2013-04-21 08:07:24955#endif
[email protected]970c63e2013-03-07 00:25:30956
[email protected]885c0e92012-11-13 20:27:42957 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55958 return false;
959
[email protected]c5dec6292013-01-25 04:54:52960 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13961 extensions::ExtensionSystem::Get(profile)->extension_service();
962 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55963 return false;
964
[email protected]be9915fb2013-07-18 09:28:55965 const Extension* extension =
966 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:55967 if (!extension)
968 return false;
969
970 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53971 // permission, or that does not allow JavaScript access to the background
972 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55973 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40974 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06975 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29976 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53977 return false;
978 }
979 }
[email protected]056ad2a2011-07-12 02:13:55980
[email protected]7b54ca02012-03-02 18:06:53981 // Hosted apps that have script access to their background page must use
982 // process per site, since all instances can make synchronous calls to the
983 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55984 return true;
985}
986
[email protected]672c8c12013-03-07 12:30:06987// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41988void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
989 std::vector<std::string>* additional_schemes) {
990 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06991}
992
[email protected]6bd30072013-02-08 18:17:11993net::URLRequestContextGetter*
994ChromeContentBrowserClient::CreateRequestContext(
995 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06996 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11997 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06998 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11999}
1000
1001net::URLRequestContextGetter*
1002ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1003 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:401004 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:111005 bool in_memory,
[email protected]672c8c12013-03-07 12:30:061006 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111007 Profile* profile = Profile::FromBrowserContext(browser_context);
1008 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:061009 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111010}
1011
[email protected]46fb9442011-12-09 17:57:471012bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1013 return ProfileIOData::IsHandledURL(url);
1014}
1015
[email protected]c4365fa42013-05-14 01:08:241016bool ChromeContentBrowserClient::CanCommitURL(
1017 content::RenderProcessHost* process_host,
1018 const GURL& url) {
1019 // We need to let most extension URLs commit in any process, since this can
1020 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1021 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1022 // cannot be loaded in iframes and should never be requested outside its
1023 // process.
1024 Profile* profile =
1025 Profile::FromBrowserContext(process_host->GetBrowserContext());
1026 ExtensionService* service =
1027 extensions::ExtensionSystem::Get(profile)->extension_service();
1028 if (!service)
1029 return true;
1030 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551031 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241032 if (new_extension &&
1033 new_extension->is_hosted_app() &&
1034 new_extension->id() == extension_misc::kWebStoreAppId &&
1035 !service->process_map()->Contains(new_extension->id(),
1036 process_host->GetID())) {
1037 return false;
1038 }
1039
1040 return true;
1041}
1042
[email protected]9a60d1602013-09-11 04:09:121043bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1044 content::SiteInstance* site_instance, const GURL& url) {
1045 GURL from_url = site_instance->GetSiteURL();
1046 // Do not allow pages from the web or other extensions navigate to
1047 // non-web-accessible extension resources.
1048 if (url.SchemeIs(extensions::kExtensionScheme) &&
1049 (from_url.SchemeIsHTTPOrHTTPS() ||
1050 from_url.SchemeIs(extensions::kExtensionScheme))) {
1051 Profile* profile = Profile::FromBrowserContext(
1052 site_instance->GetProcess()->GetBrowserContext());
1053 ExtensionService* service =
1054 extensions::ExtensionSystem::Get(profile)->extension_service();
1055 if (!service)
1056 return true;
1057 const Extension* extension =
1058 service->extensions()->GetExtensionOrAppByURL(url);
1059 if (!extension)
1060 return true;
1061 const Extension* from_extension =
1062 service->extensions()->GetExtensionOrAppByURL(
1063 site_instance->GetSiteURL());
1064 if (from_extension && from_extension->id() == extension->id())
1065 return true;
1066
1067 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1068 extension, url.path()))
1069 return false;
1070 }
1071 return true;
1072}
1073
[email protected]2a5221b2011-09-27 23:07:311074bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301075 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311076 const GURL& site_url) {
1077 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301078 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521079 // This may be NULL during tests. In that case, just assume any site can
1080 // share any host.
1081 if (!profile)
1082 return true;
1083
[email protected]d43f99fe2013-04-03 00:20:141084 // Instant URLs should only be in the instant process and instant process
1085 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521086 InstantService* instant_service =
1087 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141088 if (instant_service) {
1089 bool is_instant_process = instant_service->IsInstantProcess(
1090 process_host->GetID());
1091 bool should_be_in_instant_process =
1092 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1093 if (is_instant_process || should_be_in_instant_process)
1094 return is_instant_process && should_be_in_instant_process;
1095 }
[email protected]c5dec6292013-01-25 04:54:521096
[email protected]d5bcd06f2013-04-21 08:07:241097#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301098 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1099 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1100 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241101#endif
[email protected]970c63e2013-03-07 00:25:301102
[email protected]06bdd2b2012-11-30 18:47:131103 ExtensionService* service =
1104 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461105 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311106
[email protected]ffa97602011-11-17 17:55:521107 // Don't allow the Task Manager to share a process with anything else.
1108 // Otherwise it can affect the renderers it is observing.
1109 // Note: we could create another RenderProcessHostPrivilege bucket for
1110 // this to allow multiple chrome://tasks instances to share, but that's
1111 // a very unlikely case without serious consequences.
1112 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1113 return false;
1114
[email protected]8d3132f62011-10-12 07:13:421115 // These may be NULL during tests. In that case, just assume any site can
1116 // share any host.
[email protected]6f371442011-11-09 06:45:461117 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311118 return true;
1119
[email protected]eec0b33c2011-12-05 22:09:451120 // Otherwise, just make sure the process privilege matches the privilege
1121 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571122 RenderProcessHostPrivilege privilege_required =
1123 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451124 return GetProcessPrivilege(process_host, process_map, service) ==
1125 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311126}
1127
[email protected]76411f412012-02-22 18:56:061128// This function is trying to limit the amount of processes used by extensions
1129// with background pages. It uses a globally set percentage of processes to
1130// run such extensions and if the limit is exceeded, it returns true, to
1131// indicate to the content module to group extensions together.
1132bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1133 content::BrowserContext* browser_context, const GURL& url) {
1134 // It has to be a valid URL for us to check for an extension.
1135 if (!url.is_valid())
1136 return false;
1137
1138 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191139 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131140 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061141 if (!service)
1142 return false;
1143
1144 // We have to have a valid extension with background page to proceed.
1145 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551146 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061147 if (!extension)
1148 return false;
[email protected]9367eabc2013-03-01 01:29:291149 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061150 return false;
1151
1152 std::set<int> process_ids;
1153 size_t max_process_count =
1154 content::RenderProcessHost::GetMaxRendererProcessCount();
1155
1156 // Go through all profiles to ensure we have total count of extension
1157 // processes containing background pages, otherwise one profile can
1158 // starve the other.
1159 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1160 GetLoadedProfiles();
1161 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031162 ExtensionProcessManager* epm =
1163 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321164 for (ExtensionProcessManager::const_iterator iter =
1165 epm->background_hosts().begin();
1166 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131167 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321168 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061169 }
1170 }
1171
1172 if (process_ids.size() >
1173 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1174 return true;
1175 }
1176
1177 return false;
1178}
1179
[email protected]6f371442011-11-09 06:45:461180void ChromeContentBrowserClient::SiteInstanceGotProcess(
1181 SiteInstance* site_instance) {
1182 CHECK(site_instance->HasProcess());
1183
1184 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021185 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521186 if (!profile)
1187 return;
1188
1189 // Remember the ID of the Instant process to signal the renderer process
1190 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031191 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321192 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521193 InstantService* instant_service =
1194 InstantServiceFactory::GetForProfile(profile);
1195 if (instant_service)
1196 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1197 }
1198
[email protected]d5bcd06f2013-04-21 08:07:241199#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301200 // We only expect there to be one signin process as we use process-per-site
1201 // for signin URLs. The signin process will be cleared from SigninManager
1202 // when the renderer is destroyed.
1203 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1204 SigninManager* signin_manager =
1205 SigninManagerFactory::GetForProfile(profile);
1206 if (signin_manager)
1207 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461208 BrowserThread::PostTask(
1209 BrowserThread::IO, FROM_HERE,
1210 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1211 extensions::ExtensionSystem::Get(profile)->info_map(),
1212 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301213 }
[email protected]d5bcd06f2013-04-21 08:07:241214#endif
[email protected]970c63e2013-03-07 00:25:301215
[email protected]06bdd2b2012-11-30 18:47:131216 ExtensionService* service =
1217 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461218 if (!service)
1219 return;
1220
[email protected]be9915fb2013-07-18 09:28:551221 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1222 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461223 if (!extension)
1224 return;
1225
[email protected]6bc04fd82011-12-04 02:29:351226 service->process_map()->Insert(extension->id(),
1227 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331228 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461229 BrowserThread::PostTask(
1230 BrowserThread::IO, FROM_HERE,
1231 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591232 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461233 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351234 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331235 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461236}
1237
1238void ChromeContentBrowserClient::SiteInstanceDeleting(
1239 SiteInstance* site_instance) {
1240 if (!site_instance->HasProcess())
1241 return;
1242
1243 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021244 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131245 ExtensionService* service =
1246 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461247 if (!service)
1248 return;
1249
[email protected]be9915fb2013-07-18 09:28:551250 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1251 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461252 if (!extension)
1253 return;
1254
[email protected]6bc04fd82011-12-04 02:29:351255 service->process_map()->Remove(extension->id(),
1256 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331257 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461258 BrowserThread::PostTask(
1259 BrowserThread::IO, FROM_HERE,
1260 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591261 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461262 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351263 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331264 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461265}
1266
[email protected]f05763972012-06-06 18:17:261267bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141268 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081269 const GURL& current_url,
1270 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261271 if (current_url.is_empty()) {
1272 // Always choose a new process when navigating to extension URLs. The
1273 // process grouping logic will combine all of a given extension's pages
1274 // into the same process.
[email protected]885c0e92012-11-13 20:27:421275 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261276 return true;
[email protected]e3daf3c2011-10-05 21:17:081277
[email protected]f05763972012-06-06 18:17:261278 return false;
1279 }
1280
1281 // Also, we must switch if one is an extension and the other is not the exact
1282 // same extension.
[email protected]885c0e92012-11-13 20:27:421283 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1284 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261285 if (current_url.GetOrigin() != new_url.GetOrigin())
1286 return true;
1287 }
1288
[email protected]e9841fbd2013-02-22 23:12:141289 // The checks below only matter if we can retrieve which extensions are
1290 // installed.
1291 Profile* profile =
1292 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1293 ExtensionService* service =
1294 extensions::ExtensionSystem::Get(profile)->extension_service();
1295 if (!service)
1296 return false;
1297
1298 // We must swap if the URL is for an extension and we are not using an
1299 // extension process.
1300 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551301 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141302 // Ignore all hosted apps except the Chrome Web Store, since they do not
1303 // require their own BrowsingInstance (e.g., postMessage is ok).
1304 if (new_extension &&
1305 new_extension->is_hosted_app() &&
1306 new_extension->id() != extension_misc::kWebStoreAppId)
1307 new_extension = NULL;
1308 if (new_extension &&
1309 site_instance->HasProcess() &&
1310 !service->process_map()->Contains(new_extension->id(),
1311 site_instance->GetProcess()->GetID()))
1312 return true;
1313
[email protected]f05763972012-06-06 18:17:261314 return false;
[email protected]e3daf3c2011-10-05 21:17:081315}
1316
[email protected]395045c2012-05-22 15:04:381317bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1318 content::ResourceContext* resource_context, const GURL& current_url,
1319 const GURL& new_url) {
1320 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1321 return extensions::CrossesExtensionProcessBoundary(
1322 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551323 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381324}
1325
[email protected]3d831992013-07-04 01:13:291326bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1327 return !url.SchemeIs(chrome::kChromeNativeScheme);
1328}
1329
[email protected]763ec4ca2011-04-29 15:48:121330std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1331 const std::string& alias_name) {
1332 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1333}
1334
[email protected]b80f68432011-05-02 17:22:301335void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1336 CommandLine* command_line, int child_process_id) {
[email protected]264c0acac2013-10-01 13:33:301337#if defined(OS_POSIX)
[email protected]b80f68432011-05-02 17:22:301338 if (IsCrashReporterEnabled()) {
[email protected]264c0acac2013-10-01 13:33:301339 std::string enable_crash_reporter;
1340 GoogleUpdateSettings::GetMetricsId(&enable_crash_reporter);
1341#if !defined(OS_MACOSX)
1342 enable_crash_reporter += "," + base::GetLinuxDistro();
1343#endif
[email protected]b80f68432011-05-02 17:22:301344 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
[email protected]264c0acac2013-10-01 13:33:301345 enable_crash_reporter);
[email protected]b80f68432011-05-02 17:22:301346 }
[email protected]264c0acac2013-10-01 13:33:301347#endif // OS_POSIX
[email protected]b80f68432011-05-02 17:22:301348
[email protected]f1933792011-06-14 00:49:341349 if (logging::DialogsAreSuppressed())
1350 command_line->AppendSwitch(switches::kNoErrorDialogs);
1351
[email protected]b80f68432011-05-02 17:22:301352 std::string process_type =
1353 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171354 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321355
[email protected]7c9b6f92013-09-10 18:11:351356 static const char* const kCommonSwitchNames[] = {
1357 switches::kChromeFrame,
1358 switches::kUserDataDir, // Make logs go to the right file.
1359 };
1360 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1361 arraysize(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:321362
[email protected]718eab62011-10-05 21:16:521363 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:301364#if defined(OS_CHROMEOS)
1365 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441366 browser_command_line.GetSwitchValueASCII(
1367 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301368 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441369 command_line->AppendSwitchASCII(
1370 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301371#endif
1372
[email protected]f3b1a082011-11-18 00:34:301373 content::RenderProcessHost* process =
1374 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371375 if (process) {
1376 Profile* profile = Profile::FromBrowserContext(
1377 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131378 ExtensionService* extension_service =
1379 extensions::ExtensionSystem::Get(profile)->extension_service();
1380 if (extension_service) {
1381 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001382 if (process_map && process_map->Contains(process->GetID()))
1383 command_line->AppendSwitch(switches::kExtensionProcess);
1384 }
[email protected]b80f68432011-05-02 17:22:301385
[email protected]a8d851f82011-12-21 00:32:371386 PrefService* prefs = profile->GetPrefs();
1387 // Currently this pref is only registered if applied via a policy.
1388 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1389 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1390 // Turn this policy into a command line switch.
1391 command_line->AppendSwitch(switches::kDisable3DAPIs);
1392 }
[email protected]718eab62011-10-05 21:16:521393
[email protected]a8d851f82011-12-21 00:32:371394 // Disable client-side phishing detection in the renderer if it is
1395 // disabled in the Profile preferences or the browser process.
1396 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1397 !g_browser_process->safe_browsing_detection_service()) {
1398 command_line->AppendSwitch(
1399 switches::kDisableClientSidePhishingDetection);
1400 }
[email protected]0045b0f42012-07-26 11:52:081401
1402 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211403 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521404
1405 InstantService* instant_service =
1406 InstantServiceFactory::GetForProfile(profile);
1407 if (instant_service &&
1408 instant_service->IsInstantProcess(process->GetID()))
1409 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301410
[email protected]d5bcd06f2013-04-21 08:07:241411#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301412 SigninManager* signin_manager =
1413 SigninManagerFactory::GetForProfile(profile);
1414 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1415 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241416#endif
[email protected]47c7ec82012-01-18 03:29:211417 }
[email protected]4287a3d2011-06-13 23:56:511418
[email protected]16dc42452013-04-09 04:37:191419 if (message_center::IsRichNotificationEnabled())
1420 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191421
[email protected]47c7ec82012-01-18 03:29:211422 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511423 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171424 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431425 autofill::switches::kDisablePasswordGeneration,
[email protected]e217c5632013-04-12 19:11:481426 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171427 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]c3cc0632013-10-03 21:54:431428 autofill::switches::kEnablePasswordGeneration,
[email protected]5c42c372013-10-17 15:06:101429 autofill::switches::kNoAutofillNecessaryForPasswordGeneration,
[email protected]49d9b142013-07-19 08:50:271430 extensions::switches::kAllowLegacyExtensionManifests,
1431 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511432 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271433 extensions::switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511434 switches::kAllowHTTPBackgroundPage,
[email protected]9d450492013-06-13 23:08:371435 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1436 // to browser.
1437 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511438 switches::kAppsCheckoutURL,
1439 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311440 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511441 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501442 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531443 switches::kDisableExtensionsResourceWhitelist,
[email protected]83c85262013-08-22 21:13:461444 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111445 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531446 switches::kEnableAdview,
1447 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441448 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211449 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511450 switches::kEnableIPCFuzzing,
1451 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451452 switches::kEnableNetBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511453 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511454 switches::kMemoryProfiling,
1455 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371456 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371457 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511458 switches::kPpapiFlashArgs,
1459 switches::kPpapiFlashInProcess,
1460 switches::kPpapiFlashPath,
1461 switches::kPpapiFlashVersion,
1462 switches::kProfilingAtStart,
1463 switches::kProfilingFile,
1464 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371465 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511466 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291467 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381468 switches::kWhitelistedExtensionID,
[email protected]499e7c52013-10-04 16:03:091469 translate::switches::kTranslateSecurityOrigin,
[email protected]4287a3d2011-06-13 23:56:511470 };
1471
1472 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1473 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171474 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381475 static const char* const kSwitchNames[] = {
[email protected]c8d02992013-07-31 22:16:511476 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271477 extensions::switches::kExtensionsOnChromeURLs,
[email protected]eb653f82012-05-24 02:31:351478 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381479 switches::kWhitelistedExtensionID,
1480 };
1481
1482 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1483 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511484 } else if (process_type == switches::kPluginProcess) {
1485 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441486#if defined(OS_CHROMEOS)
1487 chromeos::switches::kLoginProfile,
1488#endif
[email protected]4287a3d2011-06-13 23:56:511489 switches::kMemoryProfiling,
1490 switches::kSilentDumpOnDCHECK,
[email protected]4287a3d2011-06-13 23:56:511491 };
1492
1493 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1494 arraysize(kSwitchNames));
1495 } else if (process_type == switches::kZygoteProcess) {
1496 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511497 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501498 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511499 switches::kPpapiFlashInProcess,
1500 switches::kPpapiFlashPath,
1501 switches::kPpapiFlashVersion,
1502 };
1503
1504 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1505 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111506 } else if (process_type == switches::kGpuProcess) {
1507 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1508 // because GPU is expected to be unreliable.
1509 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1510 !command_line->HasSwitch(switches::kDisableBreakpad))
1511 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301512 }
[email protected]6f08af82011-09-15 01:19:031513
1514 // The command line switch kEnableBenchmarking needs to be specified along
1515 // with the kEnableStatsTable switch to ensure that the stats table global
1516 // is initialized correctly.
1517 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1518 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301519}
1520
1521std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431522 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351523 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301524 return g_browser_process->GetApplicationLocale();
1525}
1526
[email protected]597a867b2011-11-18 18:31:201527std::string ChromeContentBrowserClient::GetAcceptLangs(
1528 content::BrowserContext* context) {
1529 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371530 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081531}
1532
[email protected]9ec0f452012-05-31 15:58:531533gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221534 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531535 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081536}
1537
[email protected]a2176792011-05-08 19:30:491538bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091539 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191540 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201541 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321542 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201543 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051544 return io_data->GetCookieSettings()->
1545 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491546}
1547
[email protected]ed24fad2011-05-10 22:44:011548bool ChromeContentBrowserClient::AllowGetCookie(
1549 const GURL& url,
1550 const GURL& first_party,
1551 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201552 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011553 int render_process_id,
1554 int render_view_id) {
1555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201556 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051557 bool allow = io_data->GetCookieSettings()->
1558 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011559
[email protected]8093a542011-05-13 07:29:321560 BrowserThread::PostTask(
1561 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031562 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431563 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011564 return allow;
1565}
1566
1567bool ChromeContentBrowserClient::AllowSetCookie(
1568 const GURL& url,
1569 const GURL& first_party,
1570 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201571 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011572 int render_process_id,
1573 int render_view_id,
1574 net::CookieOptions* options) {
1575 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201576 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051577 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1578 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1579
[email protected]8093a542011-05-13 07:29:321580 BrowserThread::PostTask(
1581 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031582 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431583 render_view_id, url, first_party, cookie_line, *options,
1584 !allow));
[email protected]ed24fad2011-05-10 22:44:011585 return allow;
1586}
1587
[email protected]d5a19162011-06-30 18:51:541588bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201589 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201591 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431592 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1593 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261594
[email protected]bf510ed2012-06-05 08:31:431595 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1596 // Could we even support per-origin settings?
1597 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541598}
1599
[email protected]5c5a88e2011-11-12 00:45:351600bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351601 const GURL& url,
1602 const string16& name,
1603 const string16& display_name,
1604 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201605 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481606 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201608 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351609 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1610 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1611
[email protected]62151052012-02-01 18:40:481612 // Record access to database for potential display in UI.
1613 std::vector<std::pair<int, int> >::const_iterator i;
1614 for (i = render_views.begin(); i != render_views.end(); ++i) {
1615 BrowserThread::PostTask(
1616 BrowserThread::UI, FROM_HERE,
1617 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1618 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351619 }
1620
1621 return allow;
1622}
1623
1624bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351625 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201626 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481627 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351628 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201629 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351630 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1631 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1632
[email protected]62151052012-02-01 18:40:481633 // Record access to file system for potential display in UI.
1634 std::vector<std::pair<int, int> >::const_iterator i;
1635 for (i = render_views.begin(); i != render_views.end(); ++i) {
1636 BrowserThread::PostTask(
1637 BrowserThread::UI, FROM_HERE,
1638 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1639 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351640 }
1641
1642 return allow;
1643}
1644
[email protected]7c5ff9a2012-03-02 07:42:491645bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1646 const GURL& url,
1647 const string16& name,
1648 content::ResourceContext* context,
1649 const std::vector<std::pair<int, int> >& render_views) {
1650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1651 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1652 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1653 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1654
1655 // Record access to IndexedDB for potential display in UI.
1656 std::vector<std::pair<int, int> >::const_iterator i;
1657 for (i = render_views.begin(); i != render_views.end(); ++i) {
1658 BrowserThread::PostTask(
1659 BrowserThread::UI, FROM_HERE,
1660 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1661 i->first, i->second, url, name, !allow));
1662 }
1663
1664 return allow;
1665}
1666
[email protected]33ad6ce92013-08-27 14:39:081667net::URLRequestContext*
1668ChromeContentBrowserClient::OverrideRequestContextForURL(
1669 const GURL& url, content::ResourceContext* context) {
1670 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1671 if (url.SchemeIs(extensions::kExtensionScheme)) {
1672 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1673 return io_data->extensions_request_context();
1674 }
1675
1676 return NULL;
1677}
1678
[email protected]317f96c92011-05-31 06:53:411679QuotaPermissionContext*
1680ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1681 return new ChromeQuotaPermissionContext();
1682}
1683
[email protected]848dd042011-06-04 18:24:031684void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171685 int render_process_id,
1686 int render_view_id,
1687 int cert_error,
1688 const net::SSLInfo& ssl_info,
1689 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021690 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031691 bool overridable,
[email protected]d9be47702012-05-16 03:41:221692 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171693 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001694 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021695 if (resource_type != ResourceType::MAIN_FRAME) {
1696 // A sub-resource has a certificate error. The user doesn't really
1697 // have a context for making the right decision, so block the
1698 // request hard, without an info bar to allow showing the insecure
1699 // content.
[email protected]8c965c22013-05-23 19:28:001700 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021701 return;
1702 }
1703
[email protected]f9034cf2011-07-21 12:43:411704 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131705 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171706 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411707 if (!tab) {
1708 NOTREACHED();
1709 return;
1710 }
1711 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501712 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301713 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011714 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1715 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411716 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171717 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411718 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001719 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411720 return;
1721 }
1722 }
1723
[email protected]1e87df32012-09-12 04:53:191724#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231725 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1726 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1727 if (captive_portal_tab_helper)
1728 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191729#endif
1730
[email protected]f9034cf2011-07-21 12:43:411731 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221732 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1733 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031734}
1735
[email protected]c99c442e2011-08-24 11:37:301736void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451737 int render_process_id,
1738 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401739 const net::HttpNetworkSession* network_session,
1740 net::SSLCertRequestInfo* cert_request_info,
1741 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131742 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451743 render_process_id, render_view_id);
1744 if (!tab) {
1745 NOTREACHED();
1746 return;
1747 }
1748
[email protected]6786bf402011-12-03 15:19:451749 GURL requesting_url("https://" + cert_request_info->host_and_port);
1750 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1751 << cert_request_info->host_and_port;
1752
[email protected]627e0512011-12-21 22:55:301753 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451754 scoped_ptr<Value> filter(
1755 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1756 requesting_url,
1757 requesting_url,
1758 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1759 std::string(), NULL));
1760
1761 if (filter.get()) {
1762 // Try to automatically select a client certificate.
1763 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1764 DictionaryValue* filter_dict =
1765 static_cast<DictionaryValue*>(filter.get());
1766
1767 const std::vector<scoped_refptr<net::X509Certificate> >&
1768 all_client_certs = cert_request_info->client_certs;
1769 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091770 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451771 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091772 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451773 return;
1774 }
1775 }
1776 } else {
1777 NOTREACHED();
1778 }
1779 }
1780
[email protected]11feec322012-09-18 03:58:521781 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1782 if (!ssl_tab_helper) {
1783 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451784 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141785 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401786 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451787 return;
1788 }
[email protected]11feec322012-09-18 03:58:521789 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401790 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451791}
1792
[email protected]3b455502012-12-11 18:22:581793void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451794 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581795 net::CertificateMimeType cert_type,
1796 const void* cert_data,
1797 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451798 int render_process_id,
1799 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581800 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1801 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451802}
1803
[email protected]dc73a7b2012-03-25 15:27:181804content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561805 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181806}
1807
[email protected]941623e2011-06-07 23:06:041808void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1809 const GURL& source_origin,
1810 int callback_context,
1811 int render_process_id,
1812 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111813#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1815 WebContents* contents =
1816 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1817 if (!contents) {
[email protected]941623e2011-06-07 23:06:041818 NOTREACHED();
1819 return;
1820 }
1821
[email protected]d0d9c3ee2012-06-19 03:07:021822 // Skip showing the infobar if the request comes from an extension, and that
1823 // extension has the 'notify' permission. (If the extension does not have the
1824 // permission, the user will still be prompted.)
1825 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011826 ExtensionInfoMap* extension_info_map =
1827 extensions::ExtensionSystem::Get(profile)->info_map();
1828 DesktopNotificationService* notification_service =
1829 DesktopNotificationServiceFactory::GetForProfile(profile);
1830 const Extension* extension = NULL;
1831 if (extension_info_map) {
1832 ExtensionSet extensions;
1833 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1834 source_origin, render_process_id,
1835 extensions::APIPermission::kNotification, &extensions);
1836 for (ExtensionSet::const_iterator iter = extensions.begin();
1837 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381838 if (notification_service->IsNotifierEnabled(NotifierId(
1839 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361840 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011841 break;
1842 }
1843 }
1844 }
[email protected]eb4832a2012-12-08 01:57:521845 RenderViewHost* rvh =
1846 RenderViewHost::FromID(render_process_id, render_view_id);
1847 if (IsExtensionWithPermissionOrSuggestInConsole(
1848 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021849 if (rvh)
1850 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1851 return;
1852 }
1853
[email protected]c7cd5942013-04-30 03:31:011854 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021855 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111856#else
1857 NOTIMPLEMENTED();
1858#endif
[email protected]941623e2011-06-07 23:06:041859}
1860
1861WebKit::WebNotificationPresenter::Permission
1862 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021863 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201864 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021865 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111866#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481868 // Sometimes a notification may be invoked during the shutdown.
1869 // See http://crbug.com/256638
1870 if (browser_shutdown::IsTryingToQuit())
1871 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
1872
[email protected]df02aca2012-02-09 21:03:201873 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041874
[email protected]c7cd5942013-04-30 03:31:011875 DesktopNotificationService* notification_service =
1876 io_data->GetNotificationService();
1877 if (notification_service) {
1878 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1879 ExtensionSet extensions;
1880 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1881 source_origin, render_process_id,
1882 extensions::APIPermission::kNotification, &extensions);
1883 for (ExtensionSet::const_iterator iter = extensions.begin();
1884 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381885 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
1886 if (notification_service->IsNotifierEnabled(notifier_id))
[email protected]c7cd5942013-04-30 03:31:011887 return WebKit::WebNotificationPresenter::PermissionAllowed;
1888 }
1889
1890 return notification_service->HasPermission(source_origin);
1891 }
1892
1893 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111894#else
1895 return WebKit::WebNotificationPresenter::PermissionAllowed;
1896#endif
[email protected]941623e2011-06-07 23:06:041897}
1898
1899void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171900 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041901 int render_process_id,
1902 int render_view_id,
1903 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111904#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041905 RenderViewHost* rvh = RenderViewHost::FromID(
1906 render_process_id, render_view_id);
1907 if (!rvh) {
1908 NOTREACHED();
1909 return;
1910 }
1911
[email protected]9f76c1e2012-03-05 15:15:581912 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301913 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041914 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371915 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041916 service->ShowDesktopNotification(
1917 params, render_process_id, render_view_id,
1918 worker ? DesktopNotificationService::WorkerNotification :
1919 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111920#else
1921 NOTIMPLEMENTED();
1922#endif
[email protected]941623e2011-06-07 23:06:041923}
1924
1925void ChromeContentBrowserClient::CancelDesktopNotification(
1926 int render_process_id,
1927 int render_view_id,
1928 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111929#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041930 RenderViewHost* rvh = RenderViewHost::FromID(
1931 render_process_id, render_view_id);
1932 if (!rvh) {
1933 NOTREACHED();
1934 return;
1935 }
1936
[email protected]9f76c1e2012-03-05 15:15:581937 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301938 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041939 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371940 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041941 service->CancelDesktopNotification(
1942 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111943#else
1944 NOTIMPLEMENTED();
1945#endif
[email protected]941623e2011-06-07 23:06:041946}
1947
[email protected]9f3fba52011-06-08 20:37:191948bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351949 const GURL& opener_url,
[email protected]931bc922013-09-11 21:42:571950 const GURL& opener_top_level_frame_url,
[email protected]34eec7ffe32011-11-02 23:49:021951 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191952 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:231953 const GURL& target_url,
1954 const content::Referrer& referrer,
1955 WindowOpenDisposition disposition,
1956 const WebWindowFeatures& features,
1957 bool user_gesture,
1958 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:201959 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011960 int render_process_id,
[email protected]190e5e22013-07-27 05:59:231961 bool is_guest,
1962 int opener_id,
[email protected]03b6d552012-03-29 04:03:011963 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191964 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011965
1966 *no_javascript_access = false;
1967
[email protected]5e5f55e262c52013-09-12 00:27:191968 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1969 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1970
[email protected]9f3fba52011-06-08 20:37:191971 // If the opener is trying to create a background window but doesn't have
1972 // the appropriate permission, fail the attempt.
[email protected]6940eef82013-09-11 11:58:411973 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]03b6d552012-03-29 04:03:011974 if (!map->SecurityOriginHasAPIPermission(
1975 source_origin,
1976 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061977 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011978 return false;
1979 }
1980
[email protected]7b54ca02012-03-02 18:06:531981 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1982 // return a recently installed Extension even if this CanCreateWindow call
1983 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011984 // because the permission check above would have caused an early return
1985 // already. We must use the full URL to find hosted apps, though, and not
1986 // just the origin.
[email protected]be9915fb2013-07-18 09:28:551987 const Extension* extension =
1988 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:291989 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011990 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:231991
1992 return true;
[email protected]9f3fba52011-06-08 20:37:191993 }
[email protected]056efdc2013-04-06 00:14:531994
1995 // No new browser window (popup or tab) in app mode.
1996 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1997 chrome::IsRunningInForcedAppMode()) {
1998 return false;
1999 }
2000
[email protected]d2bac6b2013-08-13 03:42:362001 if (g_browser_process->prerender_tracker() &&
2002 g_browser_process->prerender_tracker()->TryCancelOnIOThread(
2003 render_process_id,
2004 opener_id,
2005 prerender::FINAL_STATUS_CREATE_NEW_WINDOW)) {
2006 return false;
2007 }
2008
[email protected]190e5e22013-07-27 05:59:232009 if (is_guest)
2010 return true;
2011
[email protected]190e5e22013-07-27 05:59:232012 HostContentSettingsMap* content_settings =
2013 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
[email protected]916615b2013-09-11 18:19:442014 BlockedWindowParams blocked_params(target_url,
2015 referrer,
2016 disposition,
2017 features,
2018 user_gesture,
2019 opener_suppressed,
2020 render_process_id,
2021 opener_id);
[email protected]190e5e22013-07-27 05:59:232022
[email protected]7f53dff2013-08-05 10:45:502023 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch(
2024 switches::kDisablePopupBlocking)) {
[email protected]931bc922013-09-11 21:42:572025 if (content_settings->GetContentSetting(opener_top_level_frame_url,
2026 opener_top_level_frame_url,
[email protected]190e5e22013-07-27 05:59:232027 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]916615b2013-09-11 18:19:442028 std::string()) !=
[email protected]190e5e22013-07-27 05:59:232029 CONTENT_SETTING_ALLOW) {
[email protected]916615b2013-09-11 18:19:442030 BrowserThread::PostTask(BrowserThread::UI,
2031 FROM_HERE,
2032 base::Bind(&HandleBlockedPopupOnUIThread,
2033 blocked_params));
2034 return false;
[email protected]190e5e22013-07-27 05:59:232035 }
[email protected]916615b2013-09-11 18:19:442036 }
[email protected]190e5e22013-07-27 05:59:232037
[email protected]916615b2013-09-11 18:19:442038#if defined(OS_ANDROID)
2039 if (SingleTabModeTabHelper::IsRegistered(render_process_id, opener_id)) {
[email protected]190e5e22013-07-27 05:59:232040 BrowserThread::PostTask(BrowserThread::UI,
2041 FROM_HERE,
[email protected]916615b2013-09-11 18:19:442042 base::Bind(&HandleSingleTabModeBlockOnUIThread,
2043 blocked_params));
[email protected]190e5e22013-07-27 05:59:232044 return false;
2045 }
[email protected]916615b2013-09-11 18:19:442046#endif
[email protected]190e5e22013-07-27 05:59:232047
[email protected]9f3fba52011-06-08 20:37:192048 return true;
2049}
2050
2051std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202052 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192053 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2054 // Check if it's an extension-created worker, in which case we want to use
2055 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202056 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192057 const Extension* extension =
2058 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2059 return extension ? extension->name() : std::string();
2060}
2061
[email protected]99907362012-01-11 05:41:402062void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2063 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172064}
2065
[email protected]7a06d282013-05-03 04:39:332066// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022067content::SpeechRecognitionManagerDelegate*
2068 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002069#if defined(ENABLE_INPUT_SPEECH)
2070 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322071#else
[email protected]855e18b2013-07-08 21:02:002072 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2073 // need the base delegate without the bubble UI.
2074 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322075#endif
[email protected]66cfec62012-02-24 17:57:512076}
2077
[email protected]ae6e9912011-07-27 01:18:282078net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2079 return g_browser_process->net_log();
2080}
2081
[email protected]32538d92011-08-25 00:09:232082AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2083 return new ChromeAccessTokenStore();
2084}
2085
[email protected]dbae6b02011-06-29 23:51:412086bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012087 return true;
[email protected]dbae6b02011-06-29 23:51:412088}
2089
[email protected]64d69de42012-02-06 00:19:542090void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322091 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062092 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582093 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062094 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062095
[email protected]33b79542013-10-18 11:18:452096 // Fill per-script font preferences. These are not registered on Android
2097 // - http://crbug.com/308033.
2098#if !defined(OS_ANDROID)
[email protected]f3986f82012-01-03 20:00:062099 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542100 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062101 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542102 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062103 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542104 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062105 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542106 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062107 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542108 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062109 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542110 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032111 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2112 &web_prefs->pictograph_font_family_map);
[email protected]33b79542013-10-18 11:18:452113#endif
[email protected]f3986f82012-01-03 20:00:062114
[email protected]64d69de42012-02-06 00:19:542115 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402116 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542117 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402118 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542119 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402120 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542121 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402122 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062123
[email protected]ddf72142012-05-22 04:52:402124 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062125
[email protected]64d69de42012-02-06 00:19:542126 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402127 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542128 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062129 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542130 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062131 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2132 const DictionaryValue* inspector_settings =
2133 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2134 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182135 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2136 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062137 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182138 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542139 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182140 std::make_pair(iter.key(), value));
2141 }
[email protected]f3986f82012-01-03 20:00:062142 }
2143 }
[email protected]64d69de42012-02-06 00:19:542144 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062145
[email protected]ddf72142012-05-22 04:52:402146 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542147 web_prefs->javascript_enabled = false;
2148 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2149 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402150 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542151 web_prefs->plugins_enabled = false;
2152 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2153 web_prefs->java_enabled = false;
2154 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402155 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062156
[email protected]64d69de42012-02-06 00:19:542157 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2158 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062159
[email protected]64d69de42012-02-06 00:19:542160 web_prefs->memory_info_enabled =
2161 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2162 web_prefs->allow_displaying_insecure_content =
2163 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2164 web_prefs->allow_running_insecure_content =
2165 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322166#if defined(OS_ANDROID)
2167 web_prefs->font_scale_factor =
2168 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2169 web_prefs->force_enable_zoom =
2170 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2171#endif
[email protected]5c915252013-05-07 13:15:392172
[email protected]af4256d52013-06-04 20:39:072173#if defined(OS_ANDROID)
2174 web_prefs->password_echo_enabled =
2175 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2176#else
[email protected]9d06d88d2012-02-23 22:37:082177 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072178#endif
2179
[email protected]5c915252013-05-07 13:15:392180#if defined(OS_CHROMEOS)
2181 // Enable password echo during OOBE when keyboard driven flag is set.
2182 if (chromeos::UserManager::IsInitialized() &&
2183 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
[email protected]c94ac692013-07-27 00:50:102184 !chromeos::StartupUtils::IsOobeCompleted() &&
2185 chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation()) {
2186 web_prefs->password_echo_enabled = true;
[email protected]5c915252013-05-07 13:15:392187 }
2188#endif
[email protected]f3986f82012-01-03 20:00:062189
[email protected]46f8e742013-05-03 18:37:142190#if defined(OS_ANDROID)
2191 web_prefs->user_style_sheet_enabled = false;
2192#else
[email protected]64d69de42012-02-06 00:19:542193 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152194 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362195 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152196 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542197 web_prefs->user_style_sheet_enabled = true;
2198 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152199 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542200 } else {
2201 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062202 }
[email protected]46f8e742013-05-03 18:37:142203#endif
[email protected]f3986f82012-01-03 20:00:062204
[email protected]cfadadd2013-04-03 04:43:022205 web_prefs->asynchronous_spell_checking_enabled = true;
2206 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572207
[email protected]64d69de42012-02-06 00:19:542208 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062209 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542210 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062211 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542212 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062213 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2214
2215 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542216 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062217 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542218 web_prefs->default_encoding);
2219 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402220 prefs->ClearPref(prefs::kDefaultCharset);
2221 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062222 }
[email protected]64d69de42012-02-06 00:19:542223 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062224
[email protected]299d7f12012-05-23 05:31:152225 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232226 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132227 ExtensionService* service =
2228 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062229 if (service) {
[email protected]1bc28312012-11-08 08:31:532230 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2231 const Extension* extension = service->extensions()->GetByID(url.host());
2232 // Ensure that we are only granting extension preferences to URLs with
2233 // the correct scheme. Without this check, chrome-guest:// schemes used by
2234 // webview tags as well as hosts that happen to match the id of an
2235 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422236 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532237 extension_webkit_preferences::SetPreferences(
2238 extension, view_type, web_prefs);
2239 }
[email protected]f3986f82012-01-03 20:00:062240 }
2241
[email protected]cb2edf22013-04-01 20:25:232242 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542243 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232244 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062245 // Disable all kinds of acceleration for background pages.
2246 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542247 web_prefs->force_compositing_mode = false;
2248 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062249 }
[email protected]2e21fe292012-03-02 22:52:322250
2251#if defined(FILE_MANAGER_EXTENSION)
2252 // Override the default of suppressing HW compositing for WebUI pages for the
2253 // file manager, which is implemented using WebUI but wants HW acceleration
2254 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532255 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]2de96a52013-08-14 01:18:092256 url.host() == file_manager::kFileManagerAppId) {
[email protected]2e21fe292012-03-02 22:52:322257 web_prefs->accelerated_compositing_enabled = true;
2258 web_prefs->accelerated_2d_canvas_enabled = true;
2259 }
2260#endif
[email protected]181a95ee2011-07-12 19:26:362261}
2262
2263void ChromeContentBrowserClient::UpdateInspectorSetting(
2264 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062265 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582266 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062267 DictionaryPrefUpdate update(
2268 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2269 prefs::kWebKitInspectorSettings);
2270 DictionaryValue* inspector_settings = update.Get();
2271 inspector_settings->SetWithoutPathExpansion(key,
2272 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362273}
2274
[email protected]b8148ac2011-07-13 22:03:252275void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2276 BrowserURLHandler* handler) {
2277 // Add the default URL handlers.
2278 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2279 BrowserURLHandler::null_handler());
2280 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2281 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2282
[email protected]b3adbd02011-11-30 22:23:272283 // about: handler. Must come before chrome: handler, since it will
2284 // rewrite about: urls to chrome: URLs and then expect chrome: to
2285 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252286 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2287 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032288
2289 // Handler to rewrite chrome://newtab for InstantExtended.
2290 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2291 &chrome::HandleNewTabURLReverseRewrite);
2292
[email protected]b8148ac2011-07-13 22:03:252293 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242294 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252295}
2296
2297void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372298 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582299 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472300 BrowsingDataRemover* remover =
2301 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552302 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2303 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252304 // BrowsingDataRemover takes care of deleting itself when done.
2305}
2306
2307void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372308 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582309 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472310 BrowsingDataRemover* remover =
2311 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232312 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552313 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252314 // BrowsingDataRemover takes care of deleting itself when done.
2315}
2316
[email protected]650b2d52013-02-10 03:41:452317base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:492318 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:322319}
2320
[email protected]c9b6eb62011-10-18 20:49:392321std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2322 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2323}
2324
[email protected]b7631cc2012-09-15 05:08:382325void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2326 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542327#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382328 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2329 scoped_ptr<ppapi::host::HostFactory>(
2330 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542331#endif
[email protected]b7631cc2012-09-15 05:08:382332}
2333
[email protected]0c7193742012-11-07 19:05:032334content::BrowserPpapiHost*
2335 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2336 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132337 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032338 while (!iter.Done()) {
2339 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2340 if (host->process() &&
2341 host->process()->GetData().id == plugin_process_id) {
2342 // Found the plugin.
2343 return host->browser_ppapi_host();
2344 }
2345 ++iter;
2346 }
2347 return NULL;
2348}
2349
[email protected]7b38b192013-03-23 18:39:312350bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2351 content::BrowserContext* browser_context, const GURL& site_url) {
2352 if (CommandLine::ForCurrentProcess()->HasSwitch(
2353 switches::kEnableBrowserPluginForAllViewTypes))
2354 return true;
2355
[email protected]22aa4f82013-09-24 17:01:442356 if (content::HasWebUIScheme(site_url))
2357 return true;
2358
[email protected]7b38b192013-03-23 18:39:312359 Profile* profile = Profile::FromBrowserContext(browser_context);
2360 ExtensionService* service =
2361 extensions::ExtensionSystem::Get(profile)->extension_service();
2362 if (!service)
2363 return false;
2364
[email protected]be9915fb2013-07-18 09:28:552365 const Extension* extension =
2366 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312367 if (!extension)
2368 return false;
2369
[email protected]c2d2f102013-04-29 16:42:582370 return extension->HasAPIPermission(APIPermission::kWebView) ||
2371 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312372}
2373
[email protected]38cd8f7f2012-06-15 22:06:072374bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582375 content::BrowserContext* browser_context,
2376 const GURL& url,
[email protected]dda54822013-06-15 01:26:392377 bool private_api,
[email protected]8b92ed182013-09-21 04:47:122378 const content::SocketPermissionRequest* params) {
[email protected]93f72062013-05-29 20:29:402379#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372380 Profile* profile = Profile::FromBrowserContext(browser_context);
2381 const ExtensionSet* extension_set = NULL;
2382 if (profile) {
2383 extension_set = extensions::ExtensionSystem::Get(profile)->
2384 extension_service()->extensions();
2385 }
[email protected]dda54822013-06-15 01:26:392386
2387 if (private_api) {
2388 // Access to private socket APIs is controlled by the whitelist.
2389 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2390 allowed_socket_origins_)) {
2391 return true;
2392 }
2393 } else {
2394 // Access to public socket APIs is controlled by extension permissions.
2395 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2396 extension_set) {
2397 const Extension* extension = extension_set->GetByID(url.host());
2398 if (extension) {
[email protected]8b92ed182013-09-21 04:47:122399 if (params) {
2400 extensions::SocketPermission::CheckParam check_params(
2401 params->type, params->host, params->port);
2402 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2403 extension, extensions::APIPermission::kSocket,
2404 &check_params)) {
2405 return true;
2406 }
2407 } else {
2408 if (extensions::PermissionsData::HasAPIPermission(
2409 extension, extensions::APIPermission::kSocket)) {
2410 return true;
2411 }
[email protected]dda54822013-06-15 01:26:392412 }
2413 }
2414 }
2415 }
2416
2417 // Allow both public and private APIs if the command line says so.
2418 return IsHostAllowedByCommandLine(url, extension_set,
2419 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402420#else
[email protected]a658d452012-03-02 12:45:292421 return false;
[email protected]93f72062013-05-29 20:29:402422#endif
[email protected]e461da2f2012-02-16 19:06:402423}
2424
[email protected]a28e3302013-02-03 03:50:432425ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2426 WebContents* web_contents) {
2427 return new ChromeSelectFilePolicy(web_contents);
2428}
2429
[email protected]7d9424702013-04-14 13:14:162430void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2431 std::vector<std::string>* additional_allowed_schemes) {
2432 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2433 additional_allowed_schemes);
2434 additional_allowed_schemes->push_back(kChromeUIScheme);
2435 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2436}
2437
[email protected]f19bbf62013-07-09 01:22:322438void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312439 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532440 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322441 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532442#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032443 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322444 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032445 storage_partition_path,
2446 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322447 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532448#endif
[email protected]b40015c2013-06-26 08:13:312449#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312450 fileapi::ExternalMountPoints* external_mount_points =
2451 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312452 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322453 chromeos::FileSystemBackend* backend =
2454 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312455 new drive::FileSystemBackendDelegate(browser_context),
2456 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312457 external_mount_points,
2458 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322459 backend->AddSystemMountPoints();
2460 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2461 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312462#endif
[email protected]445b7db2013-08-02 04:58:272463
[email protected]e86e2be2013-08-30 11:20:392464 additional_backends->push_back(
2465 new sync_file_system::SyncFileSystemBackend(
2466 Profile::FromBrowserContext(browser_context)));
[email protected]02250952013-04-24 23:52:532467}
2468
[email protected]e60c0232011-11-11 19:56:352469#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182470void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2471 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382472 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082473 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392474#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452475 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392476 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2477 DCHECK(!data_path.empty());
2478
2479 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452480 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392481 data_path.AppendASCII("chrome_100_percent.pak");
[email protected]5db2b7492013-08-23 05:33:092482 base::PlatformFile f =
2483 base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
[email protected]29699c22012-10-03 23:57:392484 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372485 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392486 FileDescriptor(f, true)));
2487
2488 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452489 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392490 GetLocaleFilePath(locale, false);
2491 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2492 DCHECK(f != base::kInvalidPlatformFileValue);
2493 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2494 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382495
[email protected]650b2d52013-02-10 03:41:452496 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372497 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2498 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2499 DCHECK(f != base::kInvalidPlatformFileValue);
2500 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2501 FileDescriptor(f, true)));
2502
[email protected]82174aa2013-01-22 21:53:432503 if (IsCrashReporterEnabled()) {
2504 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2505 if (f == base::kInvalidPlatformFileValue) {
2506 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2507 "be disabled for this process.";
2508 } else {
2509 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2510 FileDescriptor(f, true)));
2511 }
[email protected]40da3e0c2012-10-24 22:03:382512 }
[email protected]40da3e0c2012-10-24 22:03:382513
2514#else
2515 int crash_signal_fd = GetCrashSignalFD(command_line);
2516 if (crash_signal_fd >= 0) {
2517 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2518 FileDescriptor(crash_signal_fd,
2519 false)));
2520 }
[email protected]29699c22012-10-03 23:57:392521#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302522}
[email protected]e60c0232011-11-11 19:56:352523#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302524
[email protected]4a65826d2011-08-25 16:04:012525#if defined(OS_WIN)
2526const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2527 return chrome::kBrowserResourcesDll;
2528}
[email protected]34f48682013-03-20 00:30:182529
2530void ChromeContentBrowserClient::PreSpawnRenderer(
2531 sandbox::TargetPolicy* policy,
2532 bool* success) {
2533 // This code is duplicated in nacl_exe_win_64.cc.
2534 // Allow the server side of a pipe restricted to the "chrome.nacl."
2535 // namespace so that it cannot impersonate other system or other chrome
2536 // service pipes.
2537 sandbox::ResultCode result = policy->AddRule(
2538 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2539 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2540 L"\\\\.\\pipe\\chrome.nacl.*");
2541 if (result != sandbox::SBOX_ALL_OK) {
2542 *success = false;
2543 return;
2544 }
2545
2546 // Renderers need to send named pipe handles and shared memory
2547 // segment handles to NaCl loader processes.
2548 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2549 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2550 L"File");
2551 if (result != sandbox::SBOX_ALL_OK) {
2552 *success = false;
2553 return;
2554 }
2555}
[email protected]4a65826d2011-08-25 16:04:012556#endif
2557
[email protected]37a72af2011-06-13 05:42:012558#if defined(USE_NSS)
2559crypto::CryptoModuleBlockingPasswordDelegate*
2560 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2561 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292562 return chrome::NewCryptoModuleBlockingDialogDelegate(
2563 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012564}
2565#endif
2566
[email protected]a6868c22013-10-09 02:50:292567bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle(
2568 content::BrowserContext* browser_context,
2569 const GURL& url) {
2570#if defined(ENABLE_PLUGINS)
2571 Profile* profile = Profile::FromBrowserContext(browser_context);
2572 const ExtensionSet* extension_set = NULL;
2573 if (profile) {
2574 extension_set = extensions::ExtensionSystem::Get(profile)->
2575 extension_service()->extensions();
2576 }
2577 // TODO(teravest): Populate allowed_file_handle_origins_ when FileIO is moved
2578 // from the renderer to the browser.
2579 return IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2580 allowed_file_handle_origins_) ||
2581 IsHostAllowedByCommandLine(url, extension_set,
2582 switches::kAllowNaClFileHandleAPI);
2583#else
2584 return false;
2585#endif
2586}
2587
[email protected]d977f9c2011-03-14 16:10:262588} // namespace chrome