blob: 380aa2af72c5514cb2d7b29bf21dbac1b9d9d6fa [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]eabbfb12013-04-05 23:28:3513#include "base/lazy_instance.h"
[email protected]29699c22012-10-03 23:57:3914#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5715#include "base/prefs/pref_service.h"
[email protected]e7463412013-06-10 22:53:4616#include "base/strings/string_number_conversions.h"
[email protected]135cb802013-06-09 16:44:2017#include "base/strings/utf_string_conversions.h"
[email protected]30a306f42013-06-10 03:09:0318#include "base/threading/sequenced_worker_pool.h"
[email protected]b80f68432011-05-02 17:22:3019#include "chrome/app/breakpad_mac.h"
[email protected]056efdc2013-04-06 00:14:5320#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]b8148ac2011-07-13 22:03:2521#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3022#include "chrome/browser/browser_process.h"
[email protected]5c129792013-07-10 02:08:4823#include "chrome/browser/browser_shutdown.h"
[email protected]b0cb5e82012-07-19 19:22:4724#include "chrome/browser/browsing_data/browsing_data_helper.h"
25#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1226#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4127#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4128#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5629#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0530#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4531#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3232#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0833#include "chrome/browser/defaults.h"
[email protected]b1d97272013-08-17 13:38:4934#include "chrome/browser/download/download_prefs.h"
[email protected]17263b22013-05-16 03:29:2235#include "chrome/browser/extensions/activity_log/activity_log.h"
[email protected]2b33dcd02012-03-18 01:34:1636#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]1deace22013-05-22 06:14:4637#include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
[email protected]76411f412012-02-22 18:56:0638#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0439#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3340#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2641#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0842#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2543#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0644#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5245#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2346#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1247#include "chrome/browser/google/google_util.h"
[email protected]0533cc6d2013-06-27 22:44:0548#include "chrome/browser/guestview/adview/adview_guest.h"
49#include "chrome/browser/guestview/guestview_constants.h"
50#include "chrome/browser/guestview/webview/webview_guest.h"
[email protected]11158e2d2013-02-01 02:31:5651#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0452#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]01e59752013-06-18 00:17:3553#include "chrome/browser/nacl_host/nacl_host_message_filter.h"
[email protected]0c7193742012-11-07 19:05:0354#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2855#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0456#include "chrome/browser/notifications/desktop_notification_service.h"
57#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4258#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5659#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0660#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]190e5e22013-07-27 05:59:2361#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4162#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5063#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0764#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4165#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1466#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0367#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1468#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3269#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0670#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1471#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3872#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4373#include "chrome/browser/search/instant_service.h"
74#include "chrome/browser/search/instant_service_factory.h"
75#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1476#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0277#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3378#include "chrome/browser/speech/tts_message_filter.h"
[email protected]3b455502012-12-11 18:22:5879#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0380#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5281#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]180c66a62013-08-05 12:01:3682#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:4583#include "chrome/browser/tab_contents/tab_util.h"
[email protected]a28e3302013-02-03 03:50:4384#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2585#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4486#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5087#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0688#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1589#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2790#include "chrome/browser/validation_message_message_filter.h"
[email protected]b80f68432011-05-02 17:22:3091#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0192#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1493#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3094#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2995#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0496#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3897#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4498#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4399#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:29100#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]dda54822013-06-15 01:26:39101#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]157cc902012-11-02 06:31:58102#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:34103#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37104#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12105#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38106#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09107#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53108#include "chromeos/chromeos_constants.h"
[email protected]d5d383252013-07-04 14:44:32109#include "components/nacl/common/nacl_process_type.h"
[email protected]75fee372013-03-06 00:42:44110#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43111#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30112#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38113#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03114#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31115#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03116#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59117#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:30118#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33119#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05120#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33121#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19122#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10123#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43124#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18125#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23126#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42127#include "extensions/common/constants.h"
[email protected]49d9b142013-07-19 08:50:27128#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39129#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23130#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53131#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58132#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34133#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06134#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57135#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38136#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39137#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08138#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24139#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31140#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18141#include "webkit/common/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:26142
[email protected]b48c9182011-10-26 18:03:30143#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38144#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18145#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38146#elif defined(OS_MACOSX)
147#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56148#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30149#elif defined(OS_CHROMEOS)
150#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]f19bbf62013-07-09 01:22:32151#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h"
152#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39153#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49154#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10155#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44156#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26157#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30158#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09159#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38160#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09161#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39162#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30163#elif defined(OS_POSIX)
164#include "chrome/browser/chrome_browser_main_posix.h"
165#endif
166
[email protected]6653c192012-04-10 22:52:44167#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30168#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12169#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43170#endif
[email protected]b80f68432011-05-02 17:22:30171
[email protected]190e5e22013-07-27 05:59:23172#if !defined(OS_ANDROID)
173#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
174#endif
175
[email protected]1e87df32012-09-12 04:53:19176#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
177#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
178#endif
179
[email protected]29699c22012-10-03 23:57:39180#if defined(OS_ANDROID)
181#include "ui/base/ui_base_paths.h"
182#endif
183
[email protected]37a72af2011-06-13 05:42:01184#if defined(USE_NSS)
185#include "chrome/browser/ui/crypto_module_password_dialog.h"
186#endif
187
[email protected]d5bcd06f2013-04-21 08:07:24188#if !defined(OS_CHROMEOS)
189#include "chrome/browser/signin/signin_manager.h"
190#include "chrome/browser/signin/signin_manager_factory.h"
191#endif
192
[email protected]02250952013-04-24 23:52:53193#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32194#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53195#endif
196
[email protected]6ef98b5a2013-05-31 23:58:31197#if defined(ENABLE_WEBRTC)
198#include "chrome/browser/media/webrtc_logging_handler_host.h"
199#endif
200
[email protected]855e18b2013-07-08 21:02:00201#if defined(ENABLE_INPUT_SPEECH)
202#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
203#endif
204
[email protected]02a3dc122013-06-13 15:07:53205#if defined(FILE_MANAGER_EXTENSION)
[email protected]2de96a52013-08-14 01:18:09206#include "chrome/browser/chromeos/extensions/file_manager/app_id.h"
[email protected]02a3dc122013-06-13 15:07:53207#endif
208
[email protected]e8b6ca02013-07-10 18:00:51209#if defined(TOOLKIT_GTK)
210#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
211#endif
212
213#if defined(TOOLKIT_VIEWS)
214#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
215#endif
216
217#if defined(USE_ASH)
218#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
219#endif
220
221#if defined(USE_AURA)
222#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
223#endif
224
225#if defined(USE_X11)
226#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
227#endif
228
[email protected]c6ce08072013-07-31 07:48:53229#if defined(ENABLE_SPELLCHECK)
230#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
231#endif
232
[email protected]190e5e22013-07-27 05:59:23233using WebKit::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08234using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47235using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03236using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39237using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31238using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59239using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08240using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00241using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11242using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33243using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13244using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06245using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34246using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40247using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38248using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39249
[email protected]c5dbef02011-05-13 05:06:09250namespace {
251
[email protected]eabbfb12013-04-05 23:28:35252// Cached version of the locale so we can return the locale on the I/O
253// thread.
254base::LazyInstance<std::string> g_io_thread_application_locale;
255
[email protected]93f72062013-05-29 20:29:40256#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40257const char* kPredefinedAllowedSocketOrigins[] = {
258 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18259 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45260 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
261 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
262 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
263 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35264 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54265 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
266 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
267 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
268 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
269 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
270 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38271 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58272 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29273 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42274 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
275 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
276 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
277 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
278 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
279 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40280};
[email protected]93f72062013-05-29 20:29:40281#endif
[email protected]e461da2f2012-02-16 19:06:40282
[email protected]f8f93eb2012-09-25 03:06:24283// Returns a copy of the given url with its host set to given host and path set
284// to given path. Other parts of the url will be the same.
285GURL ReplaceURLHostAndPath(const GURL& url,
286 const std::string& host,
287 const std::string& path) {
288 url_canon::Replacements<char> replacements;
289 replacements.SetHost(host.c_str(),
290 url_parse::Component(0, host.length()));
291 replacements.SetPath(path.c_str(),
292 url_parse::Component(0, path.length()));
293 return url.ReplaceComponents(replacements);
294}
295
296// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
297GURL AddUberHost(const GURL& url) {
298 const std::string uber_host = chrome::kChromeUIUberHost;
299 const std::string new_path = url.host() + url.path();
300
301 return ReplaceURLHostAndPath(url, uber_host, new_path);
302}
303
[email protected]045bf7c2012-09-28 20:27:36304// If url->host() is "chrome" and url->path() has characters other than the
305// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
306// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24307bool RemoveUberHost(GURL* url) {
308 if (url->host() != chrome::kChromeUIUberHost)
309 return false;
310
[email protected]045bf7c2012-09-28 20:27:36311 if (url->path().empty() || url->path() == "/")
312 return false;
313
[email protected]f8f93eb2012-09-25 03:06:24314 const std::string old_path = url->path();
315
316 const std::string::size_type separator = old_path.find('/', 1);
317 std::string new_host;
318 std::string new_path;
319 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36320 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24321 } else {
322 new_host = old_path.substr(1, separator - 1);
323 new_path = old_path.substr(separator);
324 }
325
[email protected]44e8add2013-06-13 17:29:15326 // Do not allow URLs with paths empty before the first slash since we can't
327 // have an empty host. (e.g "foo://chrome//")
328 if (new_host.empty())
329 return false;
330
[email protected]f8f93eb2012-09-25 03:06:24331 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
332
[email protected]44e8add2013-06-13 17:29:15333 DCHECK(url->is_valid());
334
[email protected]f8f93eb2012-09-25 03:06:24335 return true;
336}
337
[email protected]b8148ac2011-07-13 22:03:25338// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42339bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24340 // Do not handle special URLs such as "about:foo"
341 if (!url->host().empty()) {
342 const GURL chrome_url = AddUberHost(*url);
343
344 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
345 // be called.
346 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
347 browser_context, chrome_url))
348 return true;
349 }
350
[email protected]863f70a2012-01-27 02:05:50351 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
352 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25353 return false;
354
[email protected]fe69558d2012-03-12 11:34:49355#if defined(OS_CHROMEOS)
356 // Special case : in ChromeOS in Guest mode bookmarks and history are
357 // disabled for security reasons. New tab page explains the reasons, so
358 // we redirect user to new tab page.
359 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
360 if (url->SchemeIs(chrome::kChromeUIScheme) &&
361 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
362 url->DomainIs(chrome::kChromeUIHistoryHost))) {
363 // Rewrite with new tab URL
364 *url = GURL(chrome::kChromeUINewTabURL);
365 }
366 }
367#endif
368
[email protected]b8148ac2011-07-13 22:03:25369 // Special case the new tab page. In older versions of Chrome, the new tab
370 // page was hosted at chrome-internal:<blah>. This might be in people's saved
371 // sessions or bookmarks, so we say any URL with that scheme triggers the new
372 // tab page.
373 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
374 // Rewrite it with the proper new tab URL.
375 *url = GURL(chrome::kChromeUINewTabURL);
376 }
377
378 return true;
379}
380
[email protected]f8f93eb2012-09-25 03:06:24381// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
382// "chrome://foo/".
383bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
384 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
385 return false;
386
387 return RemoveUberHost(url);
388}
389
[email protected]8d3132f62011-10-12 07:13:42390// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
391// below. Extension, and isolated apps require different privileges to be
392// granted to their RenderProcessHosts. This classification allows us to make
393// sure URLs are served by hosts with the right set of privileges.
394enum RenderProcessHostPrivilege {
395 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45396 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42397 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45398 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42399};
400
401RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
402 const GURL& url,
403 ExtensionService* service) {
404 // Default to a normal renderer cause it is lower privileged. This should only
405 // occur if the URL on a site instance is either malformed, or uninitialized.
406 // If it is malformed, then there is no need for better privileges anyways.
407 // If it is uninitialized, but eventually settles on being an a scheme other
408 // than normal webrenderer, the navigation logic will correct us out of band
409 // anyways.
410 if (!url.is_valid())
411 return PRIV_NORMAL;
412
[email protected]885c0e92012-11-13 20:27:42413 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44414 const Extension* extension =
415 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43416 if (extension &&
417 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42418 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45419 if (extension && extension->is_hosted_app())
420 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42421
422 return PRIV_EXTENSION;
423 }
424
425 return PRIV_NORMAL;
426}
427
428RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30429 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46430 extensions::ProcessMap* process_map,
431 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46432 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30433 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46434 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21435 return PRIV_NORMAL;
436
[email protected]6f371442011-11-09 06:45:46437 for (std::set<std::string>::iterator iter = extension_ids.begin();
438 iter != extension_ids.end(); ++iter) {
439 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43440 if (extension &&
441 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42442 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45443 if (extension && extension->is_hosted_app())
444 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42445 }
446
[email protected]676f6ab2011-10-19 20:23:21447 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42448}
449
[email protected]6786bf402011-12-03 15:19:45450bool CertMatchesFilter(const net::X509Certificate& cert,
451 const base::DictionaryValue& filter) {
452 // TODO(markusheintz): This is the minimal required filter implementation.
453 // Implement a better matcher.
454
455 // An empty filter matches any client certificate since no requirements are
456 // specified at all.
457 if (filter.empty())
458 return true;
459
460 std::string common_name;
461 if (filter.GetString("ISSUER.CN", &common_name) &&
462 (cert.issuer().common_name == common_name)) {
463 return true;
464 }
465 return false;
466}
467
[email protected]f3986f82012-01-03 20:00:06468// Fills |map| with the per-script font prefs under path |map_name|.
469void FillFontFamilyMap(const PrefService* prefs,
470 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53471 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06472 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
473 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
474 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
475 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23476 if (!font_family.empty())
477 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06478 }
479}
480
[email protected]a1733df2012-06-22 11:24:18481#if defined(OS_POSIX) && !defined(OS_MACOSX)
482int GetCrashSignalFD(const CommandLine& command_line) {
483 if (command_line.HasSwitch(switches::kExtensionProcess)) {
484 ExtensionCrashHandlerHostLinux* crash_handler =
485 ExtensionCrashHandlerHostLinux::GetInstance();
486 return crash_handler->GetDeathSignalSocket();
487 }
488
489 std::string process_type =
490 command_line.GetSwitchValueASCII(switches::kProcessType);
491
492 if (process_type == switches::kRendererProcess)
493 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
494
495 if (process_type == switches::kPluginProcess)
496 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
497
498 if (process_type == switches::kPpapiPluginProcess)
499 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
500
501 if (process_type == switches::kGpuProcess)
502 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
503
504 return -1;
505}
506#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
507
[email protected]d5bcd06f2013-04-21 08:07:24508#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30509GURL GetEffectiveURLForSignin(const GURL& url) {
510 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
511
512 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03513 // Copy the path because the argument to SetPathStr must outlive
514 // the Replacements object.
515 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30516 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03517 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30518 effective_url = effective_url.ReplaceComponents(replacements);
519 return effective_url;
520}
[email protected]d5bcd06f2013-04-21 08:07:24521#endif
[email protected]970c63e2013-03-07 00:25:30522
[email protected]eabbfb12013-04-05 23:28:35523void SetApplicationLocaleOnIOThread(const std::string& locale) {
524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
525 g_io_thread_application_locale.Get() = locale;
526}
527
[email protected]190e5e22013-07-27 05:59:23528#if !defined(OS_ANDROID)
529struct BlockedPopupParams {
530 BlockedPopupParams(const GURL& target_url,
531 const content::Referrer& referrer,
532 WindowOpenDisposition disposition,
533 const WebWindowFeatures& features,
534 bool user_gesture,
535 bool opener_suppressed,
536 int render_process_id,
537 int opener_id)
538 : target_url(target_url),
539 referrer(referrer),
540 disposition(disposition),
541 features(features),
542 user_gesture(user_gesture),
543 opener_suppressed(opener_suppressed),
544 render_process_id(render_process_id),
545 opener_id(opener_id)
546 {}
547
548 GURL target_url;
549 content::Referrer referrer;
550 WindowOpenDisposition disposition;
551 WebWindowFeatures features;
552 bool user_gesture;
553 bool opener_suppressed;
554 int render_process_id;
555 int opener_id;
556};
557
558void HandleBlockedPopupOnUIThread(const BlockedPopupParams& params) {
559 WebContents* tab =
560 tab_util::GetWebContentsByID(params.render_process_id, params.opener_id);
561 if (!tab)
562 return;
563
[email protected]190e5e22013-07-27 05:59:23564 PopupBlockerTabHelper* popup_helper =
565 PopupBlockerTabHelper::FromWebContents(tab);
566 if (!popup_helper)
567 return;
568 popup_helper->AddBlockedPopup(params.target_url,
569 params.referrer,
570 params.disposition,
571 params.features,
572 params.user_gesture,
573 params.opener_suppressed);
574}
575#endif
576
[email protected]9dbfff12011-07-01 19:37:07577} // namespace
[email protected]c5dbef02011-05-13 05:06:09578
[email protected]d977f9c2011-03-14 16:10:26579namespace chrome {
580
[email protected]e461da2f2012-02-16 19:06:40581ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40582#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40583 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
584 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40585#endif
[email protected]1deace22013-05-22 06:14:46586
587 permissions_policy_delegate_.reset(
588 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40589}
590
591ChromeContentBrowserClient::~ChromeContentBrowserClient() {
592}
593
[email protected]bca18382012-06-25 19:15:23594// static
[email protected]37ca3fe02013-07-05 15:32:44595void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34596 user_prefs::PrefRegistrySyncable* registry) {
597 registry->RegisterBooleanPref(
598 prefs::kDisable3DAPIs,
599 false,
600 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
601 registry->RegisterBooleanPref(
602 prefs::kEnableHyperlinkAuditing,
603 true,
604 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
605 registry->RegisterBooleanPref(
606 prefs::kEnableMemoryInfo,
607 false,
608 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23609}
610
[email protected]eabbfb12013-04-05 23:28:35611// static
612void ChromeContentBrowserClient::SetApplicationLocale(
613 const std::string& locale) {
614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
615
616 // This object is guaranteed to outlive all threads so we don't have to
617 // worry about the lack of refcounting and can just post as Unretained.
618 //
619 // The common case is that this function is called early in Chrome startup
620 // before any threads are created (it will also be called later if the user
621 // changes the pref). In this case, there will be no threads created and
622 // posting will fail. When there are no threads, we can just set the string
623 // without worrying about threadsafety.
624 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
625 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
626 g_io_thread_application_locale.Get() = locale;
627 }
628}
629
[email protected]50462bf02011-11-21 19:13:31630content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
631 const content::MainFunctionParams& parameters) {
632 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30633 // Construct the Main browser parts based on the OS type.
634#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31635 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04636#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31637 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30638#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22639 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26640#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31641 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14642#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09643 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30644#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31645 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04646#else
[email protected]b48c9182011-10-26 18:03:30647 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31648 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30649#endif
650
[email protected]7e75e4a2013-05-17 17:20:03651 chrome::AddProfilesExtraParts(main_parts);
652
[email protected]c7480942011-11-08 19:18:27653 // Construct additional browser parts. Stages are called in the order in
654 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22655#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51656 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04657#endif
[email protected]c7480942011-11-08 19:18:27658
659#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51660 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27661#endif
662
[email protected]dc04be7c2012-03-15 23:57:49663#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51664 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49665#endif
666
[email protected]e050ef142012-03-21 01:04:24667#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51668 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
669#endif
670
671#if defined(USE_X11)
672 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24673#endif
674
[email protected]95132f52013-04-12 02:19:04675 chrome::AddMetricsExtraParts(main_parts);
676
[email protected]50462bf02011-11-21 19:13:31677 return main_parts;
[email protected]f967b722011-09-07 00:58:04678}
679
[email protected]e94bbcb2012-09-07 05:33:57680std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19681 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57682 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53683 std::string partition_id;
684
685 // The partition ID for webview guest processes is the string value of its
686 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
687 if (site.SchemeIs(chrome::kGuestScheme))
688 partition_id = site.spec();
689
[email protected]056efdc2013-04-06 00:14:53690 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53691 return partition_id;
692}
693
694bool ChromeContentBrowserClient::IsValidStoragePartitionId(
695 content::BrowserContext* browser_context,
696 const std::string& partition_id) {
697 // The default ID is empty and is always valid.
698 if (partition_id.empty())
699 return true;
700
701 return GURL(partition_id).is_valid();
702}
703
704void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
705 content::BrowserContext* browser_context,
706 const GURL& site,
[email protected]14acc642012-11-17 12:20:10707 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53708 std::string* partition_domain,
709 std::string* partition_name,
710 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10711 // Default to the browser-wide storage partition and override based on |site|
712 // below.
713 partition_domain->clear();
714 partition_name->clear();
715 *in_memory = false;
716
[email protected]1bc28312012-11-08 08:31:53717 // For the webview tag, we create special guest processes, which host the
718 // tag content separately from the main application that embeds the tag.
719 // A webview tag can specify both the partition name and whether the storage
720 // for that partition should be persisted. Each tag gets a SiteInstance with
721 // a specially formatted URL, based on the application it is hosted by and
722 // the partition requested by it. The format for that URL is:
723 // chrome-guest://partition_domain/persist?partition_name
724 if (site.SchemeIs(chrome::kGuestScheme)) {
725 // Since guest URLs are only used for packaged apps, there must be an app
726 // id in the URL.
727 CHECK(site.has_host());
728 *partition_domain = site.host();
729 // Since persistence is optional, the path must either be empty or the
730 // literal string.
731 *in_memory = (site.path() != "/persist");
732 // The partition name is user supplied value, which we have encoded when the
733 // URL was created, so it needs to be decoded.
734 *partition_name = net::UnescapeURLComponent(site.query(),
735 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10736 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
737 // If |can_be_default| is false, the caller is stating that the |site|
738 // should be parsed as if it had isolated storage. In particular it is
739 // important to NOT check ExtensionService for the is_storage_isolated()
740 // attribute because this code path is run during Extension uninstall
741 // to do cleanup after the Extension has already been unloaded from the
742 // ExtensionService.
743 bool is_isolated = !can_be_default;
744 if (can_be_default) {
745 const Extension* extension = NULL;
746 Profile* profile = Profile::FromBrowserContext(browser_context);
747 ExtensionService* extension_service =
748 extensions::ExtensionSystem::Get(profile)->extension_service();
749 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55750 extension =
751 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43752 if (extension &&
753 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10754 is_isolated = true;
755 }
756 }
757 }
[email protected]1bc28312012-11-08 08:31:53758
[email protected]14acc642012-11-17 12:20:10759 if (is_isolated) {
760 CHECK(site.has_host());
761 // For extensions with isolated storage, the the host of the |site| is
762 // the |partition_domain|. The |in_memory| and |partition_name| are only
763 // used in guest schemes so they are cleared here.
764 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53765 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10766 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53767 }
[email protected]d1198fd2012-08-13 22:50:19768 }
769
[email protected]14acc642012-11-17 12:20:10770 // Assert that if |can_be_default| is false, the code above must have found a
771 // non-default partition. If this fails, the caller has a serious logic
772 // error about which StoragePartition they expect to be in and it is not
773 // safe to continue.
774 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44775}
776
[email protected]38b098f2012-03-14 21:11:57777content::WebContentsViewDelegate*
778 ChromeContentBrowserClient::GetWebContentsViewDelegate(
779 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27780 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32781}
782
[email protected]738f57a2013-06-29 21:06:54783void ChromeContentBrowserClient::GuestWebContentsCreated(
784 WebContents* guest_web_contents,
785 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22786 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54787 scoped_ptr<base::DictionaryValue> extra_params) {
788 if (opener_web_contents) {
789 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
790 if (!guest) {
791 NOTREACHED();
792 return;
793 }
794
795 switch (guest->GetViewType()) {
796 case GuestView::WEBVIEW: {
[email protected]4c0e8272013-07-03 23:39:22797 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54798 break;
799 }
800 case GuestView::ADVIEW: {
[email protected]4c0e8272013-07-03 23:39:22801 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54802 break;
803 }
804 default:
805 NOTREACHED();
806 break;
807 }
808 return;
809 }
810
811 if (!extra_params) {
812 NOTREACHED();
813 return;
814 }
815 std::string api_type;
[email protected]90547d72013-08-06 05:57:27816 extra_params->GetString(guestview::kParameterApi, &api_type);
[email protected]738f57a2013-06-29 21:06:54817
818 if (api_type == "adview") {
[email protected]4c0e8272013-07-03 23:39:22819 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54820 } else if (api_type == "webview") {
[email protected]4c0e8272013-07-03 23:39:22821 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54822 } else {
823 NOTREACHED();
824 }
825}
826
[email protected]44295a12013-06-05 08:45:46827void ChromeContentBrowserClient::GuestWebContentsAttached(
828 WebContents* guest_web_contents,
829 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53830 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06831 Profile* profile = Profile::FromBrowserContext(
832 embedder_web_contents->GetBrowserContext());
833 ExtensionService* service =
834 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54835 if (!service) {
836 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06837 return;
[email protected]738f57a2013-06-29 21:06:54838 }
[email protected]44703cc72013-01-24 04:56:06839 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
[email protected]be9915fb2013-07-18 09:28:55840 const Extension* extension =
841 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]738f57a2013-06-29 21:06:54842 if (!extension) {
[email protected]efd6fb02013-08-05 04:44:06843 // It's ok to return here, since we could be running a browser plugin
844 // outside an extension, and don't need to attach a
845 // BrowserPluginGuestDelegate in that case;
846 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
[email protected]738f57a2013-06-29 21:06:54847 return;
[email protected]18699372013-06-25 20:42:55848 }
[email protected]738f57a2013-06-29 21:06:54849
850 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
851 if (!guest) {
852 NOTREACHED();
853 return;
854 }
[email protected]9934a5e2013-08-22 00:07:56855 guest->Attach(embedder_web_contents, extension->id(), extra_params);
[email protected]44703cc72013-01-24 04:56:06856}
857
[email protected]f3b1a082011-11-18 00:34:30858void ChromeContentBrowserClient::RenderProcessHostCreated(
859 content::RenderProcessHost* host) {
860 int id = host->GetID();
861 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41862 net::URLRequestContextGetter* context =
863 profile->GetRequestContextForRenderProcess(id);
864
[email protected]f3b1a082011-11-18 00:34:30865 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41866 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55867#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30868 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55869#endif
[email protected]658677f2012-06-09 06:04:02870#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08871 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03872#endif
[email protected]f3b1a082011-11-18 00:34:30873 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02874 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53875#if defined(ENABLE_SPELLCHECK)
[email protected]f3b1a082011-11-18 00:34:30876 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53877#endif
[email protected]7ceb99012011-12-21 08:05:56878#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21879 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56880#endif
[email protected]43535512013-02-20 20:41:41881 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
882 id, profile, context));
[email protected]2736c032012-05-11 18:06:07883 host->GetChannel()->AddFilter(
884 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27885 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33886 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31887#if defined(ENABLE_WEBRTC)
888 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
889#endif
[email protected]01e59752013-06-18 00:17:35890#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03891 ExtensionInfoMap* extension_info_map =
892 extensions::ExtensionSystem::Get(profile)->info_map();
893 host->GetChannel()->AddFilter(new NaClHostMessageFilter(
894 id, profile->IsOffTheRecord(),
895 profile->GetPath(), extension_info_map,
896 context));
[email protected]01e59752013-06-18 00:17:35897#endif
[email protected]3e69bc82011-05-26 23:22:38898
[email protected]2ccf45c2011-08-19 23:35:50899 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
900 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07901
[email protected]24665682013-02-25 20:59:38902 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
[email protected]42c94c72013-08-14 01:18:44903 extensions::ActivityLog::GetInstance(profile)->IsLogEnabled()));
[email protected]24665682013-02-25 20:59:38904
[email protected]39a5b532011-10-22 01:47:07905 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56906
907 RendererContentSettingRules rules;
908 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
909 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14910}
911
[email protected]3d7474ff2011-07-27 17:47:37912GURL ChromeContentBrowserClient::GetEffectiveURL(
913 content::BrowserContext* browser_context, const GURL& url) {
914 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52915 if (!profile)
916 return url;
917
[email protected]b3cb3a32013-07-31 01:32:29918 // If the input |url| should be assigned to the Instant renderer, make its
919 // effective URL distinct from other URLs on the search provider's domain.
920 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
921 return chrome::GetEffectiveURLForInstant(url, profile);
922
[email protected]d5bcd06f2013-04-21 08:07:24923#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30924 // If the input |url| should be assigned to the Signin renderer, make its
925 // effective URL distinct from other URLs on the signin service's domain.
926 // Note that the signin renderer will be allowed to sign the user in to
927 // Chrome.
928 if (SigninManager::IsWebBasedSigninFlowURL(url))
929 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24930#endif
[email protected]970c63e2013-03-07 00:25:30931
[email protected]c5dec6292013-01-25 04:54:52932 // If the input |url| is part of an installed app, the effective URL is an
933 // extension URL with the ID of that extension as the host. This has the
934 // effect of grouping apps together in a common SiteInstance.
935 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13936 extensions::ExtensionSystem::Get(profile)->extension_service();
937 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08938 return url;
939
[email protected]06bdd2b2012-11-30 18:47:13940 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55941 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08942 if (!extension)
943 return url;
944
[email protected]15877ca2011-11-18 22:40:52945 // Bookmark apps do not use the hosted app process model, and should be
946 // treated as normal URLs.
947 if (extension->from_bookmark())
948 return url;
949
[email protected]36fb2c7c2011-04-04 15:49:08950 // If the URL is part of an extension's web extent, convert it to an
951 // extension URL.
952 return extension->GetResourceURL(url.path());
953}
954
[email protected]056ad2a2011-07-12 02:13:55955bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37956 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52957 // Non-extension, non-Instant URLs should generally use
958 // process-per-site-instance. Because we expect to use the effective URL,
959 // URLs for hosted apps (apart from bookmark apps) should have an extension
960 // scheme by now.
961
962 Profile* profile = Profile::FromBrowserContext(browser_context);
963 if (!profile)
964 return false;
965
[email protected]df113a12013-07-24 04:56:08966 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52967 return true;
968
[email protected]d5bcd06f2013-04-21 08:07:24969#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30970 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
971 return true;
[email protected]d5bcd06f2013-04-21 08:07:24972#endif
[email protected]970c63e2013-03-07 00:25:30973
[email protected]885c0e92012-11-13 20:27:42974 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55975 return false;
976
[email protected]c5dec6292013-01-25 04:54:52977 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13978 extensions::ExtensionSystem::Get(profile)->extension_service();
979 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55980 return false;
981
[email protected]be9915fb2013-07-18 09:28:55982 const Extension* extension =
983 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:55984 if (!extension)
985 return false;
986
987 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53988 // permission, or that does not allow JavaScript access to the background
989 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55990 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40991 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06992 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29993 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53994 return false;
995 }
996 }
[email protected]056ad2a2011-07-12 02:13:55997
[email protected]7b54ca02012-03-02 18:06:53998 // Hosted apps that have script access to their background page must use
999 // process per site, since all instances can make synchronous calls to the
1000 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:551001 return true;
1002}
1003
[email protected]672c8c12013-03-07 12:30:061004// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:411005void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1006 std::vector<std::string>* additional_schemes) {
1007 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:061008}
1009
[email protected]6bd30072013-02-08 18:17:111010net::URLRequestContextGetter*
1011ChromeContentBrowserClient::CreateRequestContext(
1012 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:061013 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111014 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:061015 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111016}
1017
1018net::URLRequestContextGetter*
1019ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1020 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:401021 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:111022 bool in_memory,
[email protected]672c8c12013-03-07 12:30:061023 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111024 Profile* profile = Profile::FromBrowserContext(browser_context);
1025 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:061026 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111027}
1028
[email protected]46fb9442011-12-09 17:57:471029bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1030 return ProfileIOData::IsHandledURL(url);
1031}
1032
[email protected]c4365fa42013-05-14 01:08:241033bool ChromeContentBrowserClient::CanCommitURL(
1034 content::RenderProcessHost* process_host,
1035 const GURL& url) {
1036 // We need to let most extension URLs commit in any process, since this can
1037 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1038 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1039 // cannot be loaded in iframes and should never be requested outside its
1040 // process.
1041 Profile* profile =
1042 Profile::FromBrowserContext(process_host->GetBrowserContext());
1043 ExtensionService* service =
1044 extensions::ExtensionSystem::Get(profile)->extension_service();
1045 if (!service)
1046 return true;
1047 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551048 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241049 if (new_extension &&
1050 new_extension->is_hosted_app() &&
1051 new_extension->id() == extension_misc::kWebStoreAppId &&
1052 !service->process_map()->Contains(new_extension->id(),
1053 process_host->GetID())) {
1054 return false;
1055 }
1056
1057 return true;
1058}
1059
[email protected]2a5221b2011-09-27 23:07:311060bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301061 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311062 const GURL& site_url) {
1063 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301064 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521065 // This may be NULL during tests. In that case, just assume any site can
1066 // share any host.
1067 if (!profile)
1068 return true;
1069
[email protected]d43f99fe2013-04-03 00:20:141070 // Instant URLs should only be in the instant process and instant process
1071 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521072 InstantService* instant_service =
1073 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141074 if (instant_service) {
1075 bool is_instant_process = instant_service->IsInstantProcess(
1076 process_host->GetID());
1077 bool should_be_in_instant_process =
1078 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1079 if (is_instant_process || should_be_in_instant_process)
1080 return is_instant_process && should_be_in_instant_process;
1081 }
[email protected]c5dec6292013-01-25 04:54:521082
[email protected]d5bcd06f2013-04-21 08:07:241083#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301084 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1085 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1086 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241087#endif
[email protected]970c63e2013-03-07 00:25:301088
[email protected]06bdd2b2012-11-30 18:47:131089 ExtensionService* service =
1090 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461091 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311092
[email protected]ffa97602011-11-17 17:55:521093 // Don't allow the Task Manager to share a process with anything else.
1094 // Otherwise it can affect the renderers it is observing.
1095 // Note: we could create another RenderProcessHostPrivilege bucket for
1096 // this to allow multiple chrome://tasks instances to share, but that's
1097 // a very unlikely case without serious consequences.
1098 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1099 return false;
1100
[email protected]8d3132f62011-10-12 07:13:421101 // These may be NULL during tests. In that case, just assume any site can
1102 // share any host.
[email protected]6f371442011-11-09 06:45:461103 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311104 return true;
1105
[email protected]eec0b33c2011-12-05 22:09:451106 // Otherwise, just make sure the process privilege matches the privilege
1107 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571108 RenderProcessHostPrivilege privilege_required =
1109 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451110 return GetProcessPrivilege(process_host, process_map, service) ==
1111 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311112}
1113
[email protected]76411f412012-02-22 18:56:061114// This function is trying to limit the amount of processes used by extensions
1115// with background pages. It uses a globally set percentage of processes to
1116// run such extensions and if the limit is exceeded, it returns true, to
1117// indicate to the content module to group extensions together.
1118bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1119 content::BrowserContext* browser_context, const GURL& url) {
1120 // It has to be a valid URL for us to check for an extension.
1121 if (!url.is_valid())
1122 return false;
1123
1124 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191125 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131126 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061127 if (!service)
1128 return false;
1129
1130 // We have to have a valid extension with background page to proceed.
1131 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551132 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061133 if (!extension)
1134 return false;
[email protected]9367eabc2013-03-01 01:29:291135 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061136 return false;
1137
1138 std::set<int> process_ids;
1139 size_t max_process_count =
1140 content::RenderProcessHost::GetMaxRendererProcessCount();
1141
1142 // Go through all profiles to ensure we have total count of extension
1143 // processes containing background pages, otherwise one profile can
1144 // starve the other.
1145 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1146 GetLoadedProfiles();
1147 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031148 ExtensionProcessManager* epm =
1149 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321150 for (ExtensionProcessManager::const_iterator iter =
1151 epm->background_hosts().begin();
1152 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131153 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321154 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061155 }
1156 }
1157
1158 if (process_ids.size() >
1159 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1160 return true;
1161 }
1162
1163 return false;
1164}
1165
[email protected]6f371442011-11-09 06:45:461166void ChromeContentBrowserClient::SiteInstanceGotProcess(
1167 SiteInstance* site_instance) {
1168 CHECK(site_instance->HasProcess());
1169
1170 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021171 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521172 if (!profile)
1173 return;
1174
1175 // Remember the ID of the Instant process to signal the renderer process
1176 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031177 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321178 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521179 InstantService* instant_service =
1180 InstantServiceFactory::GetForProfile(profile);
1181 if (instant_service)
1182 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1183 }
1184
[email protected]d5bcd06f2013-04-21 08:07:241185#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301186 // We only expect there to be one signin process as we use process-per-site
1187 // for signin URLs. The signin process will be cleared from SigninManager
1188 // when the renderer is destroyed.
1189 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1190 SigninManager* signin_manager =
1191 SigninManagerFactory::GetForProfile(profile);
1192 if (signin_manager)
1193 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461194 BrowserThread::PostTask(
1195 BrowserThread::IO, FROM_HERE,
1196 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1197 extensions::ExtensionSystem::Get(profile)->info_map(),
1198 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301199 }
[email protected]d5bcd06f2013-04-21 08:07:241200#endif
[email protected]970c63e2013-03-07 00:25:301201
[email protected]06bdd2b2012-11-30 18:47:131202 ExtensionService* service =
1203 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461204 if (!service)
1205 return;
1206
[email protected]be9915fb2013-07-18 09:28:551207 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1208 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461209 if (!extension)
1210 return;
1211
[email protected]6bc04fd82011-12-04 02:29:351212 service->process_map()->Insert(extension->id(),
1213 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331214 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461215 BrowserThread::PostTask(
1216 BrowserThread::IO, FROM_HERE,
1217 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591218 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461219 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351220 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331221 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461222}
1223
1224void ChromeContentBrowserClient::SiteInstanceDeleting(
1225 SiteInstance* site_instance) {
1226 if (!site_instance->HasProcess())
1227 return;
1228
1229 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021230 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131231 ExtensionService* service =
1232 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461233 if (!service)
1234 return;
1235
[email protected]be9915fb2013-07-18 09:28:551236 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1237 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461238 if (!extension)
1239 return;
1240
[email protected]6bc04fd82011-12-04 02:29:351241 service->process_map()->Remove(extension->id(),
1242 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331243 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461244 BrowserThread::PostTask(
1245 BrowserThread::IO, FROM_HERE,
1246 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591247 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461248 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351249 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331250 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461251}
1252
[email protected]f05763972012-06-06 18:17:261253bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141254 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081255 const GURL& current_url,
1256 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261257 if (current_url.is_empty()) {
1258 // Always choose a new process when navigating to extension URLs. The
1259 // process grouping logic will combine all of a given extension's pages
1260 // into the same process.
[email protected]885c0e92012-11-13 20:27:421261 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261262 return true;
[email protected]e3daf3c2011-10-05 21:17:081263
[email protected]f05763972012-06-06 18:17:261264 return false;
1265 }
1266
1267 // Also, we must switch if one is an extension and the other is not the exact
1268 // same extension.
[email protected]885c0e92012-11-13 20:27:421269 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1270 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261271 if (current_url.GetOrigin() != new_url.GetOrigin())
1272 return true;
1273 }
1274
[email protected]e9841fbd2013-02-22 23:12:141275 // The checks below only matter if we can retrieve which extensions are
1276 // installed.
1277 Profile* profile =
1278 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1279 ExtensionService* service =
1280 extensions::ExtensionSystem::Get(profile)->extension_service();
1281 if (!service)
1282 return false;
1283
1284 // We must swap if the URL is for an extension and we are not using an
1285 // extension process.
1286 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551287 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141288 // Ignore all hosted apps except the Chrome Web Store, since they do not
1289 // require their own BrowsingInstance (e.g., postMessage is ok).
1290 if (new_extension &&
1291 new_extension->is_hosted_app() &&
1292 new_extension->id() != extension_misc::kWebStoreAppId)
1293 new_extension = NULL;
1294 if (new_extension &&
1295 site_instance->HasProcess() &&
1296 !service->process_map()->Contains(new_extension->id(),
1297 site_instance->GetProcess()->GetID()))
1298 return true;
1299
[email protected]f05763972012-06-06 18:17:261300 return false;
[email protected]e3daf3c2011-10-05 21:17:081301}
1302
[email protected]395045c2012-05-22 15:04:381303bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1304 content::ResourceContext* resource_context, const GURL& current_url,
1305 const GURL& new_url) {
1306 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1307 return extensions::CrossesExtensionProcessBoundary(
1308 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551309 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381310}
1311
[email protected]3d831992013-07-04 01:13:291312bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1313 return !url.SchemeIs(chrome::kChromeNativeScheme);
1314}
1315
[email protected]763ec4ca2011-04-29 15:48:121316std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1317 const std::string& alias_name) {
1318 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1319}
1320
[email protected]b80f68432011-05-02 17:22:301321void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1322 CommandLine* command_line, int child_process_id) {
[email protected]97425082013-07-16 03:10:071323#if defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301324 if (IsCrashReporterEnabled()) {
1325 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1326 child_process_logging::GetClientId());
1327 }
[email protected]97425082013-07-16 03:10:071328#elif defined(OS_POSIX)
1329 if (IsCrashReporterEnabled()) {
1330 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1331 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1332 }
1333
[email protected]b80f68432011-05-02 17:22:301334#endif // OS_MACOSX
1335
[email protected]f1933792011-06-14 00:49:341336 if (logging::DialogsAreSuppressed())
1337 command_line->AppendSwitch(switches::kNoErrorDialogs);
1338
[email protected]b80f68432011-05-02 17:22:301339 std::string process_type =
1340 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171341 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321342
1343 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1344 command_line->AppendSwitch(switches::kChromeFrame);
1345
[email protected]718eab62011-10-05 21:16:521346 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451347 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301348 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1349 if (!user_data_dir.empty())
1350 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1351#if defined(OS_CHROMEOS)
1352 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441353 browser_command_line.GetSwitchValueASCII(
1354 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301355 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441356 command_line->AppendSwitchASCII(
1357 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301358#endif
1359
[email protected]f3b1a082011-11-18 00:34:301360 content::RenderProcessHost* process =
1361 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371362 if (process) {
1363 Profile* profile = Profile::FromBrowserContext(
1364 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131365 ExtensionService* extension_service =
1366 extensions::ExtensionSystem::Get(profile)->extension_service();
1367 if (extension_service) {
1368 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001369 if (process_map && process_map->Contains(process->GetID()))
1370 command_line->AppendSwitch(switches::kExtensionProcess);
1371 }
[email protected]b80f68432011-05-02 17:22:301372
[email protected]a8d851f82011-12-21 00:32:371373 PrefService* prefs = profile->GetPrefs();
1374 // Currently this pref is only registered if applied via a policy.
1375 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1376 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1377 // Turn this policy into a command line switch.
1378 command_line->AppendSwitch(switches::kDisable3DAPIs);
1379 }
[email protected]718eab62011-10-05 21:16:521380
[email protected]a8d851f82011-12-21 00:32:371381 // Disable client-side phishing detection in the renderer if it is
1382 // disabled in the Profile preferences or the browser process.
1383 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1384 !g_browser_process->safe_browsing_detection_service()) {
1385 command_line->AppendSwitch(
1386 switches::kDisableClientSidePhishingDetection);
1387 }
[email protected]0045b0f42012-07-26 11:52:081388
1389 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211390 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521391
1392 InstantService* instant_service =
1393 InstantServiceFactory::GetForProfile(profile);
1394 if (instant_service &&
1395 instant_service->IsInstantProcess(process->GetID()))
1396 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301397
[email protected]d5bcd06f2013-04-21 08:07:241398#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301399 SigninManager* signin_manager =
1400 SigninManagerFactory::GetForProfile(profile);
1401 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1402 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241403#endif
[email protected]47c7ec82012-01-18 03:29:211404 }
[email protected]4287a3d2011-06-13 23:56:511405
[email protected]16dc42452013-04-09 04:37:191406 if (message_center::IsRichNotificationEnabled())
1407 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191408
[email protected]47c7ec82012-01-18 03:29:211409 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511410 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171411 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481412 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171413 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]49d9b142013-07-19 08:50:271414 extensions::switches::kAllowLegacyExtensionManifests,
1415 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511416 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271417 extensions::switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511418 switches::kAllowHTTPBackgroundPage,
[email protected]9d450492013-06-13 23:08:371419 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1420 // to browser.
1421 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511422 switches::kAppsCheckoutURL,
1423 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311424 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511425 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501426 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531427 switches::kDisableExtensionsResourceWhitelist,
[email protected]83c85262013-08-22 21:13:461428 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111429 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531430 switches::kEnableAdview,
1431 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441432 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211433 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511434 switches::kEnableIPCFuzzing,
1435 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451436 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481437 switches::kEnablePasswordGeneration,
[email protected]4287a3d2011-06-13 23:56:511438 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511439 switches::kMemoryProfiling,
1440 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371441 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371442 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511443 switches::kPpapiFlashArgs,
1444 switches::kPpapiFlashInProcess,
1445 switches::kPpapiFlashPath,
1446 switches::kPpapiFlashVersion,
1447 switches::kProfilingAtStart,
1448 switches::kProfilingFile,
1449 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371450 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511451 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291452 switches::kSpdyProxyAuthOrigin,
[email protected]cbcf3b5b2013-08-06 17:14:191453 switches::kTranslateSecurityOrigin,
[email protected]a446534d2012-02-09 00:07:381454 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511455 };
1456
1457 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1458 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171459 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381460 static const char* const kSwitchNames[] = {
[email protected]c8d02992013-07-31 22:16:511461 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271462 extensions::switches::kExtensionsOnChromeURLs,
[email protected]eb653f82012-05-24 02:31:351463 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381464 switches::kWhitelistedExtensionID,
1465 };
1466
1467 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1468 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511469 } else if (process_type == switches::kPluginProcess) {
1470 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441471#if defined(OS_CHROMEOS)
1472 chromeos::switches::kLoginProfile,
1473#endif
[email protected]4287a3d2011-06-13 23:56:511474 switches::kMemoryProfiling,
1475 switches::kSilentDumpOnDCHECK,
1476 switches::kUserDataDir,
1477 };
1478
1479 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1480 arraysize(kSwitchNames));
1481 } else if (process_type == switches::kZygoteProcess) {
1482 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511483 switches::kUserDataDir, // Make logs go to the right file.
1484 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501485 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511486 switches::kPpapiFlashInProcess,
1487 switches::kPpapiFlashPath,
1488 switches::kPpapiFlashVersion,
1489 };
1490
1491 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1492 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111493 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001494 base::FilePath user_data_dir =
1495 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1496 if (!user_data_dir.empty())
1497 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111498 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1499 // because GPU is expected to be unreliable.
1500 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1501 !command_line->HasSwitch(switches::kDisableBreakpad))
1502 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301503 }
[email protected]6f08af82011-09-15 01:19:031504
1505 // The command line switch kEnableBenchmarking needs to be specified along
1506 // with the kEnableStatsTable switch to ensure that the stats table global
1507 // is initialized correctly.
1508 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1509 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301510}
1511
1512std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431513 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351514 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301515 return g_browser_process->GetApplicationLocale();
1516}
1517
[email protected]597a867b2011-11-18 18:31:201518std::string ChromeContentBrowserClient::GetAcceptLangs(
1519 content::BrowserContext* context) {
1520 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371521 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081522}
1523
[email protected]9ec0f452012-05-31 15:58:531524gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221525 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531526 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081527}
1528
[email protected]a2176792011-05-08 19:30:491529bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091530 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191531 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201532 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201534 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051535 return io_data->GetCookieSettings()->
1536 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491537}
1538
[email protected]ed24fad2011-05-10 22:44:011539bool ChromeContentBrowserClient::AllowGetCookie(
1540 const GURL& url,
1541 const GURL& first_party,
1542 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201543 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011544 int render_process_id,
1545 int render_view_id) {
1546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201547 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051548 bool allow = io_data->GetCookieSettings()->
1549 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011550
[email protected]8093a542011-05-13 07:29:321551 BrowserThread::PostTask(
1552 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031553 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431554 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011555 return allow;
1556}
1557
1558bool ChromeContentBrowserClient::AllowSetCookie(
1559 const GURL& url,
1560 const GURL& first_party,
1561 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201562 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011563 int render_process_id,
1564 int render_view_id,
1565 net::CookieOptions* options) {
1566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201567 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051568 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1569 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1570
[email protected]8093a542011-05-13 07:29:321571 BrowserThread::PostTask(
1572 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031573 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431574 render_view_id, url, first_party, cookie_line, *options,
1575 !allow));
[email protected]ed24fad2011-05-10 22:44:011576 return allow;
1577}
1578
[email protected]d5a19162011-06-30 18:51:541579bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201580 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201582 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431583 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1584 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261585
[email protected]bf510ed2012-06-05 08:31:431586 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1587 // Could we even support per-origin settings?
1588 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541589}
1590
[email protected]5c5a88e2011-11-12 00:45:351591bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351592 const GURL& url,
1593 const string16& name,
1594 const string16& display_name,
1595 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201596 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481597 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201599 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351600 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1601 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1602
[email protected]62151052012-02-01 18:40:481603 // Record access to database for potential display in UI.
1604 std::vector<std::pair<int, int> >::const_iterator i;
1605 for (i = render_views.begin(); i != render_views.end(); ++i) {
1606 BrowserThread::PostTask(
1607 BrowserThread::UI, FROM_HERE,
1608 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1609 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351610 }
1611
1612 return allow;
1613}
1614
1615bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351616 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201617 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481618 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201620 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351621 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1622 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1623
[email protected]62151052012-02-01 18:40:481624 // Record access to file system for potential display in UI.
1625 std::vector<std::pair<int, int> >::const_iterator i;
1626 for (i = render_views.begin(); i != render_views.end(); ++i) {
1627 BrowserThread::PostTask(
1628 BrowserThread::UI, FROM_HERE,
1629 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1630 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351631 }
1632
1633 return allow;
1634}
1635
[email protected]7c5ff9a2012-03-02 07:42:491636bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1637 const GURL& url,
1638 const string16& name,
1639 content::ResourceContext* context,
1640 const std::vector<std::pair<int, int> >& render_views) {
1641 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1642 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1643 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1644 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1645
1646 // Record access to IndexedDB for potential display in UI.
1647 std::vector<std::pair<int, int> >::const_iterator i;
1648 for (i = render_views.begin(); i != render_views.end(); ++i) {
1649 BrowserThread::PostTask(
1650 BrowserThread::UI, FROM_HERE,
1651 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1652 i->first, i->second, url, name, !allow));
1653 }
1654
1655 return allow;
1656}
1657
[email protected]6133f922011-07-01 21:34:341658net::URLRequestContext*
1659ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201660 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421662 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201663 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341664 return io_data->extensions_request_context();
1665 }
1666
1667 return NULL;
1668}
1669
[email protected]317f96c92011-05-31 06:53:411670QuotaPermissionContext*
1671ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1672 return new ChromeQuotaPermissionContext();
1673}
1674
[email protected]848dd042011-06-04 18:24:031675void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171676 int render_process_id,
1677 int render_view_id,
1678 int cert_error,
1679 const net::SSLInfo& ssl_info,
1680 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021681 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031682 bool overridable,
[email protected]d9be47702012-05-16 03:41:221683 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171684 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001685 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021686 if (resource_type != ResourceType::MAIN_FRAME) {
1687 // A sub-resource has a certificate error. The user doesn't really
1688 // have a context for making the right decision, so block the
1689 // request hard, without an info bar to allow showing the insecure
1690 // content.
[email protected]8c965c22013-05-23 19:28:001691 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021692 return;
1693 }
1694
[email protected]f9034cf2011-07-21 12:43:411695 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131696 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171697 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411698 if (!tab) {
1699 NOTREACHED();
1700 return;
1701 }
1702 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501703 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301704 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011705 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1706 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411707 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171708 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411709 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001710 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411711 return;
1712 }
1713 }
1714
[email protected]1e87df32012-09-12 04:53:191715#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231716 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1717 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1718 if (captive_portal_tab_helper)
1719 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191720#endif
1721
[email protected]f9034cf2011-07-21 12:43:411722 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221723 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1724 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031725}
1726
[email protected]c99c442e2011-08-24 11:37:301727void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451728 int render_process_id,
1729 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401730 const net::HttpNetworkSession* network_session,
1731 net::SSLCertRequestInfo* cert_request_info,
1732 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131733 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451734 render_process_id, render_view_id);
1735 if (!tab) {
1736 NOTREACHED();
1737 return;
1738 }
1739
[email protected]6786bf402011-12-03 15:19:451740 GURL requesting_url("https://" + cert_request_info->host_and_port);
1741 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1742 << cert_request_info->host_and_port;
1743
[email protected]627e0512011-12-21 22:55:301744 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451745 scoped_ptr<Value> filter(
1746 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1747 requesting_url,
1748 requesting_url,
1749 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1750 std::string(), NULL));
1751
1752 if (filter.get()) {
1753 // Try to automatically select a client certificate.
1754 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1755 DictionaryValue* filter_dict =
1756 static_cast<DictionaryValue*>(filter.get());
1757
1758 const std::vector<scoped_refptr<net::X509Certificate> >&
1759 all_client_certs = cert_request_info->client_certs;
1760 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091761 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451762 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091763 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451764 return;
1765 }
1766 }
1767 } else {
1768 NOTREACHED();
1769 }
1770 }
1771
[email protected]11feec322012-09-18 03:58:521772 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1773 if (!ssl_tab_helper) {
1774 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451775 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141776 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401777 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451778 return;
1779 }
[email protected]11feec322012-09-18 03:58:521780 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401781 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451782}
1783
[email protected]3b455502012-12-11 18:22:581784void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451785 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581786 net::CertificateMimeType cert_type,
1787 const void* cert_data,
1788 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451789 int render_process_id,
1790 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581791 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1792 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451793}
1794
[email protected]dc73a7b2012-03-25 15:27:181795content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561796 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181797}
1798
[email protected]941623e2011-06-07 23:06:041799void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1800 const GURL& source_origin,
1801 int callback_context,
1802 int render_process_id,
1803 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111804#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021805 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1806 WebContents* contents =
1807 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1808 if (!contents) {
[email protected]941623e2011-06-07 23:06:041809 NOTREACHED();
1810 return;
1811 }
1812
[email protected]d0d9c3ee2012-06-19 03:07:021813 // Skip showing the infobar if the request comes from an extension, and that
1814 // extension has the 'notify' permission. (If the extension does not have the
1815 // permission, the user will still be prompted.)
1816 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011817 ExtensionInfoMap* extension_info_map =
1818 extensions::ExtensionSystem::Get(profile)->info_map();
1819 DesktopNotificationService* notification_service =
1820 DesktopNotificationServiceFactory::GetForProfile(profile);
1821 const Extension* extension = NULL;
1822 if (extension_info_map) {
1823 ExtensionSet extensions;
1824 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1825 source_origin, render_process_id,
1826 extensions::APIPermission::kNotification, &extensions);
1827 for (ExtensionSet::const_iterator iter = extensions.begin();
1828 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381829 if (notification_service->IsNotifierEnabled(NotifierId(
1830 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361831 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011832 break;
1833 }
1834 }
1835 }
[email protected]eb4832a2012-12-08 01:57:521836 RenderViewHost* rvh =
1837 RenderViewHost::FromID(render_process_id, render_view_id);
1838 if (IsExtensionWithPermissionOrSuggestInConsole(
1839 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021840 if (rvh)
1841 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1842 return;
1843 }
1844
[email protected]c7cd5942013-04-30 03:31:011845 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021846 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111847#else
1848 NOTIMPLEMENTED();
1849#endif
[email protected]941623e2011-06-07 23:06:041850}
1851
1852WebKit::WebNotificationPresenter::Permission
1853 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021854 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201855 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021856 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111857#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041858 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481859 // Sometimes a notification may be invoked during the shutdown.
1860 // See http://crbug.com/256638
1861 if (browser_shutdown::IsTryingToQuit())
1862 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
1863
[email protected]df02aca2012-02-09 21:03:201864 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041865
[email protected]c7cd5942013-04-30 03:31:011866 DesktopNotificationService* notification_service =
1867 io_data->GetNotificationService();
1868 if (notification_service) {
1869 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1870 ExtensionSet extensions;
1871 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1872 source_origin, render_process_id,
1873 extensions::APIPermission::kNotification, &extensions);
1874 for (ExtensionSet::const_iterator iter = extensions.begin();
1875 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381876 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
1877 if (notification_service->IsNotifierEnabled(notifier_id))
[email protected]c7cd5942013-04-30 03:31:011878 return WebKit::WebNotificationPresenter::PermissionAllowed;
1879 }
1880
1881 return notification_service->HasPermission(source_origin);
1882 }
1883
1884 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111885#else
1886 return WebKit::WebNotificationPresenter::PermissionAllowed;
1887#endif
[email protected]941623e2011-06-07 23:06:041888}
1889
1890void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171891 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041892 int render_process_id,
1893 int render_view_id,
1894 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111895#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041896 RenderViewHost* rvh = RenderViewHost::FromID(
1897 render_process_id, render_view_id);
1898 if (!rvh) {
1899 NOTREACHED();
1900 return;
1901 }
1902
[email protected]9f76c1e2012-03-05 15:15:581903 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301904 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041905 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371906 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041907 service->ShowDesktopNotification(
1908 params, render_process_id, render_view_id,
1909 worker ? DesktopNotificationService::WorkerNotification :
1910 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111911#else
1912 NOTIMPLEMENTED();
1913#endif
[email protected]941623e2011-06-07 23:06:041914}
1915
1916void ChromeContentBrowserClient::CancelDesktopNotification(
1917 int render_process_id,
1918 int render_view_id,
1919 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111920#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041921 RenderViewHost* rvh = RenderViewHost::FromID(
1922 render_process_id, render_view_id);
1923 if (!rvh) {
1924 NOTREACHED();
1925 return;
1926 }
1927
[email protected]9f76c1e2012-03-05 15:15:581928 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301929 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041930 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371931 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041932 service->CancelDesktopNotification(
1933 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111934#else
1935 NOTIMPLEMENTED();
1936#endif
[email protected]941623e2011-06-07 23:06:041937}
1938
[email protected]9f3fba52011-06-08 20:37:191939bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351940 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021941 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191942 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:231943 const GURL& target_url,
1944 const content::Referrer& referrer,
1945 WindowOpenDisposition disposition,
1946 const WebWindowFeatures& features,
1947 bool user_gesture,
1948 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:201949 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011950 int render_process_id,
[email protected]190e5e22013-07-27 05:59:231951 bool is_guest,
1952 int opener_id,
[email protected]03b6d552012-03-29 04:03:011953 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191954 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011955
1956 *no_javascript_access = false;
1957
[email protected]9f3fba52011-06-08 20:37:191958 // If the opener is trying to create a background window but doesn't have
1959 // the appropriate permission, fail the attempt.
1960 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201961 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531962 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1963
[email protected]03b6d552012-03-29 04:03:011964 if (!map->SecurityOriginHasAPIPermission(
1965 source_origin,
1966 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061967 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011968 return false;
1969 }
1970
[email protected]7b54ca02012-03-02 18:06:531971 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1972 // return a recently installed Extension even if this CanCreateWindow call
1973 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011974 // because the permission check above would have caused an early return
1975 // already. We must use the full URL to find hosted apps, though, and not
1976 // just the origin.
[email protected]be9915fb2013-07-18 09:28:551977 const Extension* extension =
1978 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:291979 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011980 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:231981
1982 return true;
[email protected]9f3fba52011-06-08 20:37:191983 }
[email protected]056efdc2013-04-06 00:14:531984
1985 // No new browser window (popup or tab) in app mode.
1986 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1987 chrome::IsRunningInForcedAppMode()) {
1988 return false;
1989 }
1990
[email protected]d2bac6b2013-08-13 03:42:361991 if (g_browser_process->prerender_tracker() &&
1992 g_browser_process->prerender_tracker()->TryCancelOnIOThread(
1993 render_process_id,
1994 opener_id,
1995 prerender::FINAL_STATUS_CREATE_NEW_WINDOW)) {
1996 return false;
1997 }
1998
[email protected]190e5e22013-07-27 05:59:231999#if !defined(OS_ANDROID)
[email protected]190e5e22013-07-27 05:59:232000 if (is_guest)
2001 return true;
2002
[email protected]190e5e22013-07-27 05:59:232003 HostContentSettingsMap* content_settings =
2004 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
2005
[email protected]7f53dff2013-08-05 10:45:502006 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch(
2007 switches::kDisablePopupBlocking)) {
[email protected]190e5e22013-07-27 05:59:232008 if (content_settings->GetContentSetting(opener_url,
2009 opener_url,
2010 CONTENT_SETTINGS_TYPE_POPUPS,
2011 std::string()) ==
2012 CONTENT_SETTING_ALLOW) {
2013 return true;
2014 }
2015
2016 BrowserThread::PostTask(BrowserThread::UI,
2017 FROM_HERE,
2018 base::Bind(&HandleBlockedPopupOnUIThread,
2019 BlockedPopupParams(target_url,
2020 referrer,
2021 disposition,
2022 features,
2023 user_gesture,
2024 opener_suppressed,
2025 render_process_id,
2026 opener_id)));
2027 return false;
2028 }
2029#endif
2030
[email protected]9f3fba52011-06-08 20:37:192031 return true;
2032}
2033
2034std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202035 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192036 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2037 // Check if it's an extension-created worker, in which case we want to use
2038 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202039 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192040 const Extension* extension =
2041 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2042 return extension ? extension->name() : std::string();
2043}
2044
[email protected]99907362012-01-11 05:41:402045void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2046 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172047}
2048
[email protected]7a06d282013-05-03 04:39:332049// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022050content::SpeechRecognitionManagerDelegate*
2051 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002052#if defined(ENABLE_INPUT_SPEECH)
2053 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322054#else
[email protected]855e18b2013-07-08 21:02:002055 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2056 // need the base delegate without the bubble UI.
2057 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322058#endif
[email protected]66cfec62012-02-24 17:57:512059}
2060
[email protected]ae6e9912011-07-27 01:18:282061net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2062 return g_browser_process->net_log();
2063}
2064
[email protected]32538d92011-08-25 00:09:232065AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2066 return new ChromeAccessTokenStore();
2067}
2068
[email protected]dbae6b02011-06-29 23:51:412069bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012070 return true;
[email protected]dbae6b02011-06-29 23:51:412071}
2072
[email protected]64d69de42012-02-06 00:19:542073void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322074 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062075 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582076 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062077 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062078
[email protected]f3986f82012-01-03 20:00:062079 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542080 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062081 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542082 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062083 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542084 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062085 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542086 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062087 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542088 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062089 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542090 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032091 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2092 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:062093
[email protected]64d69de42012-02-06 00:19:542094 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402095 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542096 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402097 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542098 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402099 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542100 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402101 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062102
[email protected]ddf72142012-05-22 04:52:402103 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062104
[email protected]64d69de42012-02-06 00:19:542105 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402106 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542107 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062108 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542109 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062110 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2111 const DictionaryValue* inspector_settings =
2112 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2113 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182114 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2115 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062116 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182117 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542118 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182119 std::make_pair(iter.key(), value));
2120 }
[email protected]f3986f82012-01-03 20:00:062121 }
2122 }
[email protected]64d69de42012-02-06 00:19:542123 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062124
[email protected]ddf72142012-05-22 04:52:402125 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542126 web_prefs->javascript_enabled = false;
2127 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2128 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402129 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542130 web_prefs->plugins_enabled = false;
2131 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2132 web_prefs->java_enabled = false;
2133 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402134 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062135
[email protected]64d69de42012-02-06 00:19:542136 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2137 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062138
[email protected]64d69de42012-02-06 00:19:542139 web_prefs->memory_info_enabled =
2140 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2141 web_prefs->allow_displaying_insecure_content =
2142 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2143 web_prefs->allow_running_insecure_content =
2144 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322145#if defined(OS_ANDROID)
2146 web_prefs->font_scale_factor =
2147 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2148 web_prefs->force_enable_zoom =
2149 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2150#endif
[email protected]5c915252013-05-07 13:15:392151
[email protected]af4256d52013-06-04 20:39:072152#if defined(OS_ANDROID)
2153 web_prefs->password_echo_enabled =
2154 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2155#else
[email protected]9d06d88d2012-02-23 22:37:082156 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072157#endif
2158
[email protected]5c915252013-05-07 13:15:392159#if defined(OS_CHROMEOS)
2160 // Enable password echo during OOBE when keyboard driven flag is set.
2161 if (chromeos::UserManager::IsInitialized() &&
2162 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
[email protected]c94ac692013-07-27 00:50:102163 !chromeos::StartupUtils::IsOobeCompleted() &&
2164 chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation()) {
2165 web_prefs->password_echo_enabled = true;
[email protected]5c915252013-05-07 13:15:392166 }
2167#endif
[email protected]f3986f82012-01-03 20:00:062168
[email protected]46f8e742013-05-03 18:37:142169#if defined(OS_ANDROID)
2170 web_prefs->user_style_sheet_enabled = false;
2171#else
[email protected]64d69de42012-02-06 00:19:542172 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152173 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362174 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152175 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542176 web_prefs->user_style_sheet_enabled = true;
2177 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152178 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542179 } else {
2180 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062181 }
[email protected]46f8e742013-05-03 18:37:142182#endif
[email protected]f3986f82012-01-03 20:00:062183
[email protected]cfadadd2013-04-03 04:43:022184 web_prefs->asynchronous_spell_checking_enabled = true;
2185 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572186
[email protected]64d69de42012-02-06 00:19:542187 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062188 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542189 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062190 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542191 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062192 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2193
2194 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542195 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062196 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542197 web_prefs->default_encoding);
2198 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402199 prefs->ClearPref(prefs::kDefaultCharset);
2200 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062201 }
[email protected]64d69de42012-02-06 00:19:542202 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062203
[email protected]299d7f12012-05-23 05:31:152204 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232205 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132206 ExtensionService* service =
2207 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062208 if (service) {
[email protected]1bc28312012-11-08 08:31:532209 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2210 const Extension* extension = service->extensions()->GetByID(url.host());
2211 // Ensure that we are only granting extension preferences to URLs with
2212 // the correct scheme. Without this check, chrome-guest:// schemes used by
2213 // webview tags as well as hosts that happen to match the id of an
2214 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422215 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532216 extension_webkit_preferences::SetPreferences(
2217 extension, view_type, web_prefs);
2218 }
[email protected]f3986f82012-01-03 20:00:062219 }
2220
[email protected]cb2edf22013-04-01 20:25:232221 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542222 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232223 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062224 // Disable all kinds of acceleration for background pages.
2225 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542226 web_prefs->force_compositing_mode = false;
2227 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062228 }
[email protected]2e21fe292012-03-02 22:52:322229
2230#if defined(FILE_MANAGER_EXTENSION)
2231 // Override the default of suppressing HW compositing for WebUI pages for the
2232 // file manager, which is implemented using WebUI but wants HW acceleration
2233 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532234 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]2de96a52013-08-14 01:18:092235 url.host() == file_manager::kFileManagerAppId) {
[email protected]2e21fe292012-03-02 22:52:322236 web_prefs->accelerated_compositing_enabled = true;
2237 web_prefs->accelerated_2d_canvas_enabled = true;
2238 }
2239#endif
[email protected]181a95ee2011-07-12 19:26:362240}
2241
2242void ChromeContentBrowserClient::UpdateInspectorSetting(
2243 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062244 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582245 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062246 DictionaryPrefUpdate update(
2247 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2248 prefs::kWebKitInspectorSettings);
2249 DictionaryValue* inspector_settings = update.Get();
2250 inspector_settings->SetWithoutPathExpansion(key,
2251 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362252}
2253
[email protected]b8148ac2011-07-13 22:03:252254void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2255 BrowserURLHandler* handler) {
2256 // Add the default URL handlers.
2257 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2258 BrowserURLHandler::null_handler());
2259 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2260 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2261
[email protected]b3adbd02011-11-30 22:23:272262 // about: handler. Must come before chrome: handler, since it will
2263 // rewrite about: urls to chrome: URLs and then expect chrome: to
2264 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252265 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2266 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032267
2268 // Handler to rewrite chrome://newtab for InstantExtended.
2269 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2270 &chrome::HandleNewTabURLReverseRewrite);
2271
[email protected]b8148ac2011-07-13 22:03:252272 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242273 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252274}
2275
2276void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372277 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582278 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472279 BrowsingDataRemover* remover =
2280 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552281 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2282 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252283 // BrowsingDataRemover takes care of deleting itself when done.
2284}
2285
2286void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372287 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582288 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472289 BrowsingDataRemover* remover =
2290 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232291 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552292 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252293 // BrowsingDataRemover takes care of deleting itself when done.
2294}
2295
[email protected]650b2d52013-02-10 03:41:452296base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:492297 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:322298}
2299
[email protected]c9b6eb62011-10-18 20:49:392300std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2301 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2302}
2303
[email protected]b7631cc2012-09-15 05:08:382304void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2305 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542306#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382307 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2308 scoped_ptr<ppapi::host::HostFactory>(
2309 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542310#endif
[email protected]b7631cc2012-09-15 05:08:382311}
2312
[email protected]0c7193742012-11-07 19:05:032313content::BrowserPpapiHost*
2314 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2315 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132316 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032317 while (!iter.Done()) {
2318 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2319 if (host->process() &&
2320 host->process()->GetData().id == plugin_process_id) {
2321 // Found the plugin.
2322 return host->browser_ppapi_host();
2323 }
2324 ++iter;
2325 }
2326 return NULL;
2327}
2328
[email protected]7b38b192013-03-23 18:39:312329bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2330 content::BrowserContext* browser_context, const GURL& site_url) {
2331 if (CommandLine::ForCurrentProcess()->HasSwitch(
2332 switches::kEnableBrowserPluginForAllViewTypes))
2333 return true;
2334
2335 Profile* profile = Profile::FromBrowserContext(browser_context);
2336 ExtensionService* service =
2337 extensions::ExtensionSystem::Get(profile)->extension_service();
2338 if (!service)
2339 return false;
2340
[email protected]be9915fb2013-07-18 09:28:552341 const Extension* extension =
2342 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312343 if (!extension)
2344 return false;
2345
[email protected]c2d2f102013-04-29 16:42:582346 return extension->HasAPIPermission(APIPermission::kWebView) ||
2347 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312348}
2349
[email protected]38cd8f7f2012-06-15 22:06:072350bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582351 content::BrowserContext* browser_context,
2352 const GURL& url,
[email protected]dda54822013-06-15 01:26:392353 bool private_api,
[email protected]157cc902012-11-02 06:31:582354 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402355#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372356 Profile* profile = Profile::FromBrowserContext(browser_context);
2357 const ExtensionSet* extension_set = NULL;
2358 if (profile) {
2359 extension_set = extensions::ExtensionSystem::Get(profile)->
2360 extension_service()->extensions();
2361 }
[email protected]dda54822013-06-15 01:26:392362
2363 if (private_api) {
2364 // Access to private socket APIs is controlled by the whitelist.
2365 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2366 allowed_socket_origins_)) {
2367 return true;
2368 }
2369 } else {
2370 // Access to public socket APIs is controlled by extension permissions.
2371 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2372 extension_set) {
2373 const Extension* extension = extension_set->GetByID(url.host());
2374 if (extension) {
2375 extensions::SocketPermission::CheckParam check_params(
2376 params.type, params.host, params.port);
2377 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2378 extension, extensions::APIPermission::kSocket, &check_params)) {
2379 return true;
2380 }
2381 }
2382 }
2383 }
2384
2385 // Allow both public and private APIs if the command line says so.
2386 return IsHostAllowedByCommandLine(url, extension_set,
2387 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402388#else
[email protected]a658d452012-03-02 12:45:292389 return false;
[email protected]93f72062013-05-29 20:29:402390#endif
[email protected]e461da2f2012-02-16 19:06:402391}
2392
[email protected]a28e3302013-02-03 03:50:432393ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2394 WebContents* web_contents) {
2395 return new ChromeSelectFilePolicy(web_contents);
2396}
2397
[email protected]7d9424702013-04-14 13:14:162398void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2399 std::vector<std::string>* additional_allowed_schemes) {
2400 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2401 additional_allowed_schemes);
2402 additional_allowed_schemes->push_back(kChromeUIScheme);
2403 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2404}
2405
[email protected]f19bbf62013-07-09 01:22:322406void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312407 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532408 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322409 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532410#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032411 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322412 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032413 storage_partition_path,
2414 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322415 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532416#endif
[email protected]b40015c2013-06-26 08:13:312417#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312418 fileapi::ExternalMountPoints* external_mount_points =
2419 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312420 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322421 chromeos::FileSystemBackend* backend =
2422 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312423 new drive::FileSystemBackendDelegate(browser_context),
2424 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312425 external_mount_points,
2426 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322427 backend->AddSystemMountPoints();
2428 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2429 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312430#endif
[email protected]445b7db2013-08-02 04:58:272431
2432 additional_backends->push_back(new sync_file_system::SyncFileSystemBackend());
[email protected]02250952013-04-24 23:52:532433}
2434
[email protected]e60c0232011-11-11 19:56:352435#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182436void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2437 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382438 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082439 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392440#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452441 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392442 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2443 DCHECK(!data_path.empty());
2444
2445 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452446 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392447 data_path.AppendASCII("chrome_100_percent.pak");
[email protected]5db2b7492013-08-23 05:33:092448 base::PlatformFile f =
2449 base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
[email protected]29699c22012-10-03 23:57:392450 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372451 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392452 FileDescriptor(f, true)));
2453
2454 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452455 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392456 GetLocaleFilePath(locale, false);
2457 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2458 DCHECK(f != base::kInvalidPlatformFileValue);
2459 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2460 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382461
[email protected]650b2d52013-02-10 03:41:452462 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372463 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2464 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2465 DCHECK(f != base::kInvalidPlatformFileValue);
2466 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2467 FileDescriptor(f, true)));
2468
[email protected]82174aa2013-01-22 21:53:432469 if (IsCrashReporterEnabled()) {
2470 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2471 if (f == base::kInvalidPlatformFileValue) {
2472 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2473 "be disabled for this process.";
2474 } else {
2475 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2476 FileDescriptor(f, true)));
2477 }
[email protected]40da3e0c2012-10-24 22:03:382478 }
[email protected]40da3e0c2012-10-24 22:03:382479
2480#else
2481 int crash_signal_fd = GetCrashSignalFD(command_line);
2482 if (crash_signal_fd >= 0) {
2483 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2484 FileDescriptor(crash_signal_fd,
2485 false)));
2486 }
[email protected]29699c22012-10-03 23:57:392487#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302488}
[email protected]e60c0232011-11-11 19:56:352489#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302490
[email protected]4a65826d2011-08-25 16:04:012491#if defined(OS_WIN)
2492const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2493 return chrome::kBrowserResourcesDll;
2494}
[email protected]34f48682013-03-20 00:30:182495
2496void ChromeContentBrowserClient::PreSpawnRenderer(
2497 sandbox::TargetPolicy* policy,
2498 bool* success) {
2499 // This code is duplicated in nacl_exe_win_64.cc.
2500 // Allow the server side of a pipe restricted to the "chrome.nacl."
2501 // namespace so that it cannot impersonate other system or other chrome
2502 // service pipes.
2503 sandbox::ResultCode result = policy->AddRule(
2504 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2505 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2506 L"\\\\.\\pipe\\chrome.nacl.*");
2507 if (result != sandbox::SBOX_ALL_OK) {
2508 *success = false;
2509 return;
2510 }
2511
2512 // Renderers need to send named pipe handles and shared memory
2513 // segment handles to NaCl loader processes.
2514 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2515 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2516 L"File");
2517 if (result != sandbox::SBOX_ALL_OK) {
2518 *success = false;
2519 return;
2520 }
2521}
[email protected]4a65826d2011-08-25 16:04:012522#endif
2523
[email protected]37a72af2011-06-13 05:42:012524#if defined(USE_NSS)
2525crypto::CryptoModuleBlockingPasswordDelegate*
2526 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2527 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292528 return chrome::NewCryptoModuleBlockingDialogDelegate(
2529 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012530}
2531#endif
2532
[email protected]d977f9c2011-03-14 16:10:262533} // namespace chrome