blob: 1c3ee3a632df054c971fcdac210f5c8100471f7c [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]e1d16eb92011-08-18 23:19:3234#include "chrome/browser/download/download_util.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]8ec26472011-06-06 16:52:4582#include "chrome/browser/tab_contents/tab_util.h"
[email protected]a28e3302013-02-03 03:50:4383#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2584#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4485#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5086#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0687#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1588#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2789#include "chrome/browser/validation_message_message_filter.h"
[email protected]b80f68432011-05-02 17:22:3090#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0191#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1492#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3093#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2994#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0495#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3896#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4497#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4398#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:2999#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]dda54822013-06-15 01:26:39100#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]157cc902012-11-02 06:31:58101#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:34102#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37103#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12104#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38105#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09106#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53107#include "chromeos/chromeos_constants.h"
[email protected]d5d383252013-07-04 14:44:32108#include "components/nacl/common/nacl_process_type.h"
[email protected]75fee372013-03-06 00:42:44109#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43110#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30111#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38112#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03113#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31114#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03115#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59116#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36117#include "content/public/browser/compositor_util.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]445b7db2013-08-02 04:58:27141#include "webkit/browser/fileapi/syncable/sync_file_system_backend.h"
[email protected]fab55e72013-05-31 07:06:18142#include "webkit/common/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04143#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26144
[email protected]b48c9182011-10-26 18:03:30145#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38146#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18147#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38148#elif defined(OS_MACOSX)
149#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56150#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30151#elif defined(OS_CHROMEOS)
152#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]f19bbf62013-07-09 01:22:32153#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h"
154#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39155#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49156#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10157#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44158#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26159#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30160#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09161#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38162#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09163#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39164#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30165#elif defined(OS_POSIX)
166#include "chrome/browser/chrome_browser_main_posix.h"
167#endif
168
[email protected]6653c192012-04-10 22:52:44169#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30170#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12171#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43172#endif
[email protected]b80f68432011-05-02 17:22:30173
[email protected]190e5e22013-07-27 05:59:23174#if !defined(OS_ANDROID)
175#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
176#endif
177
[email protected]1e87df32012-09-12 04:53:19178#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
179#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
180#endif
181
[email protected]29699c22012-10-03 23:57:39182#if defined(OS_ANDROID)
183#include "ui/base/ui_base_paths.h"
184#endif
185
[email protected]37a72af2011-06-13 05:42:01186#if defined(USE_NSS)
187#include "chrome/browser/ui/crypto_module_password_dialog.h"
188#endif
189
[email protected]d5bcd06f2013-04-21 08:07:24190#if !defined(OS_CHROMEOS)
191#include "chrome/browser/signin/signin_manager.h"
192#include "chrome/browser/signin/signin_manager_factory.h"
193#endif
194
[email protected]02250952013-04-24 23:52:53195#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32196#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53197#endif
198
[email protected]6ef98b5a2013-05-31 23:58:31199#if defined(ENABLE_WEBRTC)
200#include "chrome/browser/media/webrtc_logging_handler_host.h"
201#endif
202
[email protected]855e18b2013-07-08 21:02:00203#if defined(ENABLE_INPUT_SPEECH)
204#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
205#endif
206
[email protected]02a3dc122013-06-13 15:07:53207#if defined(FILE_MANAGER_EXTENSION)
208#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
209#endif
210
[email protected]e8b6ca02013-07-10 18:00:51211#if defined(TOOLKIT_GTK)
212#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
213#endif
214
215#if defined(TOOLKIT_VIEWS)
216#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
217#endif
218
219#if defined(USE_ASH)
220#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
221#endif
222
223#if defined(USE_AURA)
224#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
225#endif
226
227#if defined(USE_X11)
228#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
229#endif
230
[email protected]c6ce08072013-07-31 07:48:53231#if defined(ENABLE_SPELLCHECK)
232#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
233#endif
234
[email protected]190e5e22013-07-27 05:59:23235using WebKit::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08236using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47237using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03238using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39239using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31240using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59241using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08242using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00243using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11244using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33245using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13246using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06247using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34248using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40249using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38250using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39251
[email protected]c5dbef02011-05-13 05:06:09252namespace {
253
[email protected]eabbfb12013-04-05 23:28:35254// Cached version of the locale so we can return the locale on the I/O
255// thread.
256base::LazyInstance<std::string> g_io_thread_application_locale;
257
[email protected]93f72062013-05-29 20:29:40258#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40259const char* kPredefinedAllowedSocketOrigins[] = {
260 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18261 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45262 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
263 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
264 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
265 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35266 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54267 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
268 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
269 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
270 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
271 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
272 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38273 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58274 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29275 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]f6599915a2013-06-20 20:03:50276 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
[email protected]b71313232013-05-06 06:16:29277 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
278 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
279 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
280 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40281};
[email protected]93f72062013-05-29 20:29:40282#endif
[email protected]e461da2f2012-02-16 19:06:40283
[email protected]f8f93eb2012-09-25 03:06:24284// Returns a copy of the given url with its host set to given host and path set
285// to given path. Other parts of the url will be the same.
286GURL ReplaceURLHostAndPath(const GURL& url,
287 const std::string& host,
288 const std::string& path) {
289 url_canon::Replacements<char> replacements;
290 replacements.SetHost(host.c_str(),
291 url_parse::Component(0, host.length()));
292 replacements.SetPath(path.c_str(),
293 url_parse::Component(0, path.length()));
294 return url.ReplaceComponents(replacements);
295}
296
297// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
298GURL AddUberHost(const GURL& url) {
299 const std::string uber_host = chrome::kChromeUIUberHost;
300 const std::string new_path = url.host() + url.path();
301
302 return ReplaceURLHostAndPath(url, uber_host, new_path);
303}
304
[email protected]045bf7c2012-09-28 20:27:36305// If url->host() is "chrome" and url->path() has characters other than the
306// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
307// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24308bool RemoveUberHost(GURL* url) {
309 if (url->host() != chrome::kChromeUIUberHost)
310 return false;
311
[email protected]045bf7c2012-09-28 20:27:36312 if (url->path().empty() || url->path() == "/")
313 return false;
314
[email protected]f8f93eb2012-09-25 03:06:24315 const std::string old_path = url->path();
316
317 const std::string::size_type separator = old_path.find('/', 1);
318 std::string new_host;
319 std::string new_path;
320 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36321 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24322 } else {
323 new_host = old_path.substr(1, separator - 1);
324 new_path = old_path.substr(separator);
325 }
326
[email protected]44e8add2013-06-13 17:29:15327 // Do not allow URLs with paths empty before the first slash since we can't
328 // have an empty host. (e.g "foo://chrome//")
329 if (new_host.empty())
330 return false;
331
[email protected]f8f93eb2012-09-25 03:06:24332 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
333
[email protected]44e8add2013-06-13 17:29:15334 DCHECK(url->is_valid());
335
[email protected]f8f93eb2012-09-25 03:06:24336 return true;
337}
338
[email protected]b8148ac2011-07-13 22:03:25339// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42340bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24341 // Do not handle special URLs such as "about:foo"
342 if (!url->host().empty()) {
343 const GURL chrome_url = AddUberHost(*url);
344
345 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
346 // be called.
347 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
348 browser_context, chrome_url))
349 return true;
350 }
351
[email protected]863f70a2012-01-27 02:05:50352 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
353 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25354 return false;
355
[email protected]fe69558d2012-03-12 11:34:49356#if defined(OS_CHROMEOS)
357 // Special case : in ChromeOS in Guest mode bookmarks and history are
358 // disabled for security reasons. New tab page explains the reasons, so
359 // we redirect user to new tab page.
360 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
361 if (url->SchemeIs(chrome::kChromeUIScheme) &&
362 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
363 url->DomainIs(chrome::kChromeUIHistoryHost))) {
364 // Rewrite with new tab URL
365 *url = GURL(chrome::kChromeUINewTabURL);
366 }
367 }
368#endif
369
[email protected]b8148ac2011-07-13 22:03:25370 // Special case the new tab page. In older versions of Chrome, the new tab
371 // page was hosted at chrome-internal:<blah>. This might be in people's saved
372 // sessions or bookmarks, so we say any URL with that scheme triggers the new
373 // tab page.
374 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
375 // Rewrite it with the proper new tab URL.
376 *url = GURL(chrome::kChromeUINewTabURL);
377 }
378
379 return true;
380}
381
[email protected]f8f93eb2012-09-25 03:06:24382// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
383// "chrome://foo/".
384bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
385 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
386 return false;
387
388 return RemoveUberHost(url);
389}
390
[email protected]8d3132f62011-10-12 07:13:42391// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
392// below. Extension, and isolated apps require different privileges to be
393// granted to their RenderProcessHosts. This classification allows us to make
394// sure URLs are served by hosts with the right set of privileges.
395enum RenderProcessHostPrivilege {
396 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45397 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42398 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45399 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42400};
401
402RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
403 const GURL& url,
404 ExtensionService* service) {
405 // Default to a normal renderer cause it is lower privileged. This should only
406 // occur if the URL on a site instance is either malformed, or uninitialized.
407 // If it is malformed, then there is no need for better privileges anyways.
408 // If it is uninitialized, but eventually settles on being an a scheme other
409 // than normal webrenderer, the navigation logic will correct us out of band
410 // anyways.
411 if (!url.is_valid())
412 return PRIV_NORMAL;
413
[email protected]885c0e92012-11-13 20:27:42414 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44415 const Extension* extension =
416 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43417 if (extension &&
418 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42419 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45420 if (extension && extension->is_hosted_app())
421 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42422
423 return PRIV_EXTENSION;
424 }
425
426 return PRIV_NORMAL;
427}
428
429RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30430 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46431 extensions::ProcessMap* process_map,
432 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46433 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30434 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46435 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21436 return PRIV_NORMAL;
437
[email protected]6f371442011-11-09 06:45:46438 for (std::set<std::string>::iterator iter = extension_ids.begin();
439 iter != extension_ids.end(); ++iter) {
440 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43441 if (extension &&
442 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42443 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45444 if (extension && extension->is_hosted_app())
445 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42446 }
447
[email protected]676f6ab2011-10-19 20:23:21448 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42449}
450
[email protected]6786bf402011-12-03 15:19:45451bool CertMatchesFilter(const net::X509Certificate& cert,
452 const base::DictionaryValue& filter) {
453 // TODO(markusheintz): This is the minimal required filter implementation.
454 // Implement a better matcher.
455
456 // An empty filter matches any client certificate since no requirements are
457 // specified at all.
458 if (filter.empty())
459 return true;
460
461 std::string common_name;
462 if (filter.GetString("ISSUER.CN", &common_name) &&
463 (cert.issuer().common_name == common_name)) {
464 return true;
465 }
466 return false;
467}
468
[email protected]f3986f82012-01-03 20:00:06469// Fills |map| with the per-script font prefs under path |map_name|.
470void FillFontFamilyMap(const PrefService* prefs,
471 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53472 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06473 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
474 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
475 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
476 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23477 if (!font_family.empty())
478 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06479 }
480}
481
[email protected]a1733df2012-06-22 11:24:18482#if defined(OS_POSIX) && !defined(OS_MACOSX)
483int GetCrashSignalFD(const CommandLine& command_line) {
484 if (command_line.HasSwitch(switches::kExtensionProcess)) {
485 ExtensionCrashHandlerHostLinux* crash_handler =
486 ExtensionCrashHandlerHostLinux::GetInstance();
487 return crash_handler->GetDeathSignalSocket();
488 }
489
490 std::string process_type =
491 command_line.GetSwitchValueASCII(switches::kProcessType);
492
493 if (process_type == switches::kRendererProcess)
494 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
495
496 if (process_type == switches::kPluginProcess)
497 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
498
499 if (process_type == switches::kPpapiPluginProcess)
500 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
501
502 if (process_type == switches::kGpuProcess)
503 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
504
505 return -1;
506}
507#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
508
[email protected]d5bcd06f2013-04-21 08:07:24509#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30510GURL GetEffectiveURLForSignin(const GURL& url) {
511 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
512
513 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03514 // Copy the path because the argument to SetPathStr must outlive
515 // the Replacements object.
516 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30517 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03518 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30519 effective_url = effective_url.ReplaceComponents(replacements);
520 return effective_url;
521}
[email protected]d5bcd06f2013-04-21 08:07:24522#endif
[email protected]970c63e2013-03-07 00:25:30523
[email protected]eabbfb12013-04-05 23:28:35524void SetApplicationLocaleOnIOThread(const std::string& locale) {
525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
526 g_io_thread_application_locale.Get() = locale;
527}
528
[email protected]190e5e22013-07-27 05:59:23529#if !defined(OS_ANDROID)
530struct BlockedPopupParams {
531 BlockedPopupParams(const GURL& target_url,
532 const content::Referrer& referrer,
533 WindowOpenDisposition disposition,
534 const WebWindowFeatures& features,
535 bool user_gesture,
536 bool opener_suppressed,
537 int render_process_id,
538 int opener_id)
539 : target_url(target_url),
540 referrer(referrer),
541 disposition(disposition),
542 features(features),
543 user_gesture(user_gesture),
544 opener_suppressed(opener_suppressed),
545 render_process_id(render_process_id),
546 opener_id(opener_id)
547 {}
548
549 GURL target_url;
550 content::Referrer referrer;
551 WindowOpenDisposition disposition;
552 WebWindowFeatures features;
553 bool user_gesture;
554 bool opener_suppressed;
555 int render_process_id;
556 int opener_id;
557};
558
559void HandleBlockedPopupOnUIThread(const BlockedPopupParams& params) {
560 WebContents* tab =
561 tab_util::GetWebContentsByID(params.render_process_id, params.opener_id);
562 if (!tab)
563 return;
564
565 prerender::PrerenderManager* prerender_manager =
566 prerender::PrerenderManagerFactory::GetForProfile(
567 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]668cf6e2013-07-29 19:42:25568 if (prerender_manager) {
569 prerender_manager->DestroyPrerenderForRenderView(
570 params.render_process_id,
571 params.opener_id,
572 prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
573 }
[email protected]190e5e22013-07-27 05:59:23574
575 PopupBlockerTabHelper* popup_helper =
576 PopupBlockerTabHelper::FromWebContents(tab);
577 if (!popup_helper)
578 return;
579 popup_helper->AddBlockedPopup(params.target_url,
580 params.referrer,
581 params.disposition,
582 params.features,
583 params.user_gesture,
584 params.opener_suppressed);
585}
586#endif
587
[email protected]9dbfff12011-07-01 19:37:07588} // namespace
[email protected]c5dbef02011-05-13 05:06:09589
[email protected]d977f9c2011-03-14 16:10:26590namespace chrome {
591
[email protected]e461da2f2012-02-16 19:06:40592ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40593#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40594 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
595 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40596#endif
[email protected]1deace22013-05-22 06:14:46597
598 permissions_policy_delegate_.reset(
599 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40600}
601
602ChromeContentBrowserClient::~ChromeContentBrowserClient() {
603}
604
[email protected]bca18382012-06-25 19:15:23605// static
[email protected]37ca3fe02013-07-05 15:32:44606void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34607 user_prefs::PrefRegistrySyncable* registry) {
608 registry->RegisterBooleanPref(
609 prefs::kDisable3DAPIs,
610 false,
611 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
612 registry->RegisterBooleanPref(
613 prefs::kEnableHyperlinkAuditing,
614 true,
615 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
616 registry->RegisterBooleanPref(
617 prefs::kEnableMemoryInfo,
618 false,
619 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23620}
621
[email protected]eabbfb12013-04-05 23:28:35622// static
623void ChromeContentBrowserClient::SetApplicationLocale(
624 const std::string& locale) {
625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
626
627 // This object is guaranteed to outlive all threads so we don't have to
628 // worry about the lack of refcounting and can just post as Unretained.
629 //
630 // The common case is that this function is called early in Chrome startup
631 // before any threads are created (it will also be called later if the user
632 // changes the pref). In this case, there will be no threads created and
633 // posting will fail. When there are no threads, we can just set the string
634 // without worrying about threadsafety.
635 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
636 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
637 g_io_thread_application_locale.Get() = locale;
638 }
639}
640
[email protected]50462bf02011-11-21 19:13:31641content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
642 const content::MainFunctionParams& parameters) {
643 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30644 // Construct the Main browser parts based on the OS type.
645#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31646 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04647#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31648 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30649#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22650 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26651#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31652 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14653#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09654 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30655#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31656 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04657#else
[email protected]b48c9182011-10-26 18:03:30658 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31659 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30660#endif
661
[email protected]7e75e4a2013-05-17 17:20:03662 chrome::AddProfilesExtraParts(main_parts);
663
[email protected]c7480942011-11-08 19:18:27664 // Construct additional browser parts. Stages are called in the order in
665 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22666#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51667 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04668#endif
[email protected]c7480942011-11-08 19:18:27669
670#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51671 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27672#endif
673
[email protected]dc04be7c2012-03-15 23:57:49674#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51675 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49676#endif
677
[email protected]e050ef142012-03-21 01:04:24678#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51679 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
680#endif
681
682#if defined(USE_X11)
683 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24684#endif
685
[email protected]95132f52013-04-12 02:19:04686 chrome::AddMetricsExtraParts(main_parts);
687
[email protected]50462bf02011-11-21 19:13:31688 return main_parts;
[email protected]f967b722011-09-07 00:58:04689}
690
[email protected]e94bbcb2012-09-07 05:33:57691std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19692 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57693 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53694 std::string partition_id;
695
696 // The partition ID for webview guest processes is the string value of its
697 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
698 if (site.SchemeIs(chrome::kGuestScheme))
699 partition_id = site.spec();
700
[email protected]056efdc2013-04-06 00:14:53701 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53702 return partition_id;
703}
704
705bool ChromeContentBrowserClient::IsValidStoragePartitionId(
706 content::BrowserContext* browser_context,
707 const std::string& partition_id) {
708 // The default ID is empty and is always valid.
709 if (partition_id.empty())
710 return true;
711
712 return GURL(partition_id).is_valid();
713}
714
715void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
716 content::BrowserContext* browser_context,
717 const GURL& site,
[email protected]14acc642012-11-17 12:20:10718 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53719 std::string* partition_domain,
720 std::string* partition_name,
721 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10722 // Default to the browser-wide storage partition and override based on |site|
723 // below.
724 partition_domain->clear();
725 partition_name->clear();
726 *in_memory = false;
727
[email protected]1bc28312012-11-08 08:31:53728 // For the webview tag, we create special guest processes, which host the
729 // tag content separately from the main application that embeds the tag.
730 // A webview tag can specify both the partition name and whether the storage
731 // for that partition should be persisted. Each tag gets a SiteInstance with
732 // a specially formatted URL, based on the application it is hosted by and
733 // the partition requested by it. The format for that URL is:
734 // chrome-guest://partition_domain/persist?partition_name
735 if (site.SchemeIs(chrome::kGuestScheme)) {
736 // Since guest URLs are only used for packaged apps, there must be an app
737 // id in the URL.
738 CHECK(site.has_host());
739 *partition_domain = site.host();
740 // Since persistence is optional, the path must either be empty or the
741 // literal string.
742 *in_memory = (site.path() != "/persist");
743 // The partition name is user supplied value, which we have encoded when the
744 // URL was created, so it needs to be decoded.
745 *partition_name = net::UnescapeURLComponent(site.query(),
746 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10747 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
748 // If |can_be_default| is false, the caller is stating that the |site|
749 // should be parsed as if it had isolated storage. In particular it is
750 // important to NOT check ExtensionService for the is_storage_isolated()
751 // attribute because this code path is run during Extension uninstall
752 // to do cleanup after the Extension has already been unloaded from the
753 // ExtensionService.
754 bool is_isolated = !can_be_default;
755 if (can_be_default) {
756 const Extension* extension = NULL;
757 Profile* profile = Profile::FromBrowserContext(browser_context);
758 ExtensionService* extension_service =
759 extensions::ExtensionSystem::Get(profile)->extension_service();
760 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55761 extension =
762 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43763 if (extension &&
764 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10765 is_isolated = true;
766 }
767 }
768 }
[email protected]1bc28312012-11-08 08:31:53769
[email protected]14acc642012-11-17 12:20:10770 if (is_isolated) {
771 CHECK(site.has_host());
772 // For extensions with isolated storage, the the host of the |site| is
773 // the |partition_domain|. The |in_memory| and |partition_name| are only
774 // used in guest schemes so they are cleared here.
775 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53776 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10777 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53778 }
[email protected]d1198fd2012-08-13 22:50:19779 }
780
[email protected]14acc642012-11-17 12:20:10781 // Assert that if |can_be_default| is false, the code above must have found a
782 // non-default partition. If this fails, the caller has a serious logic
783 // error about which StoragePartition they expect to be in and it is not
784 // safe to continue.
785 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44786}
787
[email protected]38b098f2012-03-14 21:11:57788content::WebContentsViewDelegate*
789 ChromeContentBrowserClient::GetWebContentsViewDelegate(
790 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27791 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32792}
793
[email protected]24665682013-02-25 20:59:38794// Check if the extension activity log is enabled for the profile.
795static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33796 // crbug.com/247908 - This should be IsLogEnabled except for an issue
797 // in chrome_frame_net_tests
798 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38799}
800
[email protected]738f57a2013-06-29 21:06:54801void ChromeContentBrowserClient::GuestWebContentsCreated(
802 WebContents* guest_web_contents,
803 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22804 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54805 scoped_ptr<base::DictionaryValue> extra_params) {
806 if (opener_web_contents) {
807 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
808 if (!guest) {
809 NOTREACHED();
810 return;
811 }
812
813 switch (guest->GetViewType()) {
814 case GuestView::WEBVIEW: {
[email protected]4c0e8272013-07-03 23:39:22815 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54816 break;
817 }
818 case GuestView::ADVIEW: {
[email protected]4c0e8272013-07-03 23:39:22819 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54820 break;
821 }
822 default:
823 NOTREACHED();
824 break;
825 }
826 return;
827 }
828
829 if (!extra_params) {
830 NOTREACHED();
831 return;
832 }
833 std::string api_type;
834 extra_params->GetString(guestview::kAttributeApi, &api_type);
835
836 if (api_type == "adview") {
[email protected]4c0e8272013-07-03 23:39:22837 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54838 } else if (api_type == "webview") {
[email protected]4c0e8272013-07-03 23:39:22839 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54840 } else {
841 NOTREACHED();
842 }
843}
844
[email protected]44295a12013-06-05 08:45:46845void ChromeContentBrowserClient::GuestWebContentsAttached(
846 WebContents* guest_web_contents,
847 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53848 int browser_plugin_instance_id,
849 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06850 Profile* profile = Profile::FromBrowserContext(
851 embedder_web_contents->GetBrowserContext());
852 ExtensionService* service =
853 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54854 if (!service) {
855 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06856 return;
[email protected]738f57a2013-06-29 21:06:54857 }
[email protected]44703cc72013-01-24 04:56:06858 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
[email protected]be9915fb2013-07-18 09:28:55859 const Extension* extension =
860 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]738f57a2013-06-29 21:06:54861 if (!extension) {
[email protected]18699372013-06-25 20:42:55862 NOTREACHED();
[email protected]738f57a2013-06-29 21:06:54863 return;
[email protected]18699372013-06-25 20:42:55864 }
[email protected]738f57a2013-06-29 21:06:54865
866 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
867 if (!guest) {
868 NOTREACHED();
869 return;
870 }
871 guest->Attach(embedder_web_contents,
872 extension->id(),
873 browser_plugin_instance_id,
874 extra_params);
[email protected]44703cc72013-01-24 04:56:06875}
876
[email protected]f3b1a082011-11-18 00:34:30877void ChromeContentBrowserClient::RenderProcessHostCreated(
878 content::RenderProcessHost* host) {
879 int id = host->GetID();
880 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41881 net::URLRequestContextGetter* context =
882 profile->GetRequestContextForRenderProcess(id);
883
[email protected]f3b1a082011-11-18 00:34:30884 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41885 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55886#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30887 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55888#endif
[email protected]658677f2012-06-09 06:04:02889#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08890 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03891#endif
[email protected]f3b1a082011-11-18 00:34:30892 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02893 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53894#if defined(ENABLE_SPELLCHECK)
[email protected]f3b1a082011-11-18 00:34:30895 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53896#endif
[email protected]7ceb99012011-12-21 08:05:56897#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21898 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56899#endif
[email protected]43535512013-02-20 20:41:41900 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
901 id, profile, context));
[email protected]2736c032012-05-11 18:06:07902 host->GetChannel()->AddFilter(
903 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27904 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33905 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31906#if defined(ENABLE_WEBRTC)
907 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
908#endif
[email protected]01e59752013-06-18 00:17:35909#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03910 ExtensionInfoMap* extension_info_map =
911 extensions::ExtensionSystem::Get(profile)->info_map();
912 host->GetChannel()->AddFilter(new NaClHostMessageFilter(
913 id, profile->IsOffTheRecord(),
914 profile->GetPath(), extension_info_map,
915 context));
[email protected]01e59752013-06-18 00:17:35916#endif
[email protected]3e69bc82011-05-26 23:22:38917
[email protected]2ccf45c2011-08-19 23:35:50918 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
919 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07920
[email protected]24665682013-02-25 20:59:38921 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
922 IsExtensionActivityLogEnabledForProfile(profile)));
923
[email protected]39a5b532011-10-22 01:47:07924 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56925
926 RendererContentSettingRules rules;
927 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
928 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14929}
930
[email protected]3d7474ff2011-07-27 17:47:37931GURL ChromeContentBrowserClient::GetEffectiveURL(
932 content::BrowserContext* browser_context, const GURL& url) {
933 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52934 if (!profile)
935 return url;
936
[email protected]b3cb3a32013-07-31 01:32:29937 // If the input |url| should be assigned to the Instant renderer, make its
938 // effective URL distinct from other URLs on the search provider's domain.
939 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
940 return chrome::GetEffectiveURLForInstant(url, profile);
941
[email protected]d5bcd06f2013-04-21 08:07:24942#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30943 // If the input |url| should be assigned to the Signin renderer, make its
944 // effective URL distinct from other URLs on the signin service's domain.
945 // Note that the signin renderer will be allowed to sign the user in to
946 // Chrome.
947 if (SigninManager::IsWebBasedSigninFlowURL(url))
948 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24949#endif
[email protected]970c63e2013-03-07 00:25:30950
[email protected]c5dec6292013-01-25 04:54:52951 // If the input |url| is part of an installed app, the effective URL is an
952 // extension URL with the ID of that extension as the host. This has the
953 // effect of grouping apps together in a common SiteInstance.
954 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13955 extensions::ExtensionSystem::Get(profile)->extension_service();
956 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08957 return url;
958
[email protected]06bdd2b2012-11-30 18:47:13959 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55960 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08961 if (!extension)
962 return url;
963
[email protected]15877ca2011-11-18 22:40:52964 // Bookmark apps do not use the hosted app process model, and should be
965 // treated as normal URLs.
966 if (extension->from_bookmark())
967 return url;
968
[email protected]36fb2c7c2011-04-04 15:49:08969 // If the URL is part of an extension's web extent, convert it to an
970 // extension URL.
971 return extension->GetResourceURL(url.path());
972}
973
[email protected]056ad2a2011-07-12 02:13:55974bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37975 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52976 // Non-extension, non-Instant URLs should generally use
977 // process-per-site-instance. Because we expect to use the effective URL,
978 // URLs for hosted apps (apart from bookmark apps) should have an extension
979 // scheme by now.
980
981 Profile* profile = Profile::FromBrowserContext(browser_context);
982 if (!profile)
983 return false;
984
[email protected]df113a12013-07-24 04:56:08985 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52986 return true;
987
[email protected]d5bcd06f2013-04-21 08:07:24988#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30989 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
990 return true;
[email protected]d5bcd06f2013-04-21 08:07:24991#endif
[email protected]970c63e2013-03-07 00:25:30992
[email protected]885c0e92012-11-13 20:27:42993 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55994 return false;
995
[email protected]c5dec6292013-01-25 04:54:52996 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13997 extensions::ExtensionSystem::Get(profile)->extension_service();
998 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55999 return false;
1000
[email protected]be9915fb2013-07-18 09:28:551001 const Extension* extension =
1002 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:551003 if (!extension)
1004 return false;
1005
1006 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:531007 // permission, or that does not allow JavaScript access to the background
1008 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:551009 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:401010 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:061011 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:291012 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:531013 return false;
1014 }
1015 }
[email protected]056ad2a2011-07-12 02:13:551016
[email protected]7b54ca02012-03-02 18:06:531017 // Hosted apps that have script access to their background page must use
1018 // process per site, since all instances can make synchronous calls to the
1019 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:551020 return true;
1021}
1022
[email protected]672c8c12013-03-07 12:30:061023// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:411024void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1025 std::vector<std::string>* additional_schemes) {
1026 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:061027}
1028
[email protected]6bd30072013-02-08 18:17:111029net::URLRequestContextGetter*
1030ChromeContentBrowserClient::CreateRequestContext(
1031 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:061032 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111033 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:061034 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111035}
1036
1037net::URLRequestContextGetter*
1038ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1039 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:401040 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:111041 bool in_memory,
[email protected]672c8c12013-03-07 12:30:061042 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111043 Profile* profile = Profile::FromBrowserContext(browser_context);
1044 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:061045 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111046}
1047
[email protected]46fb9442011-12-09 17:57:471048bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1049 return ProfileIOData::IsHandledURL(url);
1050}
1051
[email protected]c4365fa42013-05-14 01:08:241052bool ChromeContentBrowserClient::CanCommitURL(
1053 content::RenderProcessHost* process_host,
1054 const GURL& url) {
1055 // We need to let most extension URLs commit in any process, since this can
1056 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1057 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1058 // cannot be loaded in iframes and should never be requested outside its
1059 // process.
1060 Profile* profile =
1061 Profile::FromBrowserContext(process_host->GetBrowserContext());
1062 ExtensionService* service =
1063 extensions::ExtensionSystem::Get(profile)->extension_service();
1064 if (!service)
1065 return true;
1066 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551067 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241068 if (new_extension &&
1069 new_extension->is_hosted_app() &&
1070 new_extension->id() == extension_misc::kWebStoreAppId &&
1071 !service->process_map()->Contains(new_extension->id(),
1072 process_host->GetID())) {
1073 return false;
1074 }
1075
1076 return true;
1077}
1078
[email protected]2a5221b2011-09-27 23:07:311079bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301080 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311081 const GURL& site_url) {
1082 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301083 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521084 // This may be NULL during tests. In that case, just assume any site can
1085 // share any host.
1086 if (!profile)
1087 return true;
1088
[email protected]d43f99fe2013-04-03 00:20:141089 // Instant URLs should only be in the instant process and instant process
1090 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521091 InstantService* instant_service =
1092 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141093 if (instant_service) {
1094 bool is_instant_process = instant_service->IsInstantProcess(
1095 process_host->GetID());
1096 bool should_be_in_instant_process =
1097 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1098 if (is_instant_process || should_be_in_instant_process)
1099 return is_instant_process && should_be_in_instant_process;
1100 }
[email protected]c5dec6292013-01-25 04:54:521101
[email protected]d5bcd06f2013-04-21 08:07:241102#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301103 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1104 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1105 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241106#endif
[email protected]970c63e2013-03-07 00:25:301107
[email protected]06bdd2b2012-11-30 18:47:131108 ExtensionService* service =
1109 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461110 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311111
[email protected]ffa97602011-11-17 17:55:521112 // Don't allow the Task Manager to share a process with anything else.
1113 // Otherwise it can affect the renderers it is observing.
1114 // Note: we could create another RenderProcessHostPrivilege bucket for
1115 // this to allow multiple chrome://tasks instances to share, but that's
1116 // a very unlikely case without serious consequences.
1117 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1118 return false;
1119
[email protected]8d3132f62011-10-12 07:13:421120 // These may be NULL during tests. In that case, just assume any site can
1121 // share any host.
[email protected]6f371442011-11-09 06:45:461122 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311123 return true;
1124
[email protected]eec0b33c2011-12-05 22:09:451125 // Otherwise, just make sure the process privilege matches the privilege
1126 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571127 RenderProcessHostPrivilege privilege_required =
1128 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451129 return GetProcessPrivilege(process_host, process_map, service) ==
1130 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311131}
1132
[email protected]76411f412012-02-22 18:56:061133// This function is trying to limit the amount of processes used by extensions
1134// with background pages. It uses a globally set percentage of processes to
1135// run such extensions and if the limit is exceeded, it returns true, to
1136// indicate to the content module to group extensions together.
1137bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1138 content::BrowserContext* browser_context, const GURL& url) {
1139 // It has to be a valid URL for us to check for an extension.
1140 if (!url.is_valid())
1141 return false;
1142
1143 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191144 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131145 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061146 if (!service)
1147 return false;
1148
1149 // We have to have a valid extension with background page to proceed.
1150 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551151 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061152 if (!extension)
1153 return false;
[email protected]9367eabc2013-03-01 01:29:291154 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061155 return false;
1156
1157 std::set<int> process_ids;
1158 size_t max_process_count =
1159 content::RenderProcessHost::GetMaxRendererProcessCount();
1160
1161 // Go through all profiles to ensure we have total count of extension
1162 // processes containing background pages, otherwise one profile can
1163 // starve the other.
1164 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1165 GetLoadedProfiles();
1166 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031167 ExtensionProcessManager* epm =
1168 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321169 for (ExtensionProcessManager::const_iterator iter =
1170 epm->background_hosts().begin();
1171 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131172 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321173 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061174 }
1175 }
1176
1177 if (process_ids.size() >
1178 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1179 return true;
1180 }
1181
1182 return false;
1183}
1184
[email protected]6f371442011-11-09 06:45:461185void ChromeContentBrowserClient::SiteInstanceGotProcess(
1186 SiteInstance* site_instance) {
1187 CHECK(site_instance->HasProcess());
1188
1189 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021190 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521191 if (!profile)
1192 return;
1193
1194 // Remember the ID of the Instant process to signal the renderer process
1195 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031196 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321197 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521198 InstantService* instant_service =
1199 InstantServiceFactory::GetForProfile(profile);
1200 if (instant_service)
1201 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1202 }
1203
[email protected]d5bcd06f2013-04-21 08:07:241204#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301205 // We only expect there to be one signin process as we use process-per-site
1206 // for signin URLs. The signin process will be cleared from SigninManager
1207 // when the renderer is destroyed.
1208 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1209 SigninManager* signin_manager =
1210 SigninManagerFactory::GetForProfile(profile);
1211 if (signin_manager)
1212 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461213 BrowserThread::PostTask(
1214 BrowserThread::IO, FROM_HERE,
1215 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1216 extensions::ExtensionSystem::Get(profile)->info_map(),
1217 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301218 }
[email protected]d5bcd06f2013-04-21 08:07:241219#endif
[email protected]970c63e2013-03-07 00:25:301220
[email protected]06bdd2b2012-11-30 18:47:131221 ExtensionService* service =
1222 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461223 if (!service)
1224 return;
1225
[email protected]be9915fb2013-07-18 09:28:551226 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1227 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461228 if (!extension)
1229 return;
1230
[email protected]6bc04fd82011-12-04 02:29:351231 service->process_map()->Insert(extension->id(),
1232 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331233 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461234 BrowserThread::PostTask(
1235 BrowserThread::IO, FROM_HERE,
1236 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591237 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461238 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351239 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331240 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461241}
1242
1243void ChromeContentBrowserClient::SiteInstanceDeleting(
1244 SiteInstance* site_instance) {
1245 if (!site_instance->HasProcess())
1246 return;
1247
1248 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021249 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131250 ExtensionService* service =
1251 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461252 if (!service)
1253 return;
1254
[email protected]be9915fb2013-07-18 09:28:551255 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1256 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461257 if (!extension)
1258 return;
1259
[email protected]6bc04fd82011-12-04 02:29:351260 service->process_map()->Remove(extension->id(),
1261 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331262 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461263 BrowserThread::PostTask(
1264 BrowserThread::IO, FROM_HERE,
1265 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591266 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461267 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351268 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331269 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461270}
1271
[email protected]f05763972012-06-06 18:17:261272bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141273 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081274 const GURL& current_url,
1275 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261276 if (current_url.is_empty()) {
1277 // Always choose a new process when navigating to extension URLs. The
1278 // process grouping logic will combine all of a given extension's pages
1279 // into the same process.
[email protected]885c0e92012-11-13 20:27:421280 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261281 return true;
[email protected]e3daf3c2011-10-05 21:17:081282
[email protected]f05763972012-06-06 18:17:261283 return false;
1284 }
1285
1286 // Also, we must switch if one is an extension and the other is not the exact
1287 // same extension.
[email protected]885c0e92012-11-13 20:27:421288 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1289 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261290 if (current_url.GetOrigin() != new_url.GetOrigin())
1291 return true;
1292 }
1293
[email protected]e9841fbd2013-02-22 23:12:141294 // The checks below only matter if we can retrieve which extensions are
1295 // installed.
1296 Profile* profile =
1297 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1298 ExtensionService* service =
1299 extensions::ExtensionSystem::Get(profile)->extension_service();
1300 if (!service)
1301 return false;
1302
1303 // We must swap if the URL is for an extension and we are not using an
1304 // extension process.
1305 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551306 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141307 // Ignore all hosted apps except the Chrome Web Store, since they do not
1308 // require their own BrowsingInstance (e.g., postMessage is ok).
1309 if (new_extension &&
1310 new_extension->is_hosted_app() &&
1311 new_extension->id() != extension_misc::kWebStoreAppId)
1312 new_extension = NULL;
1313 if (new_extension &&
1314 site_instance->HasProcess() &&
1315 !service->process_map()->Contains(new_extension->id(),
1316 site_instance->GetProcess()->GetID()))
1317 return true;
1318
[email protected]f05763972012-06-06 18:17:261319 return false;
[email protected]e3daf3c2011-10-05 21:17:081320}
1321
[email protected]395045c2012-05-22 15:04:381322bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1323 content::ResourceContext* resource_context, const GURL& current_url,
1324 const GURL& new_url) {
1325 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1326 return extensions::CrossesExtensionProcessBoundary(
1327 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551328 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381329}
1330
[email protected]3d831992013-07-04 01:13:291331bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1332 return !url.SchemeIs(chrome::kChromeNativeScheme);
1333}
1334
[email protected]763ec4ca2011-04-29 15:48:121335std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1336 const std::string& alias_name) {
1337 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1338}
1339
[email protected]b80f68432011-05-02 17:22:301340void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1341 CommandLine* command_line, int child_process_id) {
[email protected]97425082013-07-16 03:10:071342#if defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301343 if (IsCrashReporterEnabled()) {
1344 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1345 child_process_logging::GetClientId());
1346 }
[email protected]97425082013-07-16 03:10:071347#elif defined(OS_POSIX)
1348 if (IsCrashReporterEnabled()) {
1349 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1350 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1351 }
1352
[email protected]b80f68432011-05-02 17:22:301353#endif // OS_MACOSX
1354
[email protected]f1933792011-06-14 00:49:341355 if (logging::DialogsAreSuppressed())
1356 command_line->AppendSwitch(switches::kNoErrorDialogs);
1357
[email protected]b80f68432011-05-02 17:22:301358 std::string process_type =
1359 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171360 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321361
1362 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1363 command_line->AppendSwitch(switches::kChromeFrame);
1364
[email protected]718eab62011-10-05 21:16:521365 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451366 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301367 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1368 if (!user_data_dir.empty())
1369 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1370#if defined(OS_CHROMEOS)
1371 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441372 browser_command_line.GetSwitchValueASCII(
1373 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301374 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441375 command_line->AppendSwitchASCII(
1376 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301377#endif
1378
[email protected]f3b1a082011-11-18 00:34:301379 content::RenderProcessHost* process =
1380 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371381 if (process) {
1382 Profile* profile = Profile::FromBrowserContext(
1383 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131384 ExtensionService* extension_service =
1385 extensions::ExtensionSystem::Get(profile)->extension_service();
1386 if (extension_service) {
1387 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001388 if (process_map && process_map->Contains(process->GetID()))
1389 command_line->AppendSwitch(switches::kExtensionProcess);
1390 }
[email protected]b80f68432011-05-02 17:22:301391
[email protected]a8d851f82011-12-21 00:32:371392 PrefService* prefs = profile->GetPrefs();
1393 // Currently this pref is only registered if applied via a policy.
1394 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1395 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1396 // Turn this policy into a command line switch.
1397 command_line->AppendSwitch(switches::kDisable3DAPIs);
1398 }
[email protected]718eab62011-10-05 21:16:521399
[email protected]a8d851f82011-12-21 00:32:371400 // Disable client-side phishing detection in the renderer if it is
1401 // disabled in the Profile preferences or the browser process.
1402 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1403 !g_browser_process->safe_browsing_detection_service()) {
1404 command_line->AppendSwitch(
1405 switches::kDisableClientSidePhishingDetection);
1406 }
[email protected]0045b0f42012-07-26 11:52:081407
1408 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211409 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521410
1411 InstantService* instant_service =
1412 InstantServiceFactory::GetForProfile(profile);
1413 if (instant_service &&
1414 instant_service->IsInstantProcess(process->GetID()))
1415 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301416
[email protected]d5bcd06f2013-04-21 08:07:241417#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301418 SigninManager* signin_manager =
1419 SigninManagerFactory::GetForProfile(profile);
1420 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1421 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241422#endif
[email protected]47c7ec82012-01-18 03:29:211423 }
[email protected]4287a3d2011-06-13 23:56:511424
[email protected]87552982012-11-02 17:21:401425 if (content::IsThreadedCompositingEnabled())
1426 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1427
[email protected]16dc42452013-04-09 04:37:191428 if (message_center::IsRichNotificationEnabled())
1429 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191430
[email protected]47c7ec82012-01-18 03:29:211431 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511432 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171433 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481434 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171435 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]49d9b142013-07-19 08:50:271436 extensions::switches::kAllowLegacyExtensionManifests,
1437 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511438 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271439 extensions::switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511440 switches::kAllowHTTPBackgroundPage,
[email protected]9d450492013-06-13 23:08:371441 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1442 // to browser.
1443 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511444 switches::kAppsCheckoutURL,
1445 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311446 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511447 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501448 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531449 switches::kDisableExtensionsResourceWhitelist,
[email protected]df4015352013-07-26 23:18:181450 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111451 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531452 switches::kEnableAdview,
1453 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441454 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211455 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511456 switches::kEnableIPCFuzzing,
1457 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451458 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481459 switches::kEnablePasswordGeneration,
[email protected]4287a3d2011-06-13 23:56:511460 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511461 switches::kMemoryProfiling,
1462 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371463 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371464 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511465 switches::kPpapiFlashArgs,
1466 switches::kPpapiFlashInProcess,
1467 switches::kPpapiFlashPath,
1468 switches::kPpapiFlashVersion,
1469 switches::kProfilingAtStart,
1470 switches::kProfilingFile,
1471 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371472 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511473 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291474 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381475 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511476 };
1477
1478 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1479 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171480 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381481 static const char* const kSwitchNames[] = {
[email protected]c8d02992013-07-31 22:16:511482 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271483 extensions::switches::kExtensionsOnChromeURLs,
[email protected]eb653f82012-05-24 02:31:351484 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381485 switches::kWhitelistedExtensionID,
1486 };
1487
1488 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1489 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511490 } else if (process_type == switches::kPluginProcess) {
1491 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441492#if defined(OS_CHROMEOS)
1493 chromeos::switches::kLoginProfile,
1494#endif
[email protected]4287a3d2011-06-13 23:56:511495 switches::kMemoryProfiling,
1496 switches::kSilentDumpOnDCHECK,
1497 switches::kUserDataDir,
1498 };
1499
1500 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1501 arraysize(kSwitchNames));
1502 } else if (process_type == switches::kZygoteProcess) {
1503 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511504 switches::kUserDataDir, // Make logs go to the right file.
1505 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501506 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511507 switches::kPpapiFlashInProcess,
1508 switches::kPpapiFlashPath,
1509 switches::kPpapiFlashVersion,
1510 };
1511
1512 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1513 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111514 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001515 base::FilePath user_data_dir =
1516 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1517 if (!user_data_dir.empty())
1518 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111519 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1520 // because GPU is expected to be unreliable.
1521 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1522 !command_line->HasSwitch(switches::kDisableBreakpad))
1523 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301524 }
[email protected]6f08af82011-09-15 01:19:031525
1526 // The command line switch kEnableBenchmarking needs to be specified along
1527 // with the kEnableStatsTable switch to ensure that the stats table global
1528 // is initialized correctly.
1529 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1530 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301531}
1532
1533std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431534 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351535 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301536 return g_browser_process->GetApplicationLocale();
1537}
1538
[email protected]597a867b2011-11-18 18:31:201539std::string ChromeContentBrowserClient::GetAcceptLangs(
1540 content::BrowserContext* context) {
1541 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371542 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081543}
1544
[email protected]9ec0f452012-05-31 15:58:531545gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221546 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531547 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081548}
1549
[email protected]a2176792011-05-08 19:30:491550bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091551 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191552 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201553 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201555 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051556 return io_data->GetCookieSettings()->
1557 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491558}
1559
[email protected]ed24fad2011-05-10 22:44:011560bool ChromeContentBrowserClient::AllowGetCookie(
1561 const GURL& url,
1562 const GURL& first_party,
1563 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201564 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011565 int render_process_id,
1566 int render_view_id) {
1567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201568 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051569 bool allow = io_data->GetCookieSettings()->
1570 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011571
[email protected]8093a542011-05-13 07:29:321572 BrowserThread::PostTask(
1573 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031574 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431575 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011576 return allow;
1577}
1578
1579bool ChromeContentBrowserClient::AllowSetCookie(
1580 const GURL& url,
1581 const GURL& first_party,
1582 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201583 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011584 int render_process_id,
1585 int render_view_id,
1586 net::CookieOptions* options) {
1587 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201588 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051589 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1590 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1591
[email protected]8093a542011-05-13 07:29:321592 BrowserThread::PostTask(
1593 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031594 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431595 render_view_id, url, first_party, cookie_line, *options,
1596 !allow));
[email protected]ed24fad2011-05-10 22:44:011597 return allow;
1598}
1599
[email protected]d5a19162011-06-30 18:51:541600bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201601 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541602 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201603 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431604 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1605 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261606
[email protected]bf510ed2012-06-05 08:31:431607 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1608 // Could we even support per-origin settings?
1609 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541610}
1611
[email protected]5c5a88e2011-11-12 00:45:351612bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351613 const GURL& url,
1614 const string16& name,
1615 const string16& display_name,
1616 unsigned long estimated_size,
[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 database 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::WebDatabaseAccessed,
1630 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351631 }
1632
1633 return allow;
1634}
1635
1636bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351637 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201638 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481639 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201641 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351642 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1643 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1644
[email protected]62151052012-02-01 18:40:481645 // Record access to file system for potential display in UI.
1646 std::vector<std::pair<int, int> >::const_iterator i;
1647 for (i = render_views.begin(); i != render_views.end(); ++i) {
1648 BrowserThread::PostTask(
1649 BrowserThread::UI, FROM_HERE,
1650 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1651 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351652 }
1653
1654 return allow;
1655}
1656
[email protected]7c5ff9a2012-03-02 07:42:491657bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1658 const GURL& url,
1659 const string16& name,
1660 content::ResourceContext* context,
1661 const std::vector<std::pair<int, int> >& render_views) {
1662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1663 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1664 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1665 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1666
1667 // Record access to IndexedDB for potential display in UI.
1668 std::vector<std::pair<int, int> >::const_iterator i;
1669 for (i = render_views.begin(); i != render_views.end(); ++i) {
1670 BrowserThread::PostTask(
1671 BrowserThread::UI, FROM_HERE,
1672 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1673 i->first, i->second, url, name, !allow));
1674 }
1675
1676 return allow;
1677}
1678
[email protected]6133f922011-07-01 21:34:341679net::URLRequestContext*
1680ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201681 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341682 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421683 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201684 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341685 return io_data->extensions_request_context();
1686 }
1687
1688 return NULL;
1689}
1690
[email protected]317f96c92011-05-31 06:53:411691QuotaPermissionContext*
1692ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1693 return new ChromeQuotaPermissionContext();
1694}
1695
[email protected]848dd042011-06-04 18:24:031696void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171697 int render_process_id,
1698 int render_view_id,
1699 int cert_error,
1700 const net::SSLInfo& ssl_info,
1701 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021702 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031703 bool overridable,
[email protected]d9be47702012-05-16 03:41:221704 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171705 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001706 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021707 if (resource_type != ResourceType::MAIN_FRAME) {
1708 // A sub-resource has a certificate error. The user doesn't really
1709 // have a context for making the right decision, so block the
1710 // request hard, without an info bar to allow showing the insecure
1711 // content.
[email protected]8c965c22013-05-23 19:28:001712 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021713 return;
1714 }
1715
[email protected]f9034cf2011-07-21 12:43:411716 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131717 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171718 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411719 if (!tab) {
1720 NOTREACHED();
1721 return;
1722 }
1723 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501724 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301725 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011726 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1727 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411728 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171729 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411730 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001731 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411732 return;
1733 }
1734 }
1735
[email protected]1e87df32012-09-12 04:53:191736#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231737 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1738 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1739 if (captive_portal_tab_helper)
1740 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191741#endif
1742
[email protected]f9034cf2011-07-21 12:43:411743 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221744 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1745 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031746}
1747
[email protected]c99c442e2011-08-24 11:37:301748void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451749 int render_process_id,
1750 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401751 const net::HttpNetworkSession* network_session,
1752 net::SSLCertRequestInfo* cert_request_info,
1753 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131754 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451755 render_process_id, render_view_id);
1756 if (!tab) {
1757 NOTREACHED();
1758 return;
1759 }
1760
[email protected]6786bf402011-12-03 15:19:451761 GURL requesting_url("https://" + cert_request_info->host_and_port);
1762 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1763 << cert_request_info->host_and_port;
1764
[email protected]627e0512011-12-21 22:55:301765 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451766 scoped_ptr<Value> filter(
1767 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1768 requesting_url,
1769 requesting_url,
1770 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1771 std::string(), NULL));
1772
1773 if (filter.get()) {
1774 // Try to automatically select a client certificate.
1775 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1776 DictionaryValue* filter_dict =
1777 static_cast<DictionaryValue*>(filter.get());
1778
1779 const std::vector<scoped_refptr<net::X509Certificate> >&
1780 all_client_certs = cert_request_info->client_certs;
1781 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091782 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451783 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091784 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451785 return;
1786 }
1787 }
1788 } else {
1789 NOTREACHED();
1790 }
1791 }
1792
[email protected]11feec322012-09-18 03:58:521793 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1794 if (!ssl_tab_helper) {
1795 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451796 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141797 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401798 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451799 return;
1800 }
[email protected]11feec322012-09-18 03:58:521801 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401802 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451803}
1804
[email protected]3b455502012-12-11 18:22:581805void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451806 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581807 net::CertificateMimeType cert_type,
1808 const void* cert_data,
1809 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451810 int render_process_id,
1811 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581812 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1813 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451814}
1815
[email protected]dc73a7b2012-03-25 15:27:181816content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561817 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181818}
1819
[email protected]941623e2011-06-07 23:06:041820void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1821 const GURL& source_origin,
1822 int callback_context,
1823 int render_process_id,
1824 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111825#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021826 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1827 WebContents* contents =
1828 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1829 if (!contents) {
[email protected]941623e2011-06-07 23:06:041830 NOTREACHED();
1831 return;
1832 }
1833
[email protected]d0d9c3ee2012-06-19 03:07:021834 // Skip showing the infobar if the request comes from an extension, and that
1835 // extension has the 'notify' permission. (If the extension does not have the
1836 // permission, the user will still be prompted.)
1837 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011838 ExtensionInfoMap* extension_info_map =
1839 extensions::ExtensionSystem::Get(profile)->info_map();
1840 DesktopNotificationService* notification_service =
1841 DesktopNotificationServiceFactory::GetForProfile(profile);
1842 const Extension* extension = NULL;
1843 if (extension_info_map) {
1844 ExtensionSet extensions;
1845 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1846 source_origin, render_process_id,
1847 extensions::APIPermission::kNotification, &extensions);
1848 for (ExtensionSet::const_iterator iter = extensions.begin();
1849 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381850 if (notification_service->IsNotifierEnabled(NotifierId(
1851 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361852 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011853 break;
1854 }
1855 }
1856 }
[email protected]eb4832a2012-12-08 01:57:521857 RenderViewHost* rvh =
1858 RenderViewHost::FromID(render_process_id, render_view_id);
1859 if (IsExtensionWithPermissionOrSuggestInConsole(
1860 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021861 if (rvh)
1862 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1863 return;
1864 }
1865
[email protected]c7cd5942013-04-30 03:31:011866 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021867 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111868#else
1869 NOTIMPLEMENTED();
1870#endif
[email protected]941623e2011-06-07 23:06:041871}
1872
1873WebKit::WebNotificationPresenter::Permission
1874 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021875 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201876 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021877 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111878#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041879 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481880 // Sometimes a notification may be invoked during the shutdown.
1881 // See http://crbug.com/256638
1882 if (browser_shutdown::IsTryingToQuit())
1883 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
1884
[email protected]df02aca2012-02-09 21:03:201885 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041886
[email protected]c7cd5942013-04-30 03:31:011887 DesktopNotificationService* notification_service =
1888 io_data->GetNotificationService();
1889 if (notification_service) {
1890 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1891 ExtensionSet extensions;
1892 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1893 source_origin, render_process_id,
1894 extensions::APIPermission::kNotification, &extensions);
1895 for (ExtensionSet::const_iterator iter = extensions.begin();
1896 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381897 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
1898 if (notification_service->IsNotifierEnabled(notifier_id))
[email protected]c7cd5942013-04-30 03:31:011899 return WebKit::WebNotificationPresenter::PermissionAllowed;
1900 }
1901
1902 return notification_service->HasPermission(source_origin);
1903 }
1904
1905 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111906#else
1907 return WebKit::WebNotificationPresenter::PermissionAllowed;
1908#endif
[email protected]941623e2011-06-07 23:06:041909}
1910
1911void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171912 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041913 int render_process_id,
1914 int render_view_id,
1915 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111916#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041917 RenderViewHost* rvh = RenderViewHost::FromID(
1918 render_process_id, render_view_id);
1919 if (!rvh) {
1920 NOTREACHED();
1921 return;
1922 }
1923
[email protected]9f76c1e2012-03-05 15:15:581924 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301925 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041926 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371927 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041928 service->ShowDesktopNotification(
1929 params, render_process_id, render_view_id,
1930 worker ? DesktopNotificationService::WorkerNotification :
1931 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111932#else
1933 NOTIMPLEMENTED();
1934#endif
[email protected]941623e2011-06-07 23:06:041935}
1936
1937void ChromeContentBrowserClient::CancelDesktopNotification(
1938 int render_process_id,
1939 int render_view_id,
1940 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111941#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041942 RenderViewHost* rvh = RenderViewHost::FromID(
1943 render_process_id, render_view_id);
1944 if (!rvh) {
1945 NOTREACHED();
1946 return;
1947 }
1948
[email protected]9f76c1e2012-03-05 15:15:581949 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301950 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041951 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371952 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041953 service->CancelDesktopNotification(
1954 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111955#else
1956 NOTIMPLEMENTED();
1957#endif
[email protected]941623e2011-06-07 23:06:041958}
1959
[email protected]9f3fba52011-06-08 20:37:191960bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351961 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021962 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191963 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:231964 const GURL& target_url,
1965 const content::Referrer& referrer,
1966 WindowOpenDisposition disposition,
1967 const WebWindowFeatures& features,
1968 bool user_gesture,
1969 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:201970 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011971 int render_process_id,
[email protected]190e5e22013-07-27 05:59:231972 bool is_guest,
1973 int opener_id,
[email protected]03b6d552012-03-29 04:03:011974 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191975 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011976
1977 *no_javascript_access = false;
1978
[email protected]9f3fba52011-06-08 20:37:191979 // If the opener is trying to create a background window but doesn't have
1980 // the appropriate permission, fail the attempt.
1981 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201982 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531983 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1984
[email protected]03b6d552012-03-29 04:03:011985 if (!map->SecurityOriginHasAPIPermission(
1986 source_origin,
1987 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061988 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011989 return false;
1990 }
1991
[email protected]7b54ca02012-03-02 18:06:531992 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1993 // return a recently installed Extension even if this CanCreateWindow call
1994 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011995 // because the permission check above would have caused an early return
1996 // already. We must use the full URL to find hosted apps, though, and not
1997 // just the origin.
[email protected]be9915fb2013-07-18 09:28:551998 const Extension* extension =
1999 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292000 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012001 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:232002
2003 return true;
[email protected]9f3fba52011-06-08 20:37:192004 }
[email protected]056efdc2013-04-06 00:14:532005
2006 // No new browser window (popup or tab) in app mode.
2007 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
2008 chrome::IsRunningInForcedAppMode()) {
2009 return false;
2010 }
2011
[email protected]190e5e22013-07-27 05:59:232012#if !defined(OS_ANDROID)
2013 if (CommandLine::ForCurrentProcess()->HasSwitch(
2014 switches::kDisableBetterPopupBlocking)) {
2015 return true;
2016 }
2017
2018 if (is_guest)
2019 return true;
2020
[email protected]190e5e22013-07-27 05:59:232021 HostContentSettingsMap* content_settings =
2022 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
2023
2024 if ((disposition == NEW_POPUP || disposition == NEW_FOREGROUND_TAB ||
2025 disposition == NEW_BACKGROUND_TAB) && !user_gesture &&
2026 !CommandLine::ForCurrentProcess()->HasSwitch(
2027 switches::kDisablePopupBlocking)) {
2028 if (content_settings->GetContentSetting(opener_url,
2029 opener_url,
2030 CONTENT_SETTINGS_TYPE_POPUPS,
2031 std::string()) ==
2032 CONTENT_SETTING_ALLOW) {
2033 return true;
2034 }
2035
2036 BrowserThread::PostTask(BrowserThread::UI,
2037 FROM_HERE,
2038 base::Bind(&HandleBlockedPopupOnUIThread,
2039 BlockedPopupParams(target_url,
2040 referrer,
2041 disposition,
2042 features,
2043 user_gesture,
2044 opener_suppressed,
2045 render_process_id,
2046 opener_id)));
2047 return false;
2048 }
2049#endif
2050
[email protected]9f3fba52011-06-08 20:37:192051 return true;
2052}
2053
2054std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202055 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192056 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2057 // Check if it's an extension-created worker, in which case we want to use
2058 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202059 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192060 const Extension* extension =
2061 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2062 return extension ? extension->name() : std::string();
2063}
2064
[email protected]99907362012-01-11 05:41:402065void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2066 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172067}
2068
[email protected]7a06d282013-05-03 04:39:332069// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022070content::SpeechRecognitionManagerDelegate*
2071 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002072#if defined(ENABLE_INPUT_SPEECH)
2073 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322074#else
[email protected]855e18b2013-07-08 21:02:002075 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2076 // need the base delegate without the bubble UI.
2077 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322078#endif
[email protected]66cfec62012-02-24 17:57:512079}
2080
[email protected]ae6e9912011-07-27 01:18:282081net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2082 return g_browser_process->net_log();
2083}
2084
[email protected]32538d92011-08-25 00:09:232085AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2086 return new ChromeAccessTokenStore();
2087}
2088
[email protected]dbae6b02011-06-29 23:51:412089bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012090 return true;
[email protected]dbae6b02011-06-29 23:51:412091}
2092
[email protected]64d69de42012-02-06 00:19:542093void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322094 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062095 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582096 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062097 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062098
[email protected]f3986f82012-01-03 20:00:062099 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542100 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062101 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542102 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062103 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542104 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062105 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542106 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062107 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542108 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062109 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542110 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032111 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2112 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:062113
[email protected]64d69de42012-02-06 00:19:542114 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402115 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542116 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402117 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542118 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402119 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542120 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402121 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062122
[email protected]ddf72142012-05-22 04:52:402123 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062124
[email protected]64d69de42012-02-06 00:19:542125 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402126 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542127 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062128 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542129 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062130 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2131 const DictionaryValue* inspector_settings =
2132 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2133 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182134 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2135 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062136 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182137 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542138 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182139 std::make_pair(iter.key(), value));
2140 }
[email protected]f3986f82012-01-03 20:00:062141 }
2142 }
[email protected]64d69de42012-02-06 00:19:542143 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062144
[email protected]ddf72142012-05-22 04:52:402145 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542146 web_prefs->javascript_enabled = false;
2147 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2148 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402149 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542150 web_prefs->plugins_enabled = false;
2151 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2152 web_prefs->java_enabled = false;
2153 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402154 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062155
[email protected]64d69de42012-02-06 00:19:542156 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2157 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062158
[email protected]64d69de42012-02-06 00:19:542159 web_prefs->memory_info_enabled =
2160 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2161 web_prefs->allow_displaying_insecure_content =
2162 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2163 web_prefs->allow_running_insecure_content =
2164 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322165#if defined(OS_ANDROID)
2166 web_prefs->font_scale_factor =
2167 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2168 web_prefs->force_enable_zoom =
2169 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2170#endif
[email protected]5c915252013-05-07 13:15:392171
[email protected]af4256d52013-06-04 20:39:072172#if defined(OS_ANDROID)
2173 web_prefs->password_echo_enabled =
2174 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2175#else
[email protected]9d06d88d2012-02-23 22:37:082176 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072177#endif
2178
[email protected]5c915252013-05-07 13:15:392179#if defined(OS_CHROMEOS)
2180 // Enable password echo during OOBE when keyboard driven flag is set.
2181 if (chromeos::UserManager::IsInitialized() &&
2182 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
[email protected]c94ac692013-07-27 00:50:102183 !chromeos::StartupUtils::IsOobeCompleted() &&
2184 chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation()) {
2185 web_prefs->password_echo_enabled = true;
[email protected]5c915252013-05-07 13:15:392186 }
2187#endif
[email protected]f3986f82012-01-03 20:00:062188
[email protected]46f8e742013-05-03 18:37:142189#if defined(OS_ANDROID)
2190 web_prefs->user_style_sheet_enabled = false;
2191#else
[email protected]64d69de42012-02-06 00:19:542192 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152193 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362194 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152195 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542196 web_prefs->user_style_sheet_enabled = true;
2197 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152198 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542199 } else {
2200 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062201 }
[email protected]46f8e742013-05-03 18:37:142202#endif
[email protected]f3986f82012-01-03 20:00:062203
[email protected]cfadadd2013-04-03 04:43:022204 web_prefs->asynchronous_spell_checking_enabled = true;
2205 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572206
[email protected]64d69de42012-02-06 00:19:542207 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062208 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542209 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062210 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542211 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062212 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2213
2214 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542215 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062216 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542217 web_prefs->default_encoding);
2218 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402219 prefs->ClearPref(prefs::kDefaultCharset);
2220 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062221 }
[email protected]64d69de42012-02-06 00:19:542222 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062223
[email protected]88ecf66d2012-12-11 22:53:472224 if (content::IsForceCompositingModeEnabled())
2225 web_prefs->force_compositing_mode = true;
2226
[email protected]299d7f12012-05-23 05:31:152227 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232228 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132229 ExtensionService* service =
2230 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062231 if (service) {
[email protected]1bc28312012-11-08 08:31:532232 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2233 const Extension* extension = service->extensions()->GetByID(url.host());
2234 // Ensure that we are only granting extension preferences to URLs with
2235 // the correct scheme. Without this check, chrome-guest:// schemes used by
2236 // webview tags as well as hosts that happen to match the id of an
2237 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422238 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532239 extension_webkit_preferences::SetPreferences(
2240 extension, view_type, web_prefs);
2241 }
[email protected]f3986f82012-01-03 20:00:062242 }
2243
[email protected]cb2edf22013-04-01 20:25:232244 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542245 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232246 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062247 // Disable all kinds of acceleration for background pages.
2248 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542249 web_prefs->force_compositing_mode = false;
2250 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062251 }
[email protected]2e21fe292012-03-02 22:52:322252
2253#if defined(FILE_MANAGER_EXTENSION)
2254 // Override the default of suppressing HW compositing for WebUI pages for the
2255 // file manager, which is implemented using WebUI but wants HW acceleration
2256 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532257 if (url.SchemeIs(extensions::kExtensionScheme) &&
2258 url.host() == kFileBrowserDomain) {
[email protected]2e21fe292012-03-02 22:52:322259 web_prefs->accelerated_compositing_enabled = true;
2260 web_prefs->accelerated_2d_canvas_enabled = true;
2261 }
2262#endif
[email protected]181a95ee2011-07-12 19:26:362263}
2264
2265void ChromeContentBrowserClient::UpdateInspectorSetting(
2266 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062267 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582268 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062269 DictionaryPrefUpdate update(
2270 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2271 prefs::kWebKitInspectorSettings);
2272 DictionaryValue* inspector_settings = update.Get();
2273 inspector_settings->SetWithoutPathExpansion(key,
2274 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362275}
2276
[email protected]b8148ac2011-07-13 22:03:252277void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2278 BrowserURLHandler* handler) {
2279 // Add the default URL handlers.
2280 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2281 BrowserURLHandler::null_handler());
2282 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2283 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2284
[email protected]b3adbd02011-11-30 22:23:272285 // about: handler. Must come before chrome: handler, since it will
2286 // rewrite about: urls to chrome: URLs and then expect chrome: to
2287 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252288 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2289 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032290
2291 // Handler to rewrite chrome://newtab for InstantExtended.
2292 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2293 &chrome::HandleNewTabURLReverseRewrite);
2294
[email protected]b8148ac2011-07-13 22:03:252295 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242296 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252297}
2298
2299void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372300 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582301 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472302 BrowsingDataRemover* remover =
2303 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552304 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2305 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252306 // BrowsingDataRemover takes care of deleting itself when done.
2307}
2308
2309void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372310 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582311 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472312 BrowsingDataRemover* remover =
2313 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232314 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552315 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252316 // BrowsingDataRemover takes care of deleting itself when done.
2317}
2318
[email protected]650b2d52013-02-10 03:41:452319base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322320 return download_util::GetDefaultDownloadDirectory();
2321}
2322
[email protected]c9b6eb62011-10-18 20:49:392323std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2324 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2325}
2326
[email protected]b7631cc2012-09-15 05:08:382327void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2328 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542329#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382330 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2331 scoped_ptr<ppapi::host::HostFactory>(
2332 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542333#endif
[email protected]b7631cc2012-09-15 05:08:382334}
2335
[email protected]0c7193742012-11-07 19:05:032336content::BrowserPpapiHost*
2337 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2338 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132339 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032340 while (!iter.Done()) {
2341 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2342 if (host->process() &&
2343 host->process()->GetData().id == plugin_process_id) {
2344 // Found the plugin.
2345 return host->browser_ppapi_host();
2346 }
2347 ++iter;
2348 }
2349 return NULL;
2350}
2351
[email protected]7b38b192013-03-23 18:39:312352bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2353 content::BrowserContext* browser_context, const GURL& site_url) {
2354 if (CommandLine::ForCurrentProcess()->HasSwitch(
2355 switches::kEnableBrowserPluginForAllViewTypes))
2356 return true;
2357
2358 Profile* profile = Profile::FromBrowserContext(browser_context);
2359 ExtensionService* service =
2360 extensions::ExtensionSystem::Get(profile)->extension_service();
2361 if (!service)
2362 return false;
2363
[email protected]be9915fb2013-07-18 09:28:552364 const Extension* extension =
2365 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312366 if (!extension)
2367 return false;
2368
[email protected]c2d2f102013-04-29 16:42:582369 return extension->HasAPIPermission(APIPermission::kWebView) ||
2370 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312371}
2372
[email protected]38cd8f7f2012-06-15 22:06:072373bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582374 content::BrowserContext* browser_context,
2375 const GURL& url,
[email protected]dda54822013-06-15 01:26:392376 bool private_api,
[email protected]157cc902012-11-02 06:31:582377 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402378#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372379 Profile* profile = Profile::FromBrowserContext(browser_context);
2380 const ExtensionSet* extension_set = NULL;
2381 if (profile) {
2382 extension_set = extensions::ExtensionSystem::Get(profile)->
2383 extension_service()->extensions();
2384 }
[email protected]dda54822013-06-15 01:26:392385
2386 if (private_api) {
2387 // Access to private socket APIs is controlled by the whitelist.
2388 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2389 allowed_socket_origins_)) {
2390 return true;
2391 }
2392 } else {
2393 // Access to public socket APIs is controlled by extension permissions.
2394 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2395 extension_set) {
2396 const Extension* extension = extension_set->GetByID(url.host());
2397 if (extension) {
2398 extensions::SocketPermission::CheckParam check_params(
2399 params.type, params.host, params.port);
2400 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2401 extension, extensions::APIPermission::kSocket, &check_params)) {
2402 return true;
2403 }
2404 }
2405 }
2406 }
2407
2408 // Allow both public and private APIs if the command line says so.
2409 return IsHostAllowedByCommandLine(url, extension_set,
2410 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402411#else
[email protected]a658d452012-03-02 12:45:292412 return false;
[email protected]93f72062013-05-29 20:29:402413#endif
[email protected]e461da2f2012-02-16 19:06:402414}
2415
[email protected]650b2d52013-02-10 03:41:452416base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2417 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142418 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2419 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2420}
2421
[email protected]a28e3302013-02-03 03:50:432422ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2423 WebContents* web_contents) {
2424 return new ChromeSelectFilePolicy(web_contents);
2425}
2426
[email protected]7d9424702013-04-14 13:14:162427void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2428 std::vector<std::string>* additional_allowed_schemes) {
2429 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2430 additional_allowed_schemes);
2431 additional_allowed_schemes->push_back(kChromeUIScheme);
2432 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2433}
2434
[email protected]f19bbf62013-07-09 01:22:322435void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312436 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532437 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322438 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532439#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032440 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322441 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032442 storage_partition_path,
2443 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322444 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532445#endif
[email protected]b40015c2013-06-26 08:13:312446#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312447 fileapi::ExternalMountPoints* external_mount_points =
2448 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312449 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322450 chromeos::FileSystemBackend* backend =
2451 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312452 new drive::FileSystemBackendDelegate(browser_context),
2453 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312454 external_mount_points,
2455 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322456 backend->AddSystemMountPoints();
2457 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2458 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312459#endif
[email protected]445b7db2013-08-02 04:58:272460
2461 additional_backends->push_back(new sync_file_system::SyncFileSystemBackend());
[email protected]02250952013-04-24 23:52:532462}
2463
[email protected]e60c0232011-11-11 19:56:352464#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182465void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2466 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382467 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082468 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392469#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452470 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392471 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2472 DCHECK(!data_path.empty());
2473
2474 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452475 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392476 base::PlatformFile f =
2477 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2478 DCHECK(f != base::kInvalidPlatformFileValue);
2479 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2480 FileDescriptor(f, true)));
2481
[email protected]650b2d52013-02-10 03:41:452482 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392483 data_path.AppendASCII("chrome_100_percent.pak");
2484 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2485 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372486 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392487 FileDescriptor(f, true)));
2488
2489 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452490 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392491 GetLocaleFilePath(locale, false);
2492 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2493 DCHECK(f != base::kInvalidPlatformFileValue);
2494 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2495 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382496
[email protected]650b2d52013-02-10 03:41:452497 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372498 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2499 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2500 DCHECK(f != base::kInvalidPlatformFileValue);
2501 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2502 FileDescriptor(f, true)));
2503
[email protected]82174aa2013-01-22 21:53:432504 if (IsCrashReporterEnabled()) {
2505 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2506 if (f == base::kInvalidPlatformFileValue) {
2507 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2508 "be disabled for this process.";
2509 } else {
2510 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2511 FileDescriptor(f, true)));
2512 }
[email protected]40da3e0c2012-10-24 22:03:382513 }
[email protected]40da3e0c2012-10-24 22:03:382514
2515#else
2516 int crash_signal_fd = GetCrashSignalFD(command_line);
2517 if (crash_signal_fd >= 0) {
2518 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2519 FileDescriptor(crash_signal_fd,
2520 false)));
2521 }
[email protected]29699c22012-10-03 23:57:392522#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302523}
[email protected]e60c0232011-11-11 19:56:352524#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302525
[email protected]4a65826d2011-08-25 16:04:012526#if defined(OS_WIN)
2527const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2528 return chrome::kBrowserResourcesDll;
2529}
[email protected]34f48682013-03-20 00:30:182530
2531void ChromeContentBrowserClient::PreSpawnRenderer(
2532 sandbox::TargetPolicy* policy,
2533 bool* success) {
2534 // This code is duplicated in nacl_exe_win_64.cc.
2535 // Allow the server side of a pipe restricted to the "chrome.nacl."
2536 // namespace so that it cannot impersonate other system or other chrome
2537 // service pipes.
2538 sandbox::ResultCode result = policy->AddRule(
2539 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2540 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2541 L"\\\\.\\pipe\\chrome.nacl.*");
2542 if (result != sandbox::SBOX_ALL_OK) {
2543 *success = false;
2544 return;
2545 }
2546
2547 // Renderers need to send named pipe handles and shared memory
2548 // segment handles to NaCl loader processes.
2549 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2550 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2551 L"File");
2552 if (result != sandbox::SBOX_ALL_OK) {
2553 *success = false;
2554 return;
2555 }
2556}
[email protected]4a65826d2011-08-25 16:04:012557#endif
2558
[email protected]37a72af2011-06-13 05:42:012559#if defined(USE_NSS)
2560crypto::CryptoModuleBlockingPasswordDelegate*
2561 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2562 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292563 return chrome::NewCryptoModuleBlockingDialogDelegate(
2564 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012565}
2566#endif
2567
[email protected]d977f9c2011-03-14 16:10:262568} // namespace chrome