blob: 993babdb10652b0dbdf87a6a792532bf25c103ec [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]fab55e72013-05-31 07:06:18141#include "webkit/common/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04142#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26143
[email protected]b48c9182011-10-26 18:03:30144#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38145#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18146#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38147#elif defined(OS_MACOSX)
148#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56149#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30150#elif defined(OS_CHROMEOS)
151#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]f19bbf62013-07-09 01:22:32152#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h"
153#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39154#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49155#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10156#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44157#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26158#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30159#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09160#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38161#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09162#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39163#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30164#elif defined(OS_POSIX)
165#include "chrome/browser/chrome_browser_main_posix.h"
166#endif
167
[email protected]6653c192012-04-10 22:52:44168#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30169#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12170#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43171#endif
[email protected]b80f68432011-05-02 17:22:30172
[email protected]190e5e22013-07-27 05:59:23173#if !defined(OS_ANDROID)
174#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
175#endif
176
[email protected]1e87df32012-09-12 04:53:19177#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
178#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
179#endif
180
[email protected]29699c22012-10-03 23:57:39181#if defined(OS_ANDROID)
182#include "ui/base/ui_base_paths.h"
183#endif
184
[email protected]37a72af2011-06-13 05:42:01185#if defined(USE_NSS)
186#include "chrome/browser/ui/crypto_module_password_dialog.h"
187#endif
188
[email protected]d5bcd06f2013-04-21 08:07:24189#if !defined(OS_CHROMEOS)
190#include "chrome/browser/signin/signin_manager.h"
191#include "chrome/browser/signin/signin_manager_factory.h"
192#endif
193
[email protected]02250952013-04-24 23:52:53194#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32195#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53196#endif
197
[email protected]6ef98b5a2013-05-31 23:58:31198#if defined(ENABLE_WEBRTC)
199#include "chrome/browser/media/webrtc_logging_handler_host.h"
200#endif
201
[email protected]855e18b2013-07-08 21:02:00202#if defined(ENABLE_INPUT_SPEECH)
203#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
204#endif
205
[email protected]02a3dc122013-06-13 15:07:53206#if defined(FILE_MANAGER_EXTENSION)
207#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
208#endif
209
[email protected]e8b6ca02013-07-10 18:00:51210#if defined(TOOLKIT_GTK)
211#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
212#endif
213
214#if defined(TOOLKIT_VIEWS)
215#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
216#endif
217
218#if defined(USE_ASH)
219#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
220#endif
221
222#if defined(USE_AURA)
223#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
224#endif
225
226#if defined(USE_X11)
227#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
228#endif
229
[email protected]c6ce08072013-07-31 07:48:53230#if defined(ENABLE_SPELLCHECK)
231#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
232#endif
233
[email protected]190e5e22013-07-27 05:59:23234using WebKit::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08235using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47236using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03237using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39238using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31239using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59240using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08241using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00242using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11243using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33244using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13245using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06246using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34247using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40248using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38249using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39250
[email protected]c5dbef02011-05-13 05:06:09251namespace {
252
[email protected]eabbfb12013-04-05 23:28:35253// Cached version of the locale so we can return the locale on the I/O
254// thread.
255base::LazyInstance<std::string> g_io_thread_application_locale;
256
[email protected]93f72062013-05-29 20:29:40257#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40258const char* kPredefinedAllowedSocketOrigins[] = {
259 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18260 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45261 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
262 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
263 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
264 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35265 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54266 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
267 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
268 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
269 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
270 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
271 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38272 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58273 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29274 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]f6599915a2013-06-20 20:03:50275 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
[email protected]b71313232013-05-06 06:16:29276 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
277 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
278 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
279 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40280};
[email protected]93f72062013-05-29 20:29:40281#endif
[email protected]e461da2f2012-02-16 19:06:40282
[email protected]f8f93eb2012-09-25 03:06:24283// Returns a copy of the given url with its host set to given host and path set
284// to given path. Other parts of the url will be the same.
285GURL ReplaceURLHostAndPath(const GURL& url,
286 const std::string& host,
287 const std::string& path) {
288 url_canon::Replacements<char> replacements;
289 replacements.SetHost(host.c_str(),
290 url_parse::Component(0, host.length()));
291 replacements.SetPath(path.c_str(),
292 url_parse::Component(0, path.length()));
293 return url.ReplaceComponents(replacements);
294}
295
296// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
297GURL AddUberHost(const GURL& url) {
298 const std::string uber_host = chrome::kChromeUIUberHost;
299 const std::string new_path = url.host() + url.path();
300
301 return ReplaceURLHostAndPath(url, uber_host, new_path);
302}
303
[email protected]045bf7c2012-09-28 20:27:36304// If url->host() is "chrome" and url->path() has characters other than the
305// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
306// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24307bool RemoveUberHost(GURL* url) {
308 if (url->host() != chrome::kChromeUIUberHost)
309 return false;
310
[email protected]045bf7c2012-09-28 20:27:36311 if (url->path().empty() || url->path() == "/")
312 return false;
313
[email protected]f8f93eb2012-09-25 03:06:24314 const std::string old_path = url->path();
315
316 const std::string::size_type separator = old_path.find('/', 1);
317 std::string new_host;
318 std::string new_path;
319 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36320 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24321 } else {
322 new_host = old_path.substr(1, separator - 1);
323 new_path = old_path.substr(separator);
324 }
325
[email protected]44e8add2013-06-13 17:29:15326 // Do not allow URLs with paths empty before the first slash since we can't
327 // have an empty host. (e.g "foo://chrome//")
328 if (new_host.empty())
329 return false;
330
[email protected]f8f93eb2012-09-25 03:06:24331 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
332
[email protected]44e8add2013-06-13 17:29:15333 DCHECK(url->is_valid());
334
[email protected]f8f93eb2012-09-25 03:06:24335 return true;
336}
337
[email protected]b8148ac2011-07-13 22:03:25338// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42339bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24340 // Do not handle special URLs such as "about:foo"
341 if (!url->host().empty()) {
342 const GURL chrome_url = AddUberHost(*url);
343
344 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
345 // be called.
346 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
347 browser_context, chrome_url))
348 return true;
349 }
350
[email protected]863f70a2012-01-27 02:05:50351 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
352 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25353 return false;
354
[email protected]fe69558d2012-03-12 11:34:49355#if defined(OS_CHROMEOS)
356 // Special case : in ChromeOS in Guest mode bookmarks and history are
357 // disabled for security reasons. New tab page explains the reasons, so
358 // we redirect user to new tab page.
359 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
360 if (url->SchemeIs(chrome::kChromeUIScheme) &&
361 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
362 url->DomainIs(chrome::kChromeUIHistoryHost))) {
363 // Rewrite with new tab URL
364 *url = GURL(chrome::kChromeUINewTabURL);
365 }
366 }
367#endif
368
[email protected]b8148ac2011-07-13 22:03:25369 // Special case the new tab page. In older versions of Chrome, the new tab
370 // page was hosted at chrome-internal:<blah>. This might be in people's saved
371 // sessions or bookmarks, so we say any URL with that scheme triggers the new
372 // tab page.
373 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
374 // Rewrite it with the proper new tab URL.
375 *url = GURL(chrome::kChromeUINewTabURL);
376 }
377
378 return true;
379}
380
[email protected]f8f93eb2012-09-25 03:06:24381// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
382// "chrome://foo/".
383bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
384 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
385 return false;
386
387 return RemoveUberHost(url);
388}
389
[email protected]8d3132f62011-10-12 07:13:42390// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
391// below. Extension, and isolated apps require different privileges to be
392// granted to their RenderProcessHosts. This classification allows us to make
393// sure URLs are served by hosts with the right set of privileges.
394enum RenderProcessHostPrivilege {
395 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45396 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42397 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45398 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42399};
400
401RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
402 const GURL& url,
403 ExtensionService* service) {
404 // Default to a normal renderer cause it is lower privileged. This should only
405 // occur if the URL on a site instance is either malformed, or uninitialized.
406 // If it is malformed, then there is no need for better privileges anyways.
407 // If it is uninitialized, but eventually settles on being an a scheme other
408 // than normal webrenderer, the navigation logic will correct us out of band
409 // anyways.
410 if (!url.is_valid())
411 return PRIV_NORMAL;
412
[email protected]885c0e92012-11-13 20:27:42413 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44414 const Extension* extension =
415 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43416 if (extension &&
417 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42418 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45419 if (extension && extension->is_hosted_app())
420 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42421
422 return PRIV_EXTENSION;
423 }
424
425 return PRIV_NORMAL;
426}
427
428RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30429 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46430 extensions::ProcessMap* process_map,
431 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46432 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30433 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46434 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21435 return PRIV_NORMAL;
436
[email protected]6f371442011-11-09 06:45:46437 for (std::set<std::string>::iterator iter = extension_ids.begin();
438 iter != extension_ids.end(); ++iter) {
439 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43440 if (extension &&
441 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42442 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45443 if (extension && extension->is_hosted_app())
444 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42445 }
446
[email protected]676f6ab2011-10-19 20:23:21447 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42448}
449
[email protected]6786bf402011-12-03 15:19:45450bool CertMatchesFilter(const net::X509Certificate& cert,
451 const base::DictionaryValue& filter) {
452 // TODO(markusheintz): This is the minimal required filter implementation.
453 // Implement a better matcher.
454
455 // An empty filter matches any client certificate since no requirements are
456 // specified at all.
457 if (filter.empty())
458 return true;
459
460 std::string common_name;
461 if (filter.GetString("ISSUER.CN", &common_name) &&
462 (cert.issuer().common_name == common_name)) {
463 return true;
464 }
465 return false;
466}
467
[email protected]f3986f82012-01-03 20:00:06468// Fills |map| with the per-script font prefs under path |map_name|.
469void FillFontFamilyMap(const PrefService* prefs,
470 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53471 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06472 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
473 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
474 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
475 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23476 if (!font_family.empty())
477 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06478 }
479}
480
[email protected]a1733df2012-06-22 11:24:18481#if defined(OS_POSIX) && !defined(OS_MACOSX)
482int GetCrashSignalFD(const CommandLine& command_line) {
483 if (command_line.HasSwitch(switches::kExtensionProcess)) {
484 ExtensionCrashHandlerHostLinux* crash_handler =
485 ExtensionCrashHandlerHostLinux::GetInstance();
486 return crash_handler->GetDeathSignalSocket();
487 }
488
489 std::string process_type =
490 command_line.GetSwitchValueASCII(switches::kProcessType);
491
492 if (process_type == switches::kRendererProcess)
493 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
494
495 if (process_type == switches::kPluginProcess)
496 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
497
498 if (process_type == switches::kPpapiPluginProcess)
499 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
500
501 if (process_type == switches::kGpuProcess)
502 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
503
504 return -1;
505}
506#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
507
[email protected]d5bcd06f2013-04-21 08:07:24508#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30509GURL GetEffectiveURLForSignin(const GURL& url) {
510 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
511
512 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03513 // Copy the path because the argument to SetPathStr must outlive
514 // the Replacements object.
515 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30516 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03517 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30518 effective_url = effective_url.ReplaceComponents(replacements);
519 return effective_url;
520}
[email protected]d5bcd06f2013-04-21 08:07:24521#endif
[email protected]970c63e2013-03-07 00:25:30522
[email protected]eabbfb12013-04-05 23:28:35523void SetApplicationLocaleOnIOThread(const std::string& locale) {
524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
525 g_io_thread_application_locale.Get() = locale;
526}
527
[email protected]190e5e22013-07-27 05:59:23528#if !defined(OS_ANDROID)
529struct BlockedPopupParams {
530 BlockedPopupParams(const GURL& target_url,
531 const content::Referrer& referrer,
532 WindowOpenDisposition disposition,
533 const WebWindowFeatures& features,
534 bool user_gesture,
535 bool opener_suppressed,
536 int render_process_id,
537 int opener_id)
538 : target_url(target_url),
539 referrer(referrer),
540 disposition(disposition),
541 features(features),
542 user_gesture(user_gesture),
543 opener_suppressed(opener_suppressed),
544 render_process_id(render_process_id),
545 opener_id(opener_id)
546 {}
547
548 GURL target_url;
549 content::Referrer referrer;
550 WindowOpenDisposition disposition;
551 WebWindowFeatures features;
552 bool user_gesture;
553 bool opener_suppressed;
554 int render_process_id;
555 int opener_id;
556};
557
558void HandleBlockedPopupOnUIThread(const BlockedPopupParams& params) {
559 WebContents* tab =
560 tab_util::GetWebContentsByID(params.render_process_id, params.opener_id);
561 if (!tab)
562 return;
563
564 prerender::PrerenderManager* prerender_manager =
565 prerender::PrerenderManagerFactory::GetForProfile(
566 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]668cf6e2013-07-29 19:42:25567 if (prerender_manager) {
568 prerender_manager->DestroyPrerenderForRenderView(
569 params.render_process_id,
570 params.opener_id,
571 prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
572 }
[email protected]190e5e22013-07-27 05:59:23573
574 PopupBlockerTabHelper* popup_helper =
575 PopupBlockerTabHelper::FromWebContents(tab);
576 if (!popup_helper)
577 return;
578 popup_helper->AddBlockedPopup(params.target_url,
579 params.referrer,
580 params.disposition,
581 params.features,
582 params.user_gesture,
583 params.opener_suppressed);
584}
585#endif
586
[email protected]9dbfff12011-07-01 19:37:07587} // namespace
[email protected]c5dbef02011-05-13 05:06:09588
[email protected]d977f9c2011-03-14 16:10:26589namespace chrome {
590
[email protected]e461da2f2012-02-16 19:06:40591ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40592#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40593 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
594 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40595#endif
[email protected]1deace22013-05-22 06:14:46596
597 permissions_policy_delegate_.reset(
598 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40599}
600
601ChromeContentBrowserClient::~ChromeContentBrowserClient() {
602}
603
[email protected]bca18382012-06-25 19:15:23604// static
[email protected]37ca3fe02013-07-05 15:32:44605void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34606 user_prefs::PrefRegistrySyncable* registry) {
607 registry->RegisterBooleanPref(
608 prefs::kDisable3DAPIs,
609 false,
610 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
611 registry->RegisterBooleanPref(
612 prefs::kEnableHyperlinkAuditing,
613 true,
614 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
615 registry->RegisterBooleanPref(
616 prefs::kEnableMemoryInfo,
617 false,
618 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23619}
620
[email protected]eabbfb12013-04-05 23:28:35621// static
622void ChromeContentBrowserClient::SetApplicationLocale(
623 const std::string& locale) {
624 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
625
626 // This object is guaranteed to outlive all threads so we don't have to
627 // worry about the lack of refcounting and can just post as Unretained.
628 //
629 // The common case is that this function is called early in Chrome startup
630 // before any threads are created (it will also be called later if the user
631 // changes the pref). In this case, there will be no threads created and
632 // posting will fail. When there are no threads, we can just set the string
633 // without worrying about threadsafety.
634 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
635 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
636 g_io_thread_application_locale.Get() = locale;
637 }
638}
639
[email protected]50462bf02011-11-21 19:13:31640content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
641 const content::MainFunctionParams& parameters) {
642 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30643 // Construct the Main browser parts based on the OS type.
644#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31645 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04646#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31647 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30648#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22649 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26650#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31651 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14652#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09653 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30654#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31655 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04656#else
[email protected]b48c9182011-10-26 18:03:30657 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31658 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30659#endif
660
[email protected]7e75e4a2013-05-17 17:20:03661 chrome::AddProfilesExtraParts(main_parts);
662
[email protected]c7480942011-11-08 19:18:27663 // Construct additional browser parts. Stages are called in the order in
664 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22665#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51666 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04667#endif
[email protected]c7480942011-11-08 19:18:27668
669#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51670 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27671#endif
672
[email protected]dc04be7c2012-03-15 23:57:49673#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51674 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49675#endif
676
[email protected]e050ef142012-03-21 01:04:24677#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51678 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
679#endif
680
681#if defined(USE_X11)
682 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24683#endif
684
[email protected]95132f52013-04-12 02:19:04685 chrome::AddMetricsExtraParts(main_parts);
686
[email protected]50462bf02011-11-21 19:13:31687 return main_parts;
[email protected]f967b722011-09-07 00:58:04688}
689
[email protected]e94bbcb2012-09-07 05:33:57690std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19691 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57692 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53693 std::string partition_id;
694
695 // The partition ID for webview guest processes is the string value of its
696 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
697 if (site.SchemeIs(chrome::kGuestScheme))
698 partition_id = site.spec();
699
[email protected]056efdc2013-04-06 00:14:53700 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53701 return partition_id;
702}
703
704bool ChromeContentBrowserClient::IsValidStoragePartitionId(
705 content::BrowserContext* browser_context,
706 const std::string& partition_id) {
707 // The default ID is empty and is always valid.
708 if (partition_id.empty())
709 return true;
710
711 return GURL(partition_id).is_valid();
712}
713
714void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
715 content::BrowserContext* browser_context,
716 const GURL& site,
[email protected]14acc642012-11-17 12:20:10717 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53718 std::string* partition_domain,
719 std::string* partition_name,
720 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10721 // Default to the browser-wide storage partition and override based on |site|
722 // below.
723 partition_domain->clear();
724 partition_name->clear();
725 *in_memory = false;
726
[email protected]1bc28312012-11-08 08:31:53727 // For the webview tag, we create special guest processes, which host the
728 // tag content separately from the main application that embeds the tag.
729 // A webview tag can specify both the partition name and whether the storage
730 // for that partition should be persisted. Each tag gets a SiteInstance with
731 // a specially formatted URL, based on the application it is hosted by and
732 // the partition requested by it. The format for that URL is:
733 // chrome-guest://partition_domain/persist?partition_name
734 if (site.SchemeIs(chrome::kGuestScheme)) {
735 // Since guest URLs are only used for packaged apps, there must be an app
736 // id in the URL.
737 CHECK(site.has_host());
738 *partition_domain = site.host();
739 // Since persistence is optional, the path must either be empty or the
740 // literal string.
741 *in_memory = (site.path() != "/persist");
742 // The partition name is user supplied value, which we have encoded when the
743 // URL was created, so it needs to be decoded.
744 *partition_name = net::UnescapeURLComponent(site.query(),
745 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10746 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
747 // If |can_be_default| is false, the caller is stating that the |site|
748 // should be parsed as if it had isolated storage. In particular it is
749 // important to NOT check ExtensionService for the is_storage_isolated()
750 // attribute because this code path is run during Extension uninstall
751 // to do cleanup after the Extension has already been unloaded from the
752 // ExtensionService.
753 bool is_isolated = !can_be_default;
754 if (can_be_default) {
755 const Extension* extension = NULL;
756 Profile* profile = Profile::FromBrowserContext(browser_context);
757 ExtensionService* extension_service =
758 extensions::ExtensionSystem::Get(profile)->extension_service();
759 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55760 extension =
761 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43762 if (extension &&
763 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10764 is_isolated = true;
765 }
766 }
767 }
[email protected]1bc28312012-11-08 08:31:53768
[email protected]14acc642012-11-17 12:20:10769 if (is_isolated) {
770 CHECK(site.has_host());
771 // For extensions with isolated storage, the the host of the |site| is
772 // the |partition_domain|. The |in_memory| and |partition_name| are only
773 // used in guest schemes so they are cleared here.
774 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53775 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10776 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53777 }
[email protected]d1198fd2012-08-13 22:50:19778 }
779
[email protected]14acc642012-11-17 12:20:10780 // Assert that if |can_be_default| is false, the code above must have found a
781 // non-default partition. If this fails, the caller has a serious logic
782 // error about which StoragePartition they expect to be in and it is not
783 // safe to continue.
784 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44785}
786
[email protected]38b098f2012-03-14 21:11:57787content::WebContentsViewDelegate*
788 ChromeContentBrowserClient::GetWebContentsViewDelegate(
789 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27790 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32791}
792
[email protected]24665682013-02-25 20:59:38793// Check if the extension activity log is enabled for the profile.
794static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33795 // crbug.com/247908 - This should be IsLogEnabled except for an issue
796 // in chrome_frame_net_tests
797 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38798}
799
[email protected]738f57a2013-06-29 21:06:54800void ChromeContentBrowserClient::GuestWebContentsCreated(
801 WebContents* guest_web_contents,
802 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22803 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54804 scoped_ptr<base::DictionaryValue> extra_params) {
805 if (opener_web_contents) {
806 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
807 if (!guest) {
808 NOTREACHED();
809 return;
810 }
811
812 switch (guest->GetViewType()) {
813 case GuestView::WEBVIEW: {
[email protected]4c0e8272013-07-03 23:39:22814 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54815 break;
816 }
817 case GuestView::ADVIEW: {
[email protected]4c0e8272013-07-03 23:39:22818 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54819 break;
820 }
821 default:
822 NOTREACHED();
823 break;
824 }
825 return;
826 }
827
828 if (!extra_params) {
829 NOTREACHED();
830 return;
831 }
832 std::string api_type;
833 extra_params->GetString(guestview::kAttributeApi, &api_type);
834
835 if (api_type == "adview") {
[email protected]4c0e8272013-07-03 23:39:22836 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54837 } else if (api_type == "webview") {
[email protected]4c0e8272013-07-03 23:39:22838 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54839 } else {
840 NOTREACHED();
841 }
842}
843
[email protected]44295a12013-06-05 08:45:46844void ChromeContentBrowserClient::GuestWebContentsAttached(
845 WebContents* guest_web_contents,
846 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53847 int browser_plugin_instance_id,
848 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06849 Profile* profile = Profile::FromBrowserContext(
850 embedder_web_contents->GetBrowserContext());
851 ExtensionService* service =
852 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54853 if (!service) {
854 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06855 return;
[email protected]738f57a2013-06-29 21:06:54856 }
[email protected]44703cc72013-01-24 04:56:06857 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
[email protected]be9915fb2013-07-18 09:28:55858 const Extension* extension =
859 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]738f57a2013-06-29 21:06:54860 if (!extension) {
[email protected]18699372013-06-25 20:42:55861 NOTREACHED();
[email protected]738f57a2013-06-29 21:06:54862 return;
[email protected]18699372013-06-25 20:42:55863 }
[email protected]738f57a2013-06-29 21:06:54864
865 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
866 if (!guest) {
867 NOTREACHED();
868 return;
869 }
870 guest->Attach(embedder_web_contents,
871 extension->id(),
872 browser_plugin_instance_id,
873 extra_params);
[email protected]44703cc72013-01-24 04:56:06874}
875
[email protected]f3b1a082011-11-18 00:34:30876void ChromeContentBrowserClient::RenderProcessHostCreated(
877 content::RenderProcessHost* host) {
878 int id = host->GetID();
879 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41880 net::URLRequestContextGetter* context =
881 profile->GetRequestContextForRenderProcess(id);
882
[email protected]f3b1a082011-11-18 00:34:30883 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41884 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55885#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30886 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55887#endif
[email protected]658677f2012-06-09 06:04:02888#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08889 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03890#endif
[email protected]f3b1a082011-11-18 00:34:30891 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02892 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53893#if defined(ENABLE_SPELLCHECK)
[email protected]f3b1a082011-11-18 00:34:30894 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53895#endif
[email protected]7ceb99012011-12-21 08:05:56896#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21897 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56898#endif
[email protected]43535512013-02-20 20:41:41899 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
900 id, profile, context));
[email protected]2736c032012-05-11 18:06:07901 host->GetChannel()->AddFilter(
902 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27903 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33904 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31905#if defined(ENABLE_WEBRTC)
906 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
907#endif
[email protected]01e59752013-06-18 00:17:35908#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03909 ExtensionInfoMap* extension_info_map =
910 extensions::ExtensionSystem::Get(profile)->info_map();
911 host->GetChannel()->AddFilter(new NaClHostMessageFilter(
912 id, profile->IsOffTheRecord(),
913 profile->GetPath(), extension_info_map,
914 context));
[email protected]01e59752013-06-18 00:17:35915#endif
[email protected]3e69bc82011-05-26 23:22:38916
[email protected]2ccf45c2011-08-19 23:35:50917 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
918 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07919
[email protected]24665682013-02-25 20:59:38920 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
921 IsExtensionActivityLogEnabledForProfile(profile)));
922
[email protected]39a5b532011-10-22 01:47:07923 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56924
925 RendererContentSettingRules rules;
926 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
927 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14928}
929
[email protected]3d7474ff2011-07-27 17:47:37930GURL ChromeContentBrowserClient::GetEffectiveURL(
931 content::BrowserContext* browser_context, const GURL& url) {
932 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52933 if (!profile)
934 return url;
935
[email protected]b3cb3a32013-07-31 01:32:29936 // If the input |url| should be assigned to the Instant renderer, make its
937 // effective URL distinct from other URLs on the search provider's domain.
938 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
939 return chrome::GetEffectiveURLForInstant(url, profile);
940
[email protected]d5bcd06f2013-04-21 08:07:24941#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30942 // If the input |url| should be assigned to the Signin renderer, make its
943 // effective URL distinct from other URLs on the signin service's domain.
944 // Note that the signin renderer will be allowed to sign the user in to
945 // Chrome.
946 if (SigninManager::IsWebBasedSigninFlowURL(url))
947 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24948#endif
[email protected]970c63e2013-03-07 00:25:30949
[email protected]c5dec6292013-01-25 04:54:52950 // If the input |url| is part of an installed app, the effective URL is an
951 // extension URL with the ID of that extension as the host. This has the
952 // effect of grouping apps together in a common SiteInstance.
953 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13954 extensions::ExtensionSystem::Get(profile)->extension_service();
955 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08956 return url;
957
[email protected]06bdd2b2012-11-30 18:47:13958 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55959 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08960 if (!extension)
961 return url;
962
[email protected]15877ca2011-11-18 22:40:52963 // Bookmark apps do not use the hosted app process model, and should be
964 // treated as normal URLs.
965 if (extension->from_bookmark())
966 return url;
967
[email protected]36fb2c7c2011-04-04 15:49:08968 // If the URL is part of an extension's web extent, convert it to an
969 // extension URL.
970 return extension->GetResourceURL(url.path());
971}
972
[email protected]056ad2a2011-07-12 02:13:55973bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37974 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52975 // Non-extension, non-Instant URLs should generally use
976 // process-per-site-instance. Because we expect to use the effective URL,
977 // URLs for hosted apps (apart from bookmark apps) should have an extension
978 // scheme by now.
979
980 Profile* profile = Profile::FromBrowserContext(browser_context);
981 if (!profile)
982 return false;
983
[email protected]df113a12013-07-24 04:56:08984 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52985 return true;
986
[email protected]d5bcd06f2013-04-21 08:07:24987#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30988 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
989 return true;
[email protected]d5bcd06f2013-04-21 08:07:24990#endif
[email protected]970c63e2013-03-07 00:25:30991
[email protected]885c0e92012-11-13 20:27:42992 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55993 return false;
994
[email protected]c5dec6292013-01-25 04:54:52995 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13996 extensions::ExtensionSystem::Get(profile)->extension_service();
997 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55998 return false;
999
[email protected]be9915fb2013-07-18 09:28:551000 const Extension* extension =
1001 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:551002 if (!extension)
1003 return false;
1004
1005 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:531006 // permission, or that does not allow JavaScript access to the background
1007 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:551008 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:401009 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:061010 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:291011 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:531012 return false;
1013 }
1014 }
[email protected]056ad2a2011-07-12 02:13:551015
[email protected]7b54ca02012-03-02 18:06:531016 // Hosted apps that have script access to their background page must use
1017 // process per site, since all instances can make synchronous calls to the
1018 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:551019 return true;
1020}
1021
[email protected]672c8c12013-03-07 12:30:061022// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:411023void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1024 std::vector<std::string>* additional_schemes) {
1025 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:061026}
1027
[email protected]6bd30072013-02-08 18:17:111028net::URLRequestContextGetter*
1029ChromeContentBrowserClient::CreateRequestContext(
1030 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:061031 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111032 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:061033 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111034}
1035
1036net::URLRequestContextGetter*
1037ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1038 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:401039 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:111040 bool in_memory,
[email protected]672c8c12013-03-07 12:30:061041 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111042 Profile* profile = Profile::FromBrowserContext(browser_context);
1043 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:061044 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111045}
1046
[email protected]46fb9442011-12-09 17:57:471047bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1048 return ProfileIOData::IsHandledURL(url);
1049}
1050
[email protected]c4365fa42013-05-14 01:08:241051bool ChromeContentBrowserClient::CanCommitURL(
1052 content::RenderProcessHost* process_host,
1053 const GURL& url) {
1054 // We need to let most extension URLs commit in any process, since this can
1055 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1056 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1057 // cannot be loaded in iframes and should never be requested outside its
1058 // process.
1059 Profile* profile =
1060 Profile::FromBrowserContext(process_host->GetBrowserContext());
1061 ExtensionService* service =
1062 extensions::ExtensionSystem::Get(profile)->extension_service();
1063 if (!service)
1064 return true;
1065 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551066 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241067 if (new_extension &&
1068 new_extension->is_hosted_app() &&
1069 new_extension->id() == extension_misc::kWebStoreAppId &&
1070 !service->process_map()->Contains(new_extension->id(),
1071 process_host->GetID())) {
1072 return false;
1073 }
1074
1075 return true;
1076}
1077
[email protected]2a5221b2011-09-27 23:07:311078bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301079 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311080 const GURL& site_url) {
1081 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301082 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521083 // This may be NULL during tests. In that case, just assume any site can
1084 // share any host.
1085 if (!profile)
1086 return true;
1087
[email protected]d43f99fe2013-04-03 00:20:141088 // Instant URLs should only be in the instant process and instant process
1089 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521090 InstantService* instant_service =
1091 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141092 if (instant_service) {
1093 bool is_instant_process = instant_service->IsInstantProcess(
1094 process_host->GetID());
1095 bool should_be_in_instant_process =
1096 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1097 if (is_instant_process || should_be_in_instant_process)
1098 return is_instant_process && should_be_in_instant_process;
1099 }
[email protected]c5dec6292013-01-25 04:54:521100
[email protected]d5bcd06f2013-04-21 08:07:241101#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301102 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1103 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1104 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241105#endif
[email protected]970c63e2013-03-07 00:25:301106
[email protected]06bdd2b2012-11-30 18:47:131107 ExtensionService* service =
1108 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461109 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311110
[email protected]ffa97602011-11-17 17:55:521111 // Don't allow the Task Manager to share a process with anything else.
1112 // Otherwise it can affect the renderers it is observing.
1113 // Note: we could create another RenderProcessHostPrivilege bucket for
1114 // this to allow multiple chrome://tasks instances to share, but that's
1115 // a very unlikely case without serious consequences.
1116 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1117 return false;
1118
[email protected]8d3132f62011-10-12 07:13:421119 // These may be NULL during tests. In that case, just assume any site can
1120 // share any host.
[email protected]6f371442011-11-09 06:45:461121 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311122 return true;
1123
[email protected]eec0b33c2011-12-05 22:09:451124 // Otherwise, just make sure the process privilege matches the privilege
1125 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571126 RenderProcessHostPrivilege privilege_required =
1127 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451128 return GetProcessPrivilege(process_host, process_map, service) ==
1129 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311130}
1131
[email protected]76411f412012-02-22 18:56:061132// This function is trying to limit the amount of processes used by extensions
1133// with background pages. It uses a globally set percentage of processes to
1134// run such extensions and if the limit is exceeded, it returns true, to
1135// indicate to the content module to group extensions together.
1136bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1137 content::BrowserContext* browser_context, const GURL& url) {
1138 // It has to be a valid URL for us to check for an extension.
1139 if (!url.is_valid())
1140 return false;
1141
1142 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191143 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131144 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061145 if (!service)
1146 return false;
1147
1148 // We have to have a valid extension with background page to proceed.
1149 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551150 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061151 if (!extension)
1152 return false;
[email protected]9367eabc2013-03-01 01:29:291153 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061154 return false;
1155
1156 std::set<int> process_ids;
1157 size_t max_process_count =
1158 content::RenderProcessHost::GetMaxRendererProcessCount();
1159
1160 // Go through all profiles to ensure we have total count of extension
1161 // processes containing background pages, otherwise one profile can
1162 // starve the other.
1163 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1164 GetLoadedProfiles();
1165 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031166 ExtensionProcessManager* epm =
1167 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321168 for (ExtensionProcessManager::const_iterator iter =
1169 epm->background_hosts().begin();
1170 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131171 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321172 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061173 }
1174 }
1175
1176 if (process_ids.size() >
1177 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1178 return true;
1179 }
1180
1181 return false;
1182}
1183
[email protected]6f371442011-11-09 06:45:461184void ChromeContentBrowserClient::SiteInstanceGotProcess(
1185 SiteInstance* site_instance) {
1186 CHECK(site_instance->HasProcess());
1187
1188 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021189 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521190 if (!profile)
1191 return;
1192
1193 // Remember the ID of the Instant process to signal the renderer process
1194 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031195 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321196 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521197 InstantService* instant_service =
1198 InstantServiceFactory::GetForProfile(profile);
1199 if (instant_service)
1200 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1201 }
1202
[email protected]d5bcd06f2013-04-21 08:07:241203#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301204 // We only expect there to be one signin process as we use process-per-site
1205 // for signin URLs. The signin process will be cleared from SigninManager
1206 // when the renderer is destroyed.
1207 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1208 SigninManager* signin_manager =
1209 SigninManagerFactory::GetForProfile(profile);
1210 if (signin_manager)
1211 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461212 BrowserThread::PostTask(
1213 BrowserThread::IO, FROM_HERE,
1214 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1215 extensions::ExtensionSystem::Get(profile)->info_map(),
1216 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301217 }
[email protected]d5bcd06f2013-04-21 08:07:241218#endif
[email protected]970c63e2013-03-07 00:25:301219
[email protected]06bdd2b2012-11-30 18:47:131220 ExtensionService* service =
1221 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461222 if (!service)
1223 return;
1224
[email protected]be9915fb2013-07-18 09:28:551225 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1226 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461227 if (!extension)
1228 return;
1229
[email protected]6bc04fd82011-12-04 02:29:351230 service->process_map()->Insert(extension->id(),
1231 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331232 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461233 BrowserThread::PostTask(
1234 BrowserThread::IO, FROM_HERE,
1235 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591236 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461237 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351238 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331239 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461240}
1241
1242void ChromeContentBrowserClient::SiteInstanceDeleting(
1243 SiteInstance* site_instance) {
1244 if (!site_instance->HasProcess())
1245 return;
1246
1247 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021248 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131249 ExtensionService* service =
1250 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461251 if (!service)
1252 return;
1253
[email protected]be9915fb2013-07-18 09:28:551254 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1255 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461256 if (!extension)
1257 return;
1258
[email protected]6bc04fd82011-12-04 02:29:351259 service->process_map()->Remove(extension->id(),
1260 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331261 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461262 BrowserThread::PostTask(
1263 BrowserThread::IO, FROM_HERE,
1264 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591265 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461266 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351267 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331268 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461269}
1270
[email protected]f05763972012-06-06 18:17:261271bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141272 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081273 const GURL& current_url,
1274 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261275 if (current_url.is_empty()) {
1276 // Always choose a new process when navigating to extension URLs. The
1277 // process grouping logic will combine all of a given extension's pages
1278 // into the same process.
[email protected]885c0e92012-11-13 20:27:421279 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261280 return true;
[email protected]e3daf3c2011-10-05 21:17:081281
[email protected]f05763972012-06-06 18:17:261282 return false;
1283 }
1284
1285 // Also, we must switch if one is an extension and the other is not the exact
1286 // same extension.
[email protected]885c0e92012-11-13 20:27:421287 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1288 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261289 if (current_url.GetOrigin() != new_url.GetOrigin())
1290 return true;
1291 }
1292
[email protected]e9841fbd2013-02-22 23:12:141293 // The checks below only matter if we can retrieve which extensions are
1294 // installed.
1295 Profile* profile =
1296 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1297 ExtensionService* service =
1298 extensions::ExtensionSystem::Get(profile)->extension_service();
1299 if (!service)
1300 return false;
1301
1302 // We must swap if the URL is for an extension and we are not using an
1303 // extension process.
1304 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551305 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141306 // Ignore all hosted apps except the Chrome Web Store, since they do not
1307 // require their own BrowsingInstance (e.g., postMessage is ok).
1308 if (new_extension &&
1309 new_extension->is_hosted_app() &&
1310 new_extension->id() != extension_misc::kWebStoreAppId)
1311 new_extension = NULL;
1312 if (new_extension &&
1313 site_instance->HasProcess() &&
1314 !service->process_map()->Contains(new_extension->id(),
1315 site_instance->GetProcess()->GetID()))
1316 return true;
1317
[email protected]f05763972012-06-06 18:17:261318 return false;
[email protected]e3daf3c2011-10-05 21:17:081319}
1320
[email protected]395045c2012-05-22 15:04:381321bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1322 content::ResourceContext* resource_context, const GURL& current_url,
1323 const GURL& new_url) {
1324 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1325 return extensions::CrossesExtensionProcessBoundary(
1326 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551327 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381328}
1329
[email protected]3d831992013-07-04 01:13:291330bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1331 return !url.SchemeIs(chrome::kChromeNativeScheme);
1332}
1333
[email protected]763ec4ca2011-04-29 15:48:121334std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1335 const std::string& alias_name) {
1336 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1337}
1338
[email protected]b80f68432011-05-02 17:22:301339void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1340 CommandLine* command_line, int child_process_id) {
[email protected]97425082013-07-16 03:10:071341#if defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301342 if (IsCrashReporterEnabled()) {
1343 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1344 child_process_logging::GetClientId());
1345 }
[email protected]97425082013-07-16 03:10:071346#elif defined(OS_POSIX)
1347 if (IsCrashReporterEnabled()) {
1348 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1349 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1350 }
1351
[email protected]b80f68432011-05-02 17:22:301352#endif // OS_MACOSX
1353
[email protected]f1933792011-06-14 00:49:341354 if (logging::DialogsAreSuppressed())
1355 command_line->AppendSwitch(switches::kNoErrorDialogs);
1356
[email protected]b80f68432011-05-02 17:22:301357 std::string process_type =
1358 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171359 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321360
1361 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1362 command_line->AppendSwitch(switches::kChromeFrame);
1363
[email protected]718eab62011-10-05 21:16:521364 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451365 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301366 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1367 if (!user_data_dir.empty())
1368 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1369#if defined(OS_CHROMEOS)
1370 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441371 browser_command_line.GetSwitchValueASCII(
1372 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301373 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441374 command_line->AppendSwitchASCII(
1375 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301376#endif
1377
[email protected]f3b1a082011-11-18 00:34:301378 content::RenderProcessHost* process =
1379 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371380 if (process) {
1381 Profile* profile = Profile::FromBrowserContext(
1382 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131383 ExtensionService* extension_service =
1384 extensions::ExtensionSystem::Get(profile)->extension_service();
1385 if (extension_service) {
1386 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001387 if (process_map && process_map->Contains(process->GetID()))
1388 command_line->AppendSwitch(switches::kExtensionProcess);
1389 }
[email protected]b80f68432011-05-02 17:22:301390
[email protected]a8d851f82011-12-21 00:32:371391 PrefService* prefs = profile->GetPrefs();
1392 // Currently this pref is only registered if applied via a policy.
1393 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1394 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1395 // Turn this policy into a command line switch.
1396 command_line->AppendSwitch(switches::kDisable3DAPIs);
1397 }
[email protected]718eab62011-10-05 21:16:521398
[email protected]a8d851f82011-12-21 00:32:371399 // Disable client-side phishing detection in the renderer if it is
1400 // disabled in the Profile preferences or the browser process.
1401 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1402 !g_browser_process->safe_browsing_detection_service()) {
1403 command_line->AppendSwitch(
1404 switches::kDisableClientSidePhishingDetection);
1405 }
[email protected]0045b0f42012-07-26 11:52:081406
1407 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211408 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521409
1410 InstantService* instant_service =
1411 InstantServiceFactory::GetForProfile(profile);
1412 if (instant_service &&
1413 instant_service->IsInstantProcess(process->GetID()))
1414 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301415
[email protected]d5bcd06f2013-04-21 08:07:241416#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301417 SigninManager* signin_manager =
1418 SigninManagerFactory::GetForProfile(profile);
1419 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1420 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241421#endif
[email protected]47c7ec82012-01-18 03:29:211422 }
[email protected]4287a3d2011-06-13 23:56:511423
[email protected]87552982012-11-02 17:21:401424 if (content::IsThreadedCompositingEnabled())
1425 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1426
[email protected]16dc42452013-04-09 04:37:191427 if (message_center::IsRichNotificationEnabled())
1428 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191429
[email protected]47c7ec82012-01-18 03:29:211430 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511431 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171432 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481433 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171434 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]49d9b142013-07-19 08:50:271435 extensions::switches::kAllowLegacyExtensionManifests,
1436 extensions::switches::kAllowScriptingGallery,
1437 extensions::switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511438 switches::kAllowHTTPBackgroundPage,
[email protected]9d450492013-06-13 23:08:371439 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1440 // to browser.
1441 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511442 switches::kAppsCheckoutURL,
1443 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311444 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511445 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501446 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531447 switches::kDisableExtensionsResourceWhitelist,
[email protected]df4015352013-07-26 23:18:181448 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111449 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531450 switches::kEnableAdview,
1451 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441452 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211453 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511454 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511455 switches::kEnableIPCFuzzing,
1456 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451457 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481458 switches::kEnablePasswordGeneration,
[email protected]4287a3d2011-06-13 23:56:511459 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511460 switches::kMemoryProfiling,
1461 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371462 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371463 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511464 switches::kPpapiFlashArgs,
1465 switches::kPpapiFlashInProcess,
1466 switches::kPpapiFlashPath,
1467 switches::kPpapiFlashVersion,
1468 switches::kProfilingAtStart,
1469 switches::kProfilingFile,
1470 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371471 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511472 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291473 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381474 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511475 };
1476
1477 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1478 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171479 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381480 static const char* const kSwitchNames[] = {
[email protected]49d9b142013-07-19 08:50:271481 extensions::switches::kExtensionsOnChromeURLs,
[email protected]eb653f82012-05-24 02:31:351482 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381483 switches::kEnableExperimentalExtensionApis,
1484 switches::kWhitelistedExtensionID,
1485 };
1486
1487 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1488 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511489 } else if (process_type == switches::kPluginProcess) {
1490 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441491#if defined(OS_CHROMEOS)
1492 chromeos::switches::kLoginProfile,
1493#endif
[email protected]4287a3d2011-06-13 23:56:511494 switches::kMemoryProfiling,
1495 switches::kSilentDumpOnDCHECK,
1496 switches::kUserDataDir,
1497 };
1498
1499 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1500 arraysize(kSwitchNames));
1501 } else if (process_type == switches::kZygoteProcess) {
1502 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511503 switches::kUserDataDir, // Make logs go to the right file.
1504 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501505 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511506 switches::kPpapiFlashInProcess,
1507 switches::kPpapiFlashPath,
1508 switches::kPpapiFlashVersion,
1509 };
1510
1511 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1512 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111513 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001514 base::FilePath user_data_dir =
1515 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1516 if (!user_data_dir.empty())
1517 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111518 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1519 // because GPU is expected to be unreliable.
1520 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1521 !command_line->HasSwitch(switches::kDisableBreakpad))
1522 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301523 }
[email protected]6f08af82011-09-15 01:19:031524
1525 // The command line switch kEnableBenchmarking needs to be specified along
1526 // with the kEnableStatsTable switch to ensure that the stats table global
1527 // is initialized correctly.
1528 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1529 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301530}
1531
1532std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431533 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351534 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301535 return g_browser_process->GetApplicationLocale();
1536}
1537
[email protected]597a867b2011-11-18 18:31:201538std::string ChromeContentBrowserClient::GetAcceptLangs(
1539 content::BrowserContext* context) {
1540 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371541 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081542}
1543
[email protected]9ec0f452012-05-31 15:58:531544gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221545 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531546 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081547}
1548
[email protected]a2176792011-05-08 19:30:491549bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091550 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191551 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201552 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321553 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201554 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051555 return io_data->GetCookieSettings()->
1556 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491557}
1558
[email protected]ed24fad2011-05-10 22:44:011559bool ChromeContentBrowserClient::AllowGetCookie(
1560 const GURL& url,
1561 const GURL& first_party,
1562 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201563 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011564 int render_process_id,
1565 int render_view_id) {
1566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201567 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051568 bool allow = io_data->GetCookieSettings()->
1569 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011570
[email protected]8093a542011-05-13 07:29:321571 BrowserThread::PostTask(
1572 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031573 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431574 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011575 return allow;
1576}
1577
1578bool ChromeContentBrowserClient::AllowSetCookie(
1579 const GURL& url,
1580 const GURL& first_party,
1581 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201582 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011583 int render_process_id,
1584 int render_view_id,
1585 net::CookieOptions* options) {
1586 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201587 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051588 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1589 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1590
[email protected]8093a542011-05-13 07:29:321591 BrowserThread::PostTask(
1592 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031593 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431594 render_view_id, url, first_party, cookie_line, *options,
1595 !allow));
[email protected]ed24fad2011-05-10 22:44:011596 return allow;
1597}
1598
[email protected]d5a19162011-06-30 18:51:541599bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201600 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201602 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431603 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1604 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261605
[email protected]bf510ed2012-06-05 08:31:431606 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1607 // Could we even support per-origin settings?
1608 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541609}
1610
[email protected]5c5a88e2011-11-12 00:45:351611bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351612 const GURL& url,
1613 const string16& name,
1614 const string16& display_name,
1615 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201616 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481617 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201619 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351620 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1621 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1622
[email protected]62151052012-02-01 18:40:481623 // Record access to database for potential display in UI.
1624 std::vector<std::pair<int, int> >::const_iterator i;
1625 for (i = render_views.begin(); i != render_views.end(); ++i) {
1626 BrowserThread::PostTask(
1627 BrowserThread::UI, FROM_HERE,
1628 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1629 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351630 }
1631
1632 return allow;
1633}
1634
1635bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351636 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201637 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481638 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201640 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351641 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1642 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1643
[email protected]62151052012-02-01 18:40:481644 // Record access to file system for potential display in UI.
1645 std::vector<std::pair<int, int> >::const_iterator i;
1646 for (i = render_views.begin(); i != render_views.end(); ++i) {
1647 BrowserThread::PostTask(
1648 BrowserThread::UI, FROM_HERE,
1649 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1650 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351651 }
1652
1653 return allow;
1654}
1655
[email protected]7c5ff9a2012-03-02 07:42:491656bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1657 const GURL& url,
1658 const string16& name,
1659 content::ResourceContext* context,
1660 const std::vector<std::pair<int, int> >& render_views) {
1661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1662 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1663 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1664 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1665
1666 // Record access to IndexedDB for potential display in UI.
1667 std::vector<std::pair<int, int> >::const_iterator i;
1668 for (i = render_views.begin(); i != render_views.end(); ++i) {
1669 BrowserThread::PostTask(
1670 BrowserThread::UI, FROM_HERE,
1671 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1672 i->first, i->second, url, name, !allow));
1673 }
1674
1675 return allow;
1676}
1677
[email protected]6133f922011-07-01 21:34:341678net::URLRequestContext*
1679ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201680 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421682 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201683 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341684 return io_data->extensions_request_context();
1685 }
1686
1687 return NULL;
1688}
1689
[email protected]317f96c92011-05-31 06:53:411690QuotaPermissionContext*
1691ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1692 return new ChromeQuotaPermissionContext();
1693}
1694
[email protected]848dd042011-06-04 18:24:031695void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171696 int render_process_id,
1697 int render_view_id,
1698 int cert_error,
1699 const net::SSLInfo& ssl_info,
1700 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021701 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031702 bool overridable,
[email protected]d9be47702012-05-16 03:41:221703 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171704 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001705 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021706 if (resource_type != ResourceType::MAIN_FRAME) {
1707 // A sub-resource has a certificate error. The user doesn't really
1708 // have a context for making the right decision, so block the
1709 // request hard, without an info bar to allow showing the insecure
1710 // content.
[email protected]8c965c22013-05-23 19:28:001711 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021712 return;
1713 }
1714
[email protected]f9034cf2011-07-21 12:43:411715 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131716 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171717 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411718 if (!tab) {
1719 NOTREACHED();
1720 return;
1721 }
1722 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501723 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301724 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011725 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1726 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411727 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171728 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411729 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001730 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411731 return;
1732 }
1733 }
1734
[email protected]1e87df32012-09-12 04:53:191735#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231736 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1737 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1738 if (captive_portal_tab_helper)
1739 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191740#endif
1741
[email protected]f9034cf2011-07-21 12:43:411742 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221743 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1744 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031745}
1746
[email protected]c99c442e2011-08-24 11:37:301747void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451748 int render_process_id,
1749 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401750 const net::HttpNetworkSession* network_session,
1751 net::SSLCertRequestInfo* cert_request_info,
1752 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131753 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451754 render_process_id, render_view_id);
1755 if (!tab) {
1756 NOTREACHED();
1757 return;
1758 }
1759
[email protected]6786bf402011-12-03 15:19:451760 GURL requesting_url("https://" + cert_request_info->host_and_port);
1761 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1762 << cert_request_info->host_and_port;
1763
[email protected]627e0512011-12-21 22:55:301764 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451765 scoped_ptr<Value> filter(
1766 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1767 requesting_url,
1768 requesting_url,
1769 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1770 std::string(), NULL));
1771
1772 if (filter.get()) {
1773 // Try to automatically select a client certificate.
1774 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1775 DictionaryValue* filter_dict =
1776 static_cast<DictionaryValue*>(filter.get());
1777
1778 const std::vector<scoped_refptr<net::X509Certificate> >&
1779 all_client_certs = cert_request_info->client_certs;
1780 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091781 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451782 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091783 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451784 return;
1785 }
1786 }
1787 } else {
1788 NOTREACHED();
1789 }
1790 }
1791
[email protected]11feec322012-09-18 03:58:521792 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1793 if (!ssl_tab_helper) {
1794 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451795 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141796 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401797 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451798 return;
1799 }
[email protected]11feec322012-09-18 03:58:521800 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401801 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451802}
1803
[email protected]3b455502012-12-11 18:22:581804void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451805 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581806 net::CertificateMimeType cert_type,
1807 const void* cert_data,
1808 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451809 int render_process_id,
1810 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581811 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1812 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451813}
1814
[email protected]dc73a7b2012-03-25 15:27:181815content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561816 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181817}
1818
[email protected]941623e2011-06-07 23:06:041819void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1820 const GURL& source_origin,
1821 int callback_context,
1822 int render_process_id,
1823 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111824#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021825 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1826 WebContents* contents =
1827 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1828 if (!contents) {
[email protected]941623e2011-06-07 23:06:041829 NOTREACHED();
1830 return;
1831 }
1832
[email protected]d0d9c3ee2012-06-19 03:07:021833 // Skip showing the infobar if the request comes from an extension, and that
1834 // extension has the 'notify' permission. (If the extension does not have the
1835 // permission, the user will still be prompted.)
1836 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011837 ExtensionInfoMap* extension_info_map =
1838 extensions::ExtensionSystem::Get(profile)->info_map();
1839 DesktopNotificationService* notification_service =
1840 DesktopNotificationServiceFactory::GetForProfile(profile);
1841 const Extension* extension = NULL;
1842 if (extension_info_map) {
1843 ExtensionSet extensions;
1844 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1845 source_origin, render_process_id,
1846 extensions::APIPermission::kNotification, &extensions);
1847 for (ExtensionSet::const_iterator iter = extensions.begin();
1848 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381849 if (notification_service->IsNotifierEnabled(NotifierId(
1850 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361851 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011852 break;
1853 }
1854 }
1855 }
[email protected]eb4832a2012-12-08 01:57:521856 RenderViewHost* rvh =
1857 RenderViewHost::FromID(render_process_id, render_view_id);
1858 if (IsExtensionWithPermissionOrSuggestInConsole(
1859 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021860 if (rvh)
1861 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1862 return;
1863 }
1864
[email protected]c7cd5942013-04-30 03:31:011865 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021866 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111867#else
1868 NOTIMPLEMENTED();
1869#endif
[email protected]941623e2011-06-07 23:06:041870}
1871
1872WebKit::WebNotificationPresenter::Permission
1873 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021874 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201875 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021876 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111877#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041878 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481879 // Sometimes a notification may be invoked during the shutdown.
1880 // See http://crbug.com/256638
1881 if (browser_shutdown::IsTryingToQuit())
1882 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
1883
[email protected]df02aca2012-02-09 21:03:201884 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041885
[email protected]c7cd5942013-04-30 03:31:011886 DesktopNotificationService* notification_service =
1887 io_data->GetNotificationService();
1888 if (notification_service) {
1889 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1890 ExtensionSet extensions;
1891 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1892 source_origin, render_process_id,
1893 extensions::APIPermission::kNotification, &extensions);
1894 for (ExtensionSet::const_iterator iter = extensions.begin();
1895 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381896 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
1897 if (notification_service->IsNotifierEnabled(notifier_id))
[email protected]c7cd5942013-04-30 03:31:011898 return WebKit::WebNotificationPresenter::PermissionAllowed;
1899 }
1900
1901 return notification_service->HasPermission(source_origin);
1902 }
1903
1904 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111905#else
1906 return WebKit::WebNotificationPresenter::PermissionAllowed;
1907#endif
[email protected]941623e2011-06-07 23:06:041908}
1909
1910void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171911 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041912 int render_process_id,
1913 int render_view_id,
1914 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111915#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041916 RenderViewHost* rvh = RenderViewHost::FromID(
1917 render_process_id, render_view_id);
1918 if (!rvh) {
1919 NOTREACHED();
1920 return;
1921 }
1922
[email protected]9f76c1e2012-03-05 15:15:581923 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301924 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041925 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371926 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041927 service->ShowDesktopNotification(
1928 params, render_process_id, render_view_id,
1929 worker ? DesktopNotificationService::WorkerNotification :
1930 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111931#else
1932 NOTIMPLEMENTED();
1933#endif
[email protected]941623e2011-06-07 23:06:041934}
1935
1936void ChromeContentBrowserClient::CancelDesktopNotification(
1937 int render_process_id,
1938 int render_view_id,
1939 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111940#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041941 RenderViewHost* rvh = RenderViewHost::FromID(
1942 render_process_id, render_view_id);
1943 if (!rvh) {
1944 NOTREACHED();
1945 return;
1946 }
1947
[email protected]9f76c1e2012-03-05 15:15:581948 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301949 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041950 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371951 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041952 service->CancelDesktopNotification(
1953 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111954#else
1955 NOTIMPLEMENTED();
1956#endif
[email protected]941623e2011-06-07 23:06:041957}
1958
[email protected]9f3fba52011-06-08 20:37:191959bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351960 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021961 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191962 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:231963 const GURL& target_url,
1964 const content::Referrer& referrer,
1965 WindowOpenDisposition disposition,
1966 const WebWindowFeatures& features,
1967 bool user_gesture,
1968 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:201969 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011970 int render_process_id,
[email protected]190e5e22013-07-27 05:59:231971 bool is_guest,
1972 int opener_id,
[email protected]03b6d552012-03-29 04:03:011973 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191974 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011975
1976 *no_javascript_access = false;
1977
[email protected]9f3fba52011-06-08 20:37:191978 // If the opener is trying to create a background window but doesn't have
1979 // the appropriate permission, fail the attempt.
1980 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201981 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531982 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1983
[email protected]03b6d552012-03-29 04:03:011984 if (!map->SecurityOriginHasAPIPermission(
1985 source_origin,
1986 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061987 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011988 return false;
1989 }
1990
[email protected]7b54ca02012-03-02 18:06:531991 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1992 // return a recently installed Extension even if this CanCreateWindow call
1993 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011994 // because the permission check above would have caused an early return
1995 // already. We must use the full URL to find hosted apps, though, and not
1996 // just the origin.
[email protected]be9915fb2013-07-18 09:28:551997 const Extension* extension =
1998 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:291999 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012000 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:232001
2002 return true;
[email protected]9f3fba52011-06-08 20:37:192003 }
[email protected]056efdc2013-04-06 00:14:532004
2005 // No new browser window (popup or tab) in app mode.
2006 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
2007 chrome::IsRunningInForcedAppMode()) {
2008 return false;
2009 }
2010
[email protected]190e5e22013-07-27 05:59:232011#if !defined(OS_ANDROID)
2012 if (CommandLine::ForCurrentProcess()->HasSwitch(
2013 switches::kDisableBetterPopupBlocking)) {
2014 return true;
2015 }
2016
2017 if (is_guest)
2018 return true;
2019
[email protected]190e5e22013-07-27 05:59:232020 HostContentSettingsMap* content_settings =
2021 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
2022
2023 if ((disposition == NEW_POPUP || disposition == NEW_FOREGROUND_TAB ||
2024 disposition == NEW_BACKGROUND_TAB) && !user_gesture &&
2025 !CommandLine::ForCurrentProcess()->HasSwitch(
2026 switches::kDisablePopupBlocking)) {
2027 if (content_settings->GetContentSetting(opener_url,
2028 opener_url,
2029 CONTENT_SETTINGS_TYPE_POPUPS,
2030 std::string()) ==
2031 CONTENT_SETTING_ALLOW) {
2032 return true;
2033 }
2034
2035 BrowserThread::PostTask(BrowserThread::UI,
2036 FROM_HERE,
2037 base::Bind(&HandleBlockedPopupOnUIThread,
2038 BlockedPopupParams(target_url,
2039 referrer,
2040 disposition,
2041 features,
2042 user_gesture,
2043 opener_suppressed,
2044 render_process_id,
2045 opener_id)));
2046 return false;
2047 }
2048#endif
2049
[email protected]9f3fba52011-06-08 20:37:192050 return true;
2051}
2052
2053std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202054 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192055 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2056 // Check if it's an extension-created worker, in which case we want to use
2057 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202058 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192059 const Extension* extension =
2060 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2061 return extension ? extension->name() : std::string();
2062}
2063
[email protected]99907362012-01-11 05:41:402064void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2065 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172066}
2067
[email protected]7a06d282013-05-03 04:39:332068// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022069content::SpeechRecognitionManagerDelegate*
2070 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002071#if defined(ENABLE_INPUT_SPEECH)
2072 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322073#else
[email protected]855e18b2013-07-08 21:02:002074 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2075 // need the base delegate without the bubble UI.
2076 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322077#endif
[email protected]66cfec62012-02-24 17:57:512078}
2079
[email protected]ae6e9912011-07-27 01:18:282080net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2081 return g_browser_process->net_log();
2082}
2083
[email protected]32538d92011-08-25 00:09:232084AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2085 return new ChromeAccessTokenStore();
2086}
2087
[email protected]dbae6b02011-06-29 23:51:412088bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012089 return true;
[email protected]dbae6b02011-06-29 23:51:412090}
2091
[email protected]64d69de42012-02-06 00:19:542092void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322093 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062094 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582095 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062096 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062097
[email protected]f3986f82012-01-03 20:00:062098 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542099 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062100 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542101 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062102 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542103 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062104 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542105 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062106 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542107 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062108 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542109 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032110 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2111 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:062112
[email protected]64d69de42012-02-06 00:19:542113 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402114 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542115 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402116 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542117 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402118 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542119 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402120 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062121
[email protected]ddf72142012-05-22 04:52:402122 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062123
[email protected]64d69de42012-02-06 00:19:542124 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402125 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542126 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062127 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542128 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062129 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2130 const DictionaryValue* inspector_settings =
2131 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2132 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182133 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2134 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062135 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182136 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542137 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182138 std::make_pair(iter.key(), value));
2139 }
[email protected]f3986f82012-01-03 20:00:062140 }
2141 }
[email protected]64d69de42012-02-06 00:19:542142 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062143
[email protected]ddf72142012-05-22 04:52:402144 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542145 web_prefs->javascript_enabled = false;
2146 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2147 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402148 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542149 web_prefs->plugins_enabled = false;
2150 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2151 web_prefs->java_enabled = false;
2152 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402153 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062154
[email protected]64d69de42012-02-06 00:19:542155 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2156 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062157
[email protected]64d69de42012-02-06 00:19:542158 web_prefs->memory_info_enabled =
2159 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2160 web_prefs->allow_displaying_insecure_content =
2161 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2162 web_prefs->allow_running_insecure_content =
2163 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322164#if defined(OS_ANDROID)
2165 web_prefs->font_scale_factor =
2166 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2167 web_prefs->force_enable_zoom =
2168 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:452169#if defined(GOOGLE_TV)
2170 web_prefs->user_gesture_required_for_media_playback = false;
2171#endif
[email protected]d3b935f2012-10-19 23:14:322172#endif
[email protected]5c915252013-05-07 13:15:392173
[email protected]af4256d52013-06-04 20:39:072174#if defined(OS_ANDROID)
2175 web_prefs->password_echo_enabled =
2176 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2177#else
[email protected]9d06d88d2012-02-23 22:37:082178 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072179#endif
2180
[email protected]5c915252013-05-07 13:15:392181#if defined(OS_CHROMEOS)
2182 // Enable password echo during OOBE when keyboard driven flag is set.
2183 if (chromeos::UserManager::IsInitialized() &&
2184 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
[email protected]c94ac692013-07-27 00:50:102185 !chromeos::StartupUtils::IsOobeCompleted() &&
2186 chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation()) {
2187 web_prefs->password_echo_enabled = true;
[email protected]5c915252013-05-07 13:15:392188 }
2189#endif
[email protected]f3986f82012-01-03 20:00:062190
[email protected]46f8e742013-05-03 18:37:142191#if defined(OS_ANDROID)
2192 web_prefs->user_style_sheet_enabled = false;
2193#else
[email protected]64d69de42012-02-06 00:19:542194 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152195 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362196 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152197 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542198 web_prefs->user_style_sheet_enabled = true;
2199 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152200 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542201 } else {
2202 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062203 }
[email protected]46f8e742013-05-03 18:37:142204#endif
[email protected]f3986f82012-01-03 20:00:062205
[email protected]cfadadd2013-04-03 04:43:022206 web_prefs->asynchronous_spell_checking_enabled = true;
2207 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572208
[email protected]64d69de42012-02-06 00:19:542209 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062210 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542211 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062212 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542213 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062214 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2215
2216 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542217 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062218 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542219 web_prefs->default_encoding);
2220 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402221 prefs->ClearPref(prefs::kDefaultCharset);
2222 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062223 }
[email protected]64d69de42012-02-06 00:19:542224 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062225
[email protected]88ecf66d2012-12-11 22:53:472226 if (content::IsForceCompositingModeEnabled())
2227 web_prefs->force_compositing_mode = true;
2228
[email protected]299d7f12012-05-23 05:31:152229 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232230 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132231 ExtensionService* service =
2232 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062233 if (service) {
[email protected]1bc28312012-11-08 08:31:532234 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2235 const Extension* extension = service->extensions()->GetByID(url.host());
2236 // Ensure that we are only granting extension preferences to URLs with
2237 // the correct scheme. Without this check, chrome-guest:// schemes used by
2238 // webview tags as well as hosts that happen to match the id of an
2239 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422240 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532241 extension_webkit_preferences::SetPreferences(
2242 extension, view_type, web_prefs);
2243 }
[email protected]f3986f82012-01-03 20:00:062244 }
2245
[email protected]cb2edf22013-04-01 20:25:232246 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542247 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232248 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062249 // Disable all kinds of acceleration for background pages.
2250 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542251 web_prefs->force_compositing_mode = false;
2252 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062253 }
[email protected]2e21fe292012-03-02 22:52:322254
2255#if defined(FILE_MANAGER_EXTENSION)
2256 // Override the default of suppressing HW compositing for WebUI pages for the
2257 // file manager, which is implemented using WebUI but wants HW acceleration
2258 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532259 if (url.SchemeIs(extensions::kExtensionScheme) &&
2260 url.host() == kFileBrowserDomain) {
[email protected]2e21fe292012-03-02 22:52:322261 web_prefs->accelerated_compositing_enabled = true;
2262 web_prefs->accelerated_2d_canvas_enabled = true;
2263 }
2264#endif
[email protected]181a95ee2011-07-12 19:26:362265}
2266
2267void ChromeContentBrowserClient::UpdateInspectorSetting(
2268 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062269 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582270 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062271 DictionaryPrefUpdate update(
2272 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2273 prefs::kWebKitInspectorSettings);
2274 DictionaryValue* inspector_settings = update.Get();
2275 inspector_settings->SetWithoutPathExpansion(key,
2276 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362277}
2278
[email protected]b8148ac2011-07-13 22:03:252279void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2280 BrowserURLHandler* handler) {
2281 // Add the default URL handlers.
2282 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2283 BrowserURLHandler::null_handler());
2284 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2285 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2286
[email protected]b3adbd02011-11-30 22:23:272287 // about: handler. Must come before chrome: handler, since it will
2288 // rewrite about: urls to chrome: URLs and then expect chrome: to
2289 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252290 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2291 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032292
2293 // Handler to rewrite chrome://newtab for InstantExtended.
2294 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2295 &chrome::HandleNewTabURLReverseRewrite);
2296
[email protected]b8148ac2011-07-13 22:03:252297 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242298 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252299}
2300
2301void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372302 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582303 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472304 BrowsingDataRemover* remover =
2305 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552306 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2307 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252308 // BrowsingDataRemover takes care of deleting itself when done.
2309}
2310
2311void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372312 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582313 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472314 BrowsingDataRemover* remover =
2315 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232316 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552317 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252318 // BrowsingDataRemover takes care of deleting itself when done.
2319}
2320
[email protected]650b2d52013-02-10 03:41:452321base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322322 return download_util::GetDefaultDownloadDirectory();
2323}
2324
[email protected]c9b6eb62011-10-18 20:49:392325std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2326 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2327}
2328
[email protected]b7631cc2012-09-15 05:08:382329void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2330 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542331#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382332 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2333 scoped_ptr<ppapi::host::HostFactory>(
2334 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542335#endif
[email protected]b7631cc2012-09-15 05:08:382336}
2337
[email protected]0c7193742012-11-07 19:05:032338content::BrowserPpapiHost*
2339 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2340 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132341 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032342 while (!iter.Done()) {
2343 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2344 if (host->process() &&
2345 host->process()->GetData().id == plugin_process_id) {
2346 // Found the plugin.
2347 return host->browser_ppapi_host();
2348 }
2349 ++iter;
2350 }
2351 return NULL;
2352}
2353
[email protected]7b38b192013-03-23 18:39:312354bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2355 content::BrowserContext* browser_context, const GURL& site_url) {
2356 if (CommandLine::ForCurrentProcess()->HasSwitch(
2357 switches::kEnableBrowserPluginForAllViewTypes))
2358 return true;
2359
2360 Profile* profile = Profile::FromBrowserContext(browser_context);
2361 ExtensionService* service =
2362 extensions::ExtensionSystem::Get(profile)->extension_service();
2363 if (!service)
2364 return false;
2365
[email protected]be9915fb2013-07-18 09:28:552366 const Extension* extension =
2367 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312368 if (!extension)
2369 return false;
2370
[email protected]c2d2f102013-04-29 16:42:582371 return extension->HasAPIPermission(APIPermission::kWebView) ||
2372 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312373}
2374
[email protected]38cd8f7f2012-06-15 22:06:072375bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582376 content::BrowserContext* browser_context,
2377 const GURL& url,
[email protected]dda54822013-06-15 01:26:392378 bool private_api,
[email protected]157cc902012-11-02 06:31:582379 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402380#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372381 Profile* profile = Profile::FromBrowserContext(browser_context);
2382 const ExtensionSet* extension_set = NULL;
2383 if (profile) {
2384 extension_set = extensions::ExtensionSystem::Get(profile)->
2385 extension_service()->extensions();
2386 }
[email protected]dda54822013-06-15 01:26:392387
2388 if (private_api) {
2389 // Access to private socket APIs is controlled by the whitelist.
2390 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2391 allowed_socket_origins_)) {
2392 return true;
2393 }
2394 } else {
2395 // Access to public socket APIs is controlled by extension permissions.
2396 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2397 extension_set) {
2398 const Extension* extension = extension_set->GetByID(url.host());
2399 if (extension) {
2400 extensions::SocketPermission::CheckParam check_params(
2401 params.type, params.host, params.port);
2402 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2403 extension, extensions::APIPermission::kSocket, &check_params)) {
2404 return true;
2405 }
2406 }
2407 }
2408 }
2409
2410 // Allow both public and private APIs if the command line says so.
2411 return IsHostAllowedByCommandLine(url, extension_set,
2412 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402413#else
[email protected]a658d452012-03-02 12:45:292414 return false;
[email protected]93f72062013-05-29 20:29:402415#endif
[email protected]e461da2f2012-02-16 19:06:402416}
2417
[email protected]650b2d52013-02-10 03:41:452418base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2419 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142420 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2421 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2422}
2423
[email protected]a28e3302013-02-03 03:50:432424ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2425 WebContents* web_contents) {
2426 return new ChromeSelectFilePolicy(web_contents);
2427}
2428
[email protected]7d9424702013-04-14 13:14:162429void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2430 std::vector<std::string>* additional_allowed_schemes) {
2431 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2432 additional_allowed_schemes);
2433 additional_allowed_schemes->push_back(kChromeUIScheme);
2434 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2435}
2436
[email protected]f19bbf62013-07-09 01:22:322437void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312438 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532439 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322440 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532441#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032442 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322443 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032444 storage_partition_path,
2445 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322446 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532447#endif
[email protected]b40015c2013-06-26 08:13:312448#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312449 fileapi::ExternalMountPoints* external_mount_points =
2450 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312451 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322452 chromeos::FileSystemBackend* backend =
2453 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312454 new drive::FileSystemBackendDelegate(browser_context),
2455 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312456 external_mount_points,
2457 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322458 backend->AddSystemMountPoints();
2459 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2460 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312461#endif
[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