blob: 3cc9abdf3db8da3a091d5f89eb643bc3ee7a0f65 [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]8ec71262011-07-28 08:12:4679#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5880#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0381#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5282#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4583#include "chrome/browser/tab_contents/tab_util.h"
[email protected]a28e3302013-02-03 03:50:4384#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2585#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4486#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5087#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0688#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1589#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2790#include "chrome/browser/validation_message_message_filter.h"
[email protected]b80f68432011-05-02 17:22:3091#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0192#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1493#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3094#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2995#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0496#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3897#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4498#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4399#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:29100#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]dda54822013-06-15 01:26:39101#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]157cc902012-11-02 06:31:58102#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:34103#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37104#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12105#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38106#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09107#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53108#include "chromeos/chromeos_constants.h"
[email protected]d5d383252013-07-04 14:44:32109#include "components/nacl/common/nacl_process_type.h"
[email protected]75fee372013-03-06 00:42:44110#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43111#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30112#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38113#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03114#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31115#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03116#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59117#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36118#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30119#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33120#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05121#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33122#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19123#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10124#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43125#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18126#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23127#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42128#include "extensions/common/constants.h"
[email protected]49d9b142013-07-19 08:50:27129#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39130#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23131#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53132#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58133#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34134#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06135#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57136#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38137#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39138#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08139#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24140#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31141#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18142#include "webkit/common/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04143#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26144
[email protected]b48c9182011-10-26 18:03:30145#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38146#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18147#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38148#elif defined(OS_MACOSX)
149#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56150#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30151#elif defined(OS_CHROMEOS)
152#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]f19bbf62013-07-09 01:22:32153#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h"
154#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39155#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49156#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10157#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44158#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26159#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30160#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09161#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38162#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09163#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39164#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30165#elif defined(OS_POSIX)
166#include "chrome/browser/chrome_browser_main_posix.h"
167#endif
168
[email protected]6653c192012-04-10 22:52:44169#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30170#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12171#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43172#endif
[email protected]b80f68432011-05-02 17:22:30173
[email protected]190e5e22013-07-27 05:59:23174#if !defined(OS_ANDROID)
175#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
176#endif
177
[email protected]1e87df32012-09-12 04:53:19178#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
179#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
180#endif
181
[email protected]29699c22012-10-03 23:57:39182#if defined(OS_ANDROID)
183#include "ui/base/ui_base_paths.h"
184#endif
185
[email protected]37a72af2011-06-13 05:42:01186#if defined(USE_NSS)
187#include "chrome/browser/ui/crypto_module_password_dialog.h"
188#endif
189
[email protected]d5bcd06f2013-04-21 08:07:24190#if !defined(OS_CHROMEOS)
191#include "chrome/browser/signin/signin_manager.h"
192#include "chrome/browser/signin/signin_manager_factory.h"
193#endif
194
[email protected]02250952013-04-24 23:52:53195#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32196#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53197#endif
198
[email protected]6ef98b5a2013-05-31 23:58:31199#if defined(ENABLE_WEBRTC)
200#include "chrome/browser/media/webrtc_logging_handler_host.h"
201#endif
202
[email protected]855e18b2013-07-08 21:02:00203#if defined(ENABLE_INPUT_SPEECH)
204#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
205#endif
206
[email protected]02a3dc122013-06-13 15:07:53207#if defined(FILE_MANAGER_EXTENSION)
208#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
209#endif
210
[email protected]e8b6ca02013-07-10 18:00:51211#if defined(TOOLKIT_GTK)
212#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
213#endif
214
215#if defined(TOOLKIT_VIEWS)
216#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
217#endif
218
219#if defined(USE_ASH)
220#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
221#endif
222
223#if defined(USE_AURA)
224#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
225#endif
226
227#if defined(USE_X11)
228#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
229#endif
230
[email protected]190e5e22013-07-27 05:59:23231using WebKit::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08232using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47233using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03234using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39235using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31236using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59237using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08238using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00239using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11240using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33241using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13242using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06243using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34244using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40245using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38246using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39247
[email protected]c5dbef02011-05-13 05:06:09248namespace {
249
[email protected]eabbfb12013-04-05 23:28:35250// Cached version of the locale so we can return the locale on the I/O
251// thread.
252base::LazyInstance<std::string> g_io_thread_application_locale;
253
[email protected]93f72062013-05-29 20:29:40254#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40255const char* kPredefinedAllowedSocketOrigins[] = {
256 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18257 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45258 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
259 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
260 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
261 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35262 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54263 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
264 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
265 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
266 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
267 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
268 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38269 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58270 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29271 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]f6599915a2013-06-20 20:03:50272 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
[email protected]b71313232013-05-06 06:16:29273 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
274 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
275 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
276 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40277};
[email protected]93f72062013-05-29 20:29:40278#endif
[email protected]e461da2f2012-02-16 19:06:40279
[email protected]f8f93eb2012-09-25 03:06:24280// Returns a copy of the given url with its host set to given host and path set
281// to given path. Other parts of the url will be the same.
282GURL ReplaceURLHostAndPath(const GURL& url,
283 const std::string& host,
284 const std::string& path) {
285 url_canon::Replacements<char> replacements;
286 replacements.SetHost(host.c_str(),
287 url_parse::Component(0, host.length()));
288 replacements.SetPath(path.c_str(),
289 url_parse::Component(0, path.length()));
290 return url.ReplaceComponents(replacements);
291}
292
293// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
294GURL AddUberHost(const GURL& url) {
295 const std::string uber_host = chrome::kChromeUIUberHost;
296 const std::string new_path = url.host() + url.path();
297
298 return ReplaceURLHostAndPath(url, uber_host, new_path);
299}
300
[email protected]045bf7c2012-09-28 20:27:36301// If url->host() is "chrome" and url->path() has characters other than the
302// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
303// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24304bool RemoveUberHost(GURL* url) {
305 if (url->host() != chrome::kChromeUIUberHost)
306 return false;
307
[email protected]045bf7c2012-09-28 20:27:36308 if (url->path().empty() || url->path() == "/")
309 return false;
310
[email protected]f8f93eb2012-09-25 03:06:24311 const std::string old_path = url->path();
312
313 const std::string::size_type separator = old_path.find('/', 1);
314 std::string new_host;
315 std::string new_path;
316 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36317 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24318 } else {
319 new_host = old_path.substr(1, separator - 1);
320 new_path = old_path.substr(separator);
321 }
322
[email protected]44e8add2013-06-13 17:29:15323 // Do not allow URLs with paths empty before the first slash since we can't
324 // have an empty host. (e.g "foo://chrome//")
325 if (new_host.empty())
326 return false;
327
[email protected]f8f93eb2012-09-25 03:06:24328 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
329
[email protected]44e8add2013-06-13 17:29:15330 DCHECK(url->is_valid());
331
[email protected]f8f93eb2012-09-25 03:06:24332 return true;
333}
334
[email protected]b8148ac2011-07-13 22:03:25335// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42336bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24337 // Do not handle special URLs such as "about:foo"
338 if (!url->host().empty()) {
339 const GURL chrome_url = AddUberHost(*url);
340
341 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
342 // be called.
343 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
344 browser_context, chrome_url))
345 return true;
346 }
347
[email protected]863f70a2012-01-27 02:05:50348 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
349 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25350 return false;
351
[email protected]fe69558d2012-03-12 11:34:49352#if defined(OS_CHROMEOS)
353 // Special case : in ChromeOS in Guest mode bookmarks and history are
354 // disabled for security reasons. New tab page explains the reasons, so
355 // we redirect user to new tab page.
356 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
357 if (url->SchemeIs(chrome::kChromeUIScheme) &&
358 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
359 url->DomainIs(chrome::kChromeUIHistoryHost))) {
360 // Rewrite with new tab URL
361 *url = GURL(chrome::kChromeUINewTabURL);
362 }
363 }
364#endif
365
[email protected]b8148ac2011-07-13 22:03:25366 // Special case the new tab page. In older versions of Chrome, the new tab
367 // page was hosted at chrome-internal:<blah>. This might be in people's saved
368 // sessions or bookmarks, so we say any URL with that scheme triggers the new
369 // tab page.
370 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
371 // Rewrite it with the proper new tab URL.
372 *url = GURL(chrome::kChromeUINewTabURL);
373 }
374
375 return true;
376}
377
[email protected]f8f93eb2012-09-25 03:06:24378// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
379// "chrome://foo/".
380bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
381 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
382 return false;
383
384 return RemoveUberHost(url);
385}
386
[email protected]8d3132f62011-10-12 07:13:42387// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
388// below. Extension, and isolated apps require different privileges to be
389// granted to their RenderProcessHosts. This classification allows us to make
390// sure URLs are served by hosts with the right set of privileges.
391enum RenderProcessHostPrivilege {
392 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45393 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42394 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45395 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42396};
397
398RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
399 const GURL& url,
400 ExtensionService* service) {
401 // Default to a normal renderer cause it is lower privileged. This should only
402 // occur if the URL on a site instance is either malformed, or uninitialized.
403 // If it is malformed, then there is no need for better privileges anyways.
404 // If it is uninitialized, but eventually settles on being an a scheme other
405 // than normal webrenderer, the navigation logic will correct us out of band
406 // anyways.
407 if (!url.is_valid())
408 return PRIV_NORMAL;
409
[email protected]885c0e92012-11-13 20:27:42410 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44411 const Extension* extension =
412 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43413 if (extension &&
414 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42415 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45416 if (extension && extension->is_hosted_app())
417 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42418
419 return PRIV_EXTENSION;
420 }
421
422 return PRIV_NORMAL;
423}
424
425RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30426 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46427 extensions::ProcessMap* process_map,
428 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46429 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30430 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46431 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21432 return PRIV_NORMAL;
433
[email protected]6f371442011-11-09 06:45:46434 for (std::set<std::string>::iterator iter = extension_ids.begin();
435 iter != extension_ids.end(); ++iter) {
436 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43437 if (extension &&
438 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42439 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45440 if (extension && extension->is_hosted_app())
441 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42442 }
443
[email protected]676f6ab2011-10-19 20:23:21444 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42445}
446
[email protected]6786bf402011-12-03 15:19:45447bool CertMatchesFilter(const net::X509Certificate& cert,
448 const base::DictionaryValue& filter) {
449 // TODO(markusheintz): This is the minimal required filter implementation.
450 // Implement a better matcher.
451
452 // An empty filter matches any client certificate since no requirements are
453 // specified at all.
454 if (filter.empty())
455 return true;
456
457 std::string common_name;
458 if (filter.GetString("ISSUER.CN", &common_name) &&
459 (cert.issuer().common_name == common_name)) {
460 return true;
461 }
462 return false;
463}
464
[email protected]f3986f82012-01-03 20:00:06465// Fills |map| with the per-script font prefs under path |map_name|.
466void FillFontFamilyMap(const PrefService* prefs,
467 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53468 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06469 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
470 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
471 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
472 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23473 if (!font_family.empty())
474 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06475 }
476}
477
[email protected]a1733df2012-06-22 11:24:18478#if defined(OS_POSIX) && !defined(OS_MACOSX)
479int GetCrashSignalFD(const CommandLine& command_line) {
480 if (command_line.HasSwitch(switches::kExtensionProcess)) {
481 ExtensionCrashHandlerHostLinux* crash_handler =
482 ExtensionCrashHandlerHostLinux::GetInstance();
483 return crash_handler->GetDeathSignalSocket();
484 }
485
486 std::string process_type =
487 command_line.GetSwitchValueASCII(switches::kProcessType);
488
489 if (process_type == switches::kRendererProcess)
490 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
491
492 if (process_type == switches::kPluginProcess)
493 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
494
495 if (process_type == switches::kPpapiPluginProcess)
496 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
497
498 if (process_type == switches::kGpuProcess)
499 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
500
501 return -1;
502}
503#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
504
[email protected]d5bcd06f2013-04-21 08:07:24505#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30506GURL GetEffectiveURLForSignin(const GURL& url) {
507 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
508
509 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03510 // Copy the path because the argument to SetPathStr must outlive
511 // the Replacements object.
512 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30513 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03514 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30515 effective_url = effective_url.ReplaceComponents(replacements);
516 return effective_url;
517}
[email protected]d5bcd06f2013-04-21 08:07:24518#endif
[email protected]970c63e2013-03-07 00:25:30519
[email protected]eabbfb12013-04-05 23:28:35520void SetApplicationLocaleOnIOThread(const std::string& locale) {
521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
522 g_io_thread_application_locale.Get() = locale;
523}
524
[email protected]190e5e22013-07-27 05:59:23525#if !defined(OS_ANDROID)
526struct BlockedPopupParams {
527 BlockedPopupParams(const GURL& target_url,
528 const content::Referrer& referrer,
529 WindowOpenDisposition disposition,
530 const WebWindowFeatures& features,
531 bool user_gesture,
532 bool opener_suppressed,
533 int render_process_id,
534 int opener_id)
535 : target_url(target_url),
536 referrer(referrer),
537 disposition(disposition),
538 features(features),
539 user_gesture(user_gesture),
540 opener_suppressed(opener_suppressed),
541 render_process_id(render_process_id),
542 opener_id(opener_id)
543 {}
544
545 GURL target_url;
546 content::Referrer referrer;
547 WindowOpenDisposition disposition;
548 WebWindowFeatures features;
549 bool user_gesture;
550 bool opener_suppressed;
551 int render_process_id;
552 int opener_id;
553};
554
555void HandleBlockedPopupOnUIThread(const BlockedPopupParams& params) {
556 WebContents* tab =
557 tab_util::GetWebContentsByID(params.render_process_id, params.opener_id);
558 if (!tab)
559 return;
560
561 prerender::PrerenderManager* prerender_manager =
562 prerender::PrerenderManagerFactory::GetForProfile(
563 Profile::FromBrowserContext(tab->GetBrowserContext()));
564 prerender_manager->DestroyPrerenderForRenderView(
565 params.render_process_id,
566 params.opener_id,
567 prerender::FINAL_STATUS_CREATE_NEW_WINDOW);
568
569 PopupBlockerTabHelper* popup_helper =
570 PopupBlockerTabHelper::FromWebContents(tab);
571 if (!popup_helper)
572 return;
573 popup_helper->AddBlockedPopup(params.target_url,
574 params.referrer,
575 params.disposition,
576 params.features,
577 params.user_gesture,
578 params.opener_suppressed);
579}
580#endif
581
[email protected]9dbfff12011-07-01 19:37:07582} // namespace
[email protected]c5dbef02011-05-13 05:06:09583
[email protected]d977f9c2011-03-14 16:10:26584namespace chrome {
585
[email protected]e461da2f2012-02-16 19:06:40586ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40587#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40588 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
589 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40590#endif
[email protected]1deace22013-05-22 06:14:46591
592 permissions_policy_delegate_.reset(
593 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40594}
595
596ChromeContentBrowserClient::~ChromeContentBrowserClient() {
597}
598
[email protected]bca18382012-06-25 19:15:23599// static
[email protected]37ca3fe02013-07-05 15:32:44600void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34601 user_prefs::PrefRegistrySyncable* registry) {
602 registry->RegisterBooleanPref(
603 prefs::kDisable3DAPIs,
604 false,
605 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
606 registry->RegisterBooleanPref(
607 prefs::kEnableHyperlinkAuditing,
608 true,
609 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
610 registry->RegisterBooleanPref(
611 prefs::kEnableMemoryInfo,
612 false,
613 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23614}
615
[email protected]eabbfb12013-04-05 23:28:35616// static
617void ChromeContentBrowserClient::SetApplicationLocale(
618 const std::string& locale) {
619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
620
621 // This object is guaranteed to outlive all threads so we don't have to
622 // worry about the lack of refcounting and can just post as Unretained.
623 //
624 // The common case is that this function is called early in Chrome startup
625 // before any threads are created (it will also be called later if the user
626 // changes the pref). In this case, there will be no threads created and
627 // posting will fail. When there are no threads, we can just set the string
628 // without worrying about threadsafety.
629 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
630 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
631 g_io_thread_application_locale.Get() = locale;
632 }
633}
634
[email protected]50462bf02011-11-21 19:13:31635content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
636 const content::MainFunctionParams& parameters) {
637 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30638 // Construct the Main browser parts based on the OS type.
639#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31640 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04641#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31642 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30643#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22644 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26645#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31646 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14647#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09648 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30649#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31650 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04651#else
[email protected]b48c9182011-10-26 18:03:30652 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31653 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30654#endif
655
[email protected]7e75e4a2013-05-17 17:20:03656 chrome::AddProfilesExtraParts(main_parts);
657
[email protected]c7480942011-11-08 19:18:27658 // Construct additional browser parts. Stages are called in the order in
659 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22660#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51661 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04662#endif
[email protected]c7480942011-11-08 19:18:27663
664#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51665 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27666#endif
667
[email protected]dc04be7c2012-03-15 23:57:49668#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51669 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49670#endif
671
[email protected]e050ef142012-03-21 01:04:24672#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51673 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
674#endif
675
676#if defined(USE_X11)
677 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24678#endif
679
[email protected]95132f52013-04-12 02:19:04680 chrome::AddMetricsExtraParts(main_parts);
681
[email protected]50462bf02011-11-21 19:13:31682 return main_parts;
[email protected]f967b722011-09-07 00:58:04683}
684
[email protected]e94bbcb2012-09-07 05:33:57685std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19686 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57687 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53688 std::string partition_id;
689
690 // The partition ID for webview guest processes is the string value of its
691 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
692 if (site.SchemeIs(chrome::kGuestScheme))
693 partition_id = site.spec();
694
[email protected]056efdc2013-04-06 00:14:53695 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53696 return partition_id;
697}
698
699bool ChromeContentBrowserClient::IsValidStoragePartitionId(
700 content::BrowserContext* browser_context,
701 const std::string& partition_id) {
702 // The default ID is empty and is always valid.
703 if (partition_id.empty())
704 return true;
705
706 return GURL(partition_id).is_valid();
707}
708
709void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
710 content::BrowserContext* browser_context,
711 const GURL& site,
[email protected]14acc642012-11-17 12:20:10712 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53713 std::string* partition_domain,
714 std::string* partition_name,
715 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10716 // Default to the browser-wide storage partition and override based on |site|
717 // below.
718 partition_domain->clear();
719 partition_name->clear();
720 *in_memory = false;
721
[email protected]1bc28312012-11-08 08:31:53722 // For the webview tag, we create special guest processes, which host the
723 // tag content separately from the main application that embeds the tag.
724 // A webview tag can specify both the partition name and whether the storage
725 // for that partition should be persisted. Each tag gets a SiteInstance with
726 // a specially formatted URL, based on the application it is hosted by and
727 // the partition requested by it. The format for that URL is:
728 // chrome-guest://partition_domain/persist?partition_name
729 if (site.SchemeIs(chrome::kGuestScheme)) {
730 // Since guest URLs are only used for packaged apps, there must be an app
731 // id in the URL.
732 CHECK(site.has_host());
733 *partition_domain = site.host();
734 // Since persistence is optional, the path must either be empty or the
735 // literal string.
736 *in_memory = (site.path() != "/persist");
737 // The partition name is user supplied value, which we have encoded when the
738 // URL was created, so it needs to be decoded.
739 *partition_name = net::UnescapeURLComponent(site.query(),
740 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10741 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
742 // If |can_be_default| is false, the caller is stating that the |site|
743 // should be parsed as if it had isolated storage. In particular it is
744 // important to NOT check ExtensionService for the is_storage_isolated()
745 // attribute because this code path is run during Extension uninstall
746 // to do cleanup after the Extension has already been unloaded from the
747 // ExtensionService.
748 bool is_isolated = !can_be_default;
749 if (can_be_default) {
750 const Extension* extension = NULL;
751 Profile* profile = Profile::FromBrowserContext(browser_context);
752 ExtensionService* extension_service =
753 extensions::ExtensionSystem::Get(profile)->extension_service();
754 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55755 extension =
756 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43757 if (extension &&
758 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10759 is_isolated = true;
760 }
761 }
762 }
[email protected]1bc28312012-11-08 08:31:53763
[email protected]14acc642012-11-17 12:20:10764 if (is_isolated) {
765 CHECK(site.has_host());
766 // For extensions with isolated storage, the the host of the |site| is
767 // the |partition_domain|. The |in_memory| and |partition_name| are only
768 // used in guest schemes so they are cleared here.
769 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53770 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10771 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53772 }
[email protected]d1198fd2012-08-13 22:50:19773 }
774
[email protected]14acc642012-11-17 12:20:10775 // Assert that if |can_be_default| is false, the code above must have found a
776 // non-default partition. If this fails, the caller has a serious logic
777 // error about which StoragePartition they expect to be in and it is not
778 // safe to continue.
779 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44780}
781
[email protected]38b098f2012-03-14 21:11:57782content::WebContentsViewDelegate*
783 ChromeContentBrowserClient::GetWebContentsViewDelegate(
784 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27785 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32786}
787
[email protected]24665682013-02-25 20:59:38788// Check if the extension activity log is enabled for the profile.
789static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33790 // crbug.com/247908 - This should be IsLogEnabled except for an issue
791 // in chrome_frame_net_tests
792 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38793}
794
[email protected]738f57a2013-06-29 21:06:54795void ChromeContentBrowserClient::GuestWebContentsCreated(
796 WebContents* guest_web_contents,
797 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22798 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54799 scoped_ptr<base::DictionaryValue> extra_params) {
800 if (opener_web_contents) {
801 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
802 if (!guest) {
803 NOTREACHED();
804 return;
805 }
806
807 switch (guest->GetViewType()) {
808 case GuestView::WEBVIEW: {
[email protected]4c0e8272013-07-03 23:39:22809 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54810 break;
811 }
812 case GuestView::ADVIEW: {
[email protected]4c0e8272013-07-03 23:39:22813 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54814 break;
815 }
816 default:
817 NOTREACHED();
818 break;
819 }
820 return;
821 }
822
823 if (!extra_params) {
824 NOTREACHED();
825 return;
826 }
827 std::string api_type;
828 extra_params->GetString(guestview::kAttributeApi, &api_type);
829
830 if (api_type == "adview") {
[email protected]4c0e8272013-07-03 23:39:22831 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54832 } else if (api_type == "webview") {
[email protected]4c0e8272013-07-03 23:39:22833 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54834 } else {
835 NOTREACHED();
836 }
837}
838
[email protected]44295a12013-06-05 08:45:46839void ChromeContentBrowserClient::GuestWebContentsAttached(
840 WebContents* guest_web_contents,
841 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53842 int browser_plugin_instance_id,
843 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06844 Profile* profile = Profile::FromBrowserContext(
845 embedder_web_contents->GetBrowserContext());
846 ExtensionService* service =
847 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54848 if (!service) {
849 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06850 return;
[email protected]738f57a2013-06-29 21:06:54851 }
[email protected]44703cc72013-01-24 04:56:06852 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
[email protected]be9915fb2013-07-18 09:28:55853 const Extension* extension =
854 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]738f57a2013-06-29 21:06:54855 if (!extension) {
[email protected]18699372013-06-25 20:42:55856 NOTREACHED();
[email protected]738f57a2013-06-29 21:06:54857 return;
[email protected]18699372013-06-25 20:42:55858 }
[email protected]738f57a2013-06-29 21:06:54859
860 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
861 if (!guest) {
862 NOTREACHED();
863 return;
864 }
865 guest->Attach(embedder_web_contents,
866 extension->id(),
867 browser_plugin_instance_id,
868 extra_params);
[email protected]44703cc72013-01-24 04:56:06869}
870
[email protected]f3b1a082011-11-18 00:34:30871void ChromeContentBrowserClient::RenderProcessHostCreated(
872 content::RenderProcessHost* host) {
873 int id = host->GetID();
874 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41875 net::URLRequestContextGetter* context =
876 profile->GetRequestContextForRenderProcess(id);
877
[email protected]f3b1a082011-11-18 00:34:30878 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41879 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55880#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30881 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55882#endif
[email protected]658677f2012-06-09 06:04:02883#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08884 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03885#endif
[email protected]f3b1a082011-11-18 00:34:30886 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02887 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30888 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56889#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21890 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56891#endif
[email protected]43535512013-02-20 20:41:41892 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
893 id, profile, context));
[email protected]2736c032012-05-11 18:06:07894 host->GetChannel()->AddFilter(
895 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27896 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33897 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31898#if defined(ENABLE_WEBRTC)
899 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
900#endif
[email protected]01e59752013-06-18 00:17:35901#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03902 ExtensionInfoMap* extension_info_map =
903 extensions::ExtensionSystem::Get(profile)->info_map();
904 host->GetChannel()->AddFilter(new NaClHostMessageFilter(
905 id, profile->IsOffTheRecord(),
906 profile->GetPath(), extension_info_map,
907 context));
[email protected]01e59752013-06-18 00:17:35908#endif
[email protected]3e69bc82011-05-26 23:22:38909
[email protected]2ccf45c2011-08-19 23:35:50910 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
911 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07912
[email protected]24665682013-02-25 20:59:38913 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
914 IsExtensionActivityLogEnabledForProfile(profile)));
915
[email protected]39a5b532011-10-22 01:47:07916 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56917
918 RendererContentSettingRules rules;
919 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
920 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14921}
922
[email protected]95c95552013-05-03 04:21:22923GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
924 content::BrowserContext* browser_context,
925 const GURL& url,
926 bool is_renderer_initiated,
927 content::SiteInstance* current_instance) {
928 Profile* profile = Profile::FromBrowserContext(browser_context);
929 if (!profile)
930 return url;
931
932 // Only return the privileged instant URL if we are entering from a browser-
933 // initiated navigation or if we are already in the instant process.
934 bool is_instant_process = false;
935 int process_id = current_instance->GetProcess()->GetID();
936 InstantService* instant_service =
937 InstantServiceFactory::GetForProfile(profile);
938 if (instant_service)
939 is_instant_process = instant_service->IsInstantProcess(process_id);
940
941 DCHECK_EQ(is_instant_process,
942 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
943 if (!is_renderer_initiated || is_instant_process) {
944 // If the input |url| should be assigned to the Instant renderer, make its
945 // privileged URL distinct from other URLs on the search provider's domain.
946 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
947 return chrome::GetPrivilegedURLForInstant(url, profile);
948 }
949
950 return url;
951}
952
[email protected]3d7474ff2011-07-27 17:47:37953GURL ChromeContentBrowserClient::GetEffectiveURL(
954 content::BrowserContext* browser_context, const GURL& url) {
955 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52956 if (!profile)
957 return url;
958
[email protected]d5bcd06f2013-04-21 08:07:24959#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30960 // If the input |url| should be assigned to the Signin renderer, make its
961 // effective URL distinct from other URLs on the signin service's domain.
962 // Note that the signin renderer will be allowed to sign the user in to
963 // Chrome.
964 if (SigninManager::IsWebBasedSigninFlowURL(url))
965 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24966#endif
[email protected]970c63e2013-03-07 00:25:30967
[email protected]c5dec6292013-01-25 04:54:52968 // If the input |url| is part of an installed app, the effective URL is an
969 // extension URL with the ID of that extension as the host. This has the
970 // effect of grouping apps together in a common SiteInstance.
971 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13972 extensions::ExtensionSystem::Get(profile)->extension_service();
973 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08974 return url;
975
[email protected]06bdd2b2012-11-30 18:47:13976 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55977 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08978 if (!extension)
979 return url;
980
[email protected]15877ca2011-11-18 22:40:52981 // Bookmark apps do not use the hosted app process model, and should be
982 // treated as normal URLs.
983 if (extension->from_bookmark())
984 return url;
985
[email protected]36fb2c7c2011-04-04 15:49:08986 // If the URL is part of an extension's web extent, convert it to an
987 // extension URL.
988 return extension->GetResourceURL(url.path());
989}
990
[email protected]056ad2a2011-07-12 02:13:55991bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37992 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52993 // Non-extension, non-Instant URLs should generally use
994 // process-per-site-instance. Because we expect to use the effective URL,
995 // URLs for hosted apps (apart from bookmark apps) should have an extension
996 // scheme by now.
997
998 Profile* profile = Profile::FromBrowserContext(browser_context);
999 if (!profile)
1000 return false;
1001
[email protected]df113a12013-07-24 04:56:081002 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:521003 return true;
1004
[email protected]d5bcd06f2013-04-21 08:07:241005#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301006 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
1007 return true;
[email protected]d5bcd06f2013-04-21 08:07:241008#endif
[email protected]970c63e2013-03-07 00:25:301009
[email protected]885c0e92012-11-13 20:27:421010 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:551011 return false;
1012
[email protected]c5dec6292013-01-25 04:54:521013 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:131014 extensions::ExtensionSystem::Get(profile)->extension_service();
1015 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:551016 return false;
1017
[email protected]be9915fb2013-07-18 09:28:551018 const Extension* extension =
1019 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:551020 if (!extension)
1021 return false;
1022
1023 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:531024 // permission, or that does not allow JavaScript access to the background
1025 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:551026 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:401027 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:061028 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:291029 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:531030 return false;
1031 }
1032 }
[email protected]056ad2a2011-07-12 02:13:551033
[email protected]7b54ca02012-03-02 18:06:531034 // Hosted apps that have script access to their background page must use
1035 // process per site, since all instances can make synchronous calls to the
1036 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:551037 return true;
1038}
1039
[email protected]672c8c12013-03-07 12:30:061040// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:411041void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
1042 std::vector<std::string>* additional_schemes) {
1043 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:061044}
1045
[email protected]6bd30072013-02-08 18:17:111046net::URLRequestContextGetter*
1047ChromeContentBrowserClient::CreateRequestContext(
1048 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:061049 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111050 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:061051 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111052}
1053
1054net::URLRequestContextGetter*
1055ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1056 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:401057 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:111058 bool in_memory,
[email protected]672c8c12013-03-07 12:30:061059 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111060 Profile* profile = Profile::FromBrowserContext(browser_context);
1061 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:061062 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111063}
1064
[email protected]46fb9442011-12-09 17:57:471065bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1066 return ProfileIOData::IsHandledURL(url);
1067}
1068
[email protected]c4365fa42013-05-14 01:08:241069bool ChromeContentBrowserClient::CanCommitURL(
1070 content::RenderProcessHost* process_host,
1071 const GURL& url) {
1072 // We need to let most extension URLs commit in any process, since this can
1073 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1074 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1075 // cannot be loaded in iframes and should never be requested outside its
1076 // process.
1077 Profile* profile =
1078 Profile::FromBrowserContext(process_host->GetBrowserContext());
1079 ExtensionService* service =
1080 extensions::ExtensionSystem::Get(profile)->extension_service();
1081 if (!service)
1082 return true;
1083 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551084 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241085 if (new_extension &&
1086 new_extension->is_hosted_app() &&
1087 new_extension->id() == extension_misc::kWebStoreAppId &&
1088 !service->process_map()->Contains(new_extension->id(),
1089 process_host->GetID())) {
1090 return false;
1091 }
1092
1093 return true;
1094}
1095
[email protected]2a5221b2011-09-27 23:07:311096bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301097 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311098 const GURL& site_url) {
1099 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301100 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521101 // This may be NULL during tests. In that case, just assume any site can
1102 // share any host.
1103 if (!profile)
1104 return true;
1105
[email protected]d43f99fe2013-04-03 00:20:141106 // Instant URLs should only be in the instant process and instant process
1107 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521108 InstantService* instant_service =
1109 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141110 if (instant_service) {
1111 bool is_instant_process = instant_service->IsInstantProcess(
1112 process_host->GetID());
1113 bool should_be_in_instant_process =
1114 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1115 if (is_instant_process || should_be_in_instant_process)
1116 return is_instant_process && should_be_in_instant_process;
1117 }
[email protected]c5dec6292013-01-25 04:54:521118
[email protected]d5bcd06f2013-04-21 08:07:241119#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301120 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1121 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1122 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241123#endif
[email protected]970c63e2013-03-07 00:25:301124
[email protected]06bdd2b2012-11-30 18:47:131125 ExtensionService* service =
1126 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461127 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311128
[email protected]ffa97602011-11-17 17:55:521129 // Don't allow the Task Manager to share a process with anything else.
1130 // Otherwise it can affect the renderers it is observing.
1131 // Note: we could create another RenderProcessHostPrivilege bucket for
1132 // this to allow multiple chrome://tasks instances to share, but that's
1133 // a very unlikely case without serious consequences.
1134 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1135 return false;
1136
[email protected]8d3132f62011-10-12 07:13:421137 // These may be NULL during tests. In that case, just assume any site can
1138 // share any host.
[email protected]6f371442011-11-09 06:45:461139 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311140 return true;
1141
[email protected]eec0b33c2011-12-05 22:09:451142 // Otherwise, just make sure the process privilege matches the privilege
1143 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571144 RenderProcessHostPrivilege privilege_required =
1145 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451146 return GetProcessPrivilege(process_host, process_map, service) ==
1147 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311148}
1149
[email protected]76411f412012-02-22 18:56:061150// This function is trying to limit the amount of processes used by extensions
1151// with background pages. It uses a globally set percentage of processes to
1152// run such extensions and if the limit is exceeded, it returns true, to
1153// indicate to the content module to group extensions together.
1154bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1155 content::BrowserContext* browser_context, const GURL& url) {
1156 // It has to be a valid URL for us to check for an extension.
1157 if (!url.is_valid())
1158 return false;
1159
1160 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191161 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131162 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061163 if (!service)
1164 return false;
1165
1166 // We have to have a valid extension with background page to proceed.
1167 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551168 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061169 if (!extension)
1170 return false;
[email protected]9367eabc2013-03-01 01:29:291171 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061172 return false;
1173
1174 std::set<int> process_ids;
1175 size_t max_process_count =
1176 content::RenderProcessHost::GetMaxRendererProcessCount();
1177
1178 // Go through all profiles to ensure we have total count of extension
1179 // processes containing background pages, otherwise one profile can
1180 // starve the other.
1181 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1182 GetLoadedProfiles();
1183 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031184 ExtensionProcessManager* epm =
1185 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321186 for (ExtensionProcessManager::const_iterator iter =
1187 epm->background_hosts().begin();
1188 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131189 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321190 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061191 }
1192 }
1193
1194 if (process_ids.size() >
1195 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1196 return true;
1197 }
1198
1199 return false;
1200}
1201
[email protected]6f371442011-11-09 06:45:461202void ChromeContentBrowserClient::SiteInstanceGotProcess(
1203 SiteInstance* site_instance) {
1204 CHECK(site_instance->HasProcess());
1205
1206 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021207 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521208 if (!profile)
1209 return;
1210
1211 // Remember the ID of the Instant process to signal the renderer process
1212 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031213 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321214 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521215 InstantService* instant_service =
1216 InstantServiceFactory::GetForProfile(profile);
1217 if (instant_service)
1218 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1219 }
1220
[email protected]d5bcd06f2013-04-21 08:07:241221#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301222 // We only expect there to be one signin process as we use process-per-site
1223 // for signin URLs. The signin process will be cleared from SigninManager
1224 // when the renderer is destroyed.
1225 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1226 SigninManager* signin_manager =
1227 SigninManagerFactory::GetForProfile(profile);
1228 if (signin_manager)
1229 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461230 BrowserThread::PostTask(
1231 BrowserThread::IO, FROM_HERE,
1232 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1233 extensions::ExtensionSystem::Get(profile)->info_map(),
1234 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301235 }
[email protected]d5bcd06f2013-04-21 08:07:241236#endif
[email protected]970c63e2013-03-07 00:25:301237
[email protected]06bdd2b2012-11-30 18:47:131238 ExtensionService* service =
1239 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461240 if (!service)
1241 return;
1242
[email protected]be9915fb2013-07-18 09:28:551243 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1244 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461245 if (!extension)
1246 return;
1247
[email protected]6bc04fd82011-12-04 02:29:351248 service->process_map()->Insert(extension->id(),
1249 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331250 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461251 BrowserThread::PostTask(
1252 BrowserThread::IO, FROM_HERE,
1253 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591254 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461255 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351256 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331257 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461258}
1259
1260void ChromeContentBrowserClient::SiteInstanceDeleting(
1261 SiteInstance* site_instance) {
1262 if (!site_instance->HasProcess())
1263 return;
1264
1265 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021266 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131267 ExtensionService* service =
1268 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461269 if (!service)
1270 return;
1271
[email protected]be9915fb2013-07-18 09:28:551272 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1273 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461274 if (!extension)
1275 return;
1276
[email protected]6bc04fd82011-12-04 02:29:351277 service->process_map()->Remove(extension->id(),
1278 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331279 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461280 BrowserThread::PostTask(
1281 BrowserThread::IO, FROM_HERE,
1282 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591283 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461284 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351285 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331286 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461287}
1288
[email protected]f05763972012-06-06 18:17:261289bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141290 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081291 const GURL& current_url,
1292 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261293 if (current_url.is_empty()) {
1294 // Always choose a new process when navigating to extension URLs. The
1295 // process grouping logic will combine all of a given extension's pages
1296 // into the same process.
[email protected]885c0e92012-11-13 20:27:421297 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261298 return true;
[email protected]e3daf3c2011-10-05 21:17:081299
[email protected]f05763972012-06-06 18:17:261300 return false;
1301 }
1302
1303 // Also, we must switch if one is an extension and the other is not the exact
1304 // same extension.
[email protected]885c0e92012-11-13 20:27:421305 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1306 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261307 if (current_url.GetOrigin() != new_url.GetOrigin())
1308 return true;
1309 }
1310
[email protected]e9841fbd2013-02-22 23:12:141311 // The checks below only matter if we can retrieve which extensions are
1312 // installed.
1313 Profile* profile =
1314 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1315 ExtensionService* service =
1316 extensions::ExtensionSystem::Get(profile)->extension_service();
1317 if (!service)
1318 return false;
1319
1320 // We must swap if the URL is for an extension and we are not using an
1321 // extension process.
1322 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551323 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141324 // Ignore all hosted apps except the Chrome Web Store, since they do not
1325 // require their own BrowsingInstance (e.g., postMessage is ok).
1326 if (new_extension &&
1327 new_extension->is_hosted_app() &&
1328 new_extension->id() != extension_misc::kWebStoreAppId)
1329 new_extension = NULL;
1330 if (new_extension &&
1331 site_instance->HasProcess() &&
1332 !service->process_map()->Contains(new_extension->id(),
1333 site_instance->GetProcess()->GetID()))
1334 return true;
1335
[email protected]f05763972012-06-06 18:17:261336 return false;
[email protected]e3daf3c2011-10-05 21:17:081337}
1338
[email protected]395045c2012-05-22 15:04:381339bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1340 content::ResourceContext* resource_context, const GURL& current_url,
1341 const GURL& new_url) {
1342 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1343 return extensions::CrossesExtensionProcessBoundary(
1344 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551345 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381346}
1347
[email protected]3d831992013-07-04 01:13:291348bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1349 return !url.SchemeIs(chrome::kChromeNativeScheme);
1350}
1351
[email protected]763ec4ca2011-04-29 15:48:121352std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1353 const std::string& alias_name) {
1354 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1355}
1356
[email protected]b80f68432011-05-02 17:22:301357void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1358 CommandLine* command_line, int child_process_id) {
[email protected]97425082013-07-16 03:10:071359#if defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301360 if (IsCrashReporterEnabled()) {
1361 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1362 child_process_logging::GetClientId());
1363 }
[email protected]97425082013-07-16 03:10:071364#elif defined(OS_POSIX)
1365 if (IsCrashReporterEnabled()) {
1366 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1367 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1368 }
1369
[email protected]b80f68432011-05-02 17:22:301370#endif // OS_MACOSX
1371
[email protected]f1933792011-06-14 00:49:341372 if (logging::DialogsAreSuppressed())
1373 command_line->AppendSwitch(switches::kNoErrorDialogs);
1374
[email protected]b80f68432011-05-02 17:22:301375 std::string process_type =
1376 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171377 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321378
1379 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1380 command_line->AppendSwitch(switches::kChromeFrame);
1381
[email protected]718eab62011-10-05 21:16:521382 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451383 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301384 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1385 if (!user_data_dir.empty())
1386 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1387#if defined(OS_CHROMEOS)
1388 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441389 browser_command_line.GetSwitchValueASCII(
1390 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301391 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441392 command_line->AppendSwitchASCII(
1393 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301394#endif
1395
[email protected]f3b1a082011-11-18 00:34:301396 content::RenderProcessHost* process =
1397 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371398 if (process) {
1399 Profile* profile = Profile::FromBrowserContext(
1400 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131401 ExtensionService* extension_service =
1402 extensions::ExtensionSystem::Get(profile)->extension_service();
1403 if (extension_service) {
1404 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001405 if (process_map && process_map->Contains(process->GetID()))
1406 command_line->AppendSwitch(switches::kExtensionProcess);
1407 }
[email protected]b80f68432011-05-02 17:22:301408
[email protected]a8d851f82011-12-21 00:32:371409 PrefService* prefs = profile->GetPrefs();
1410 // Currently this pref is only registered if applied via a policy.
1411 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1412 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1413 // Turn this policy into a command line switch.
1414 command_line->AppendSwitch(switches::kDisable3DAPIs);
1415 }
[email protected]718eab62011-10-05 21:16:521416
[email protected]a8d851f82011-12-21 00:32:371417 // Disable client-side phishing detection in the renderer if it is
1418 // disabled in the Profile preferences or the browser process.
1419 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1420 !g_browser_process->safe_browsing_detection_service()) {
1421 command_line->AppendSwitch(
1422 switches::kDisableClientSidePhishingDetection);
1423 }
[email protected]0045b0f42012-07-26 11:52:081424
1425 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211426 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521427
1428 InstantService* instant_service =
1429 InstantServiceFactory::GetForProfile(profile);
1430 if (instant_service &&
1431 instant_service->IsInstantProcess(process->GetID()))
1432 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301433
[email protected]d5bcd06f2013-04-21 08:07:241434#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301435 SigninManager* signin_manager =
1436 SigninManagerFactory::GetForProfile(profile);
1437 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1438 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241439#endif
[email protected]47c7ec82012-01-18 03:29:211440 }
[email protected]4287a3d2011-06-13 23:56:511441
[email protected]87552982012-11-02 17:21:401442 if (content::IsThreadedCompositingEnabled())
1443 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1444
[email protected]16dc42452013-04-09 04:37:191445 if (message_center::IsRichNotificationEnabled())
1446 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191447
[email protected]47c7ec82012-01-18 03:29:211448 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511449 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171450 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481451 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171452 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]49d9b142013-07-19 08:50:271453 extensions::switches::kAllowLegacyExtensionManifests,
1454 extensions::switches::kAllowScriptingGallery,
1455 extensions::switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511456 switches::kAllowHTTPBackgroundPage,
[email protected]9d450492013-06-13 23:08:371457 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1458 // to browser.
1459 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511460 switches::kAppsCheckoutURL,
1461 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311462 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511463 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501464 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531465 switches::kDisableExtensionsResourceWhitelist,
[email protected]df4015352013-07-26 23:18:181466 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111467 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531468 switches::kEnableAdview,
1469 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441470 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211471 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511472 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511473 switches::kEnableIPCFuzzing,
1474 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451475 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481476 switches::kEnablePasswordGeneration,
[email protected]4287a3d2011-06-13 23:56:511477 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511478 switches::kMemoryProfiling,
1479 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371480 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371481 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511482 switches::kPpapiFlashArgs,
1483 switches::kPpapiFlashInProcess,
1484 switches::kPpapiFlashPath,
1485 switches::kPpapiFlashVersion,
1486 switches::kProfilingAtStart,
1487 switches::kProfilingFile,
1488 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371489 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511490 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291491 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381492 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511493 };
1494
1495 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1496 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171497 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381498 static const char* const kSwitchNames[] = {
[email protected]49d9b142013-07-19 08:50:271499 extensions::switches::kExtensionsOnChromeURLs,
[email protected]eb653f82012-05-24 02:31:351500 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381501 switches::kEnableExperimentalExtensionApis,
1502 switches::kWhitelistedExtensionID,
1503 };
1504
1505 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1506 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511507 } else if (process_type == switches::kPluginProcess) {
1508 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441509#if defined(OS_CHROMEOS)
1510 chromeos::switches::kLoginProfile,
1511#endif
[email protected]4287a3d2011-06-13 23:56:511512 switches::kMemoryProfiling,
1513 switches::kSilentDumpOnDCHECK,
1514 switches::kUserDataDir,
1515 };
1516
1517 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1518 arraysize(kSwitchNames));
1519 } else if (process_type == switches::kZygoteProcess) {
1520 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511521 switches::kUserDataDir, // Make logs go to the right file.
1522 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501523 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511524 switches::kPpapiFlashInProcess,
1525 switches::kPpapiFlashPath,
1526 switches::kPpapiFlashVersion,
1527 };
1528
1529 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1530 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111531 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001532 base::FilePath user_data_dir =
1533 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1534 if (!user_data_dir.empty())
1535 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111536 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1537 // because GPU is expected to be unreliable.
1538 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1539 !command_line->HasSwitch(switches::kDisableBreakpad))
1540 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301541 }
[email protected]6f08af82011-09-15 01:19:031542
1543 // The command line switch kEnableBenchmarking needs to be specified along
1544 // with the kEnableStatsTable switch to ensure that the stats table global
1545 // is initialized correctly.
1546 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1547 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301548}
1549
1550std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431551 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351552 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301553 return g_browser_process->GetApplicationLocale();
1554}
1555
[email protected]597a867b2011-11-18 18:31:201556std::string ChromeContentBrowserClient::GetAcceptLangs(
1557 content::BrowserContext* context) {
1558 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371559 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081560}
1561
[email protected]9ec0f452012-05-31 15:58:531562gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221563 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531564 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081565}
1566
[email protected]a2176792011-05-08 19:30:491567bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091568 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191569 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201570 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201572 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051573 return io_data->GetCookieSettings()->
1574 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491575}
1576
[email protected]ed24fad2011-05-10 22:44:011577bool ChromeContentBrowserClient::AllowGetCookie(
1578 const GURL& url,
1579 const GURL& first_party,
1580 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201581 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011582 int render_process_id,
1583 int render_view_id) {
1584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201585 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051586 bool allow = io_data->GetCookieSettings()->
1587 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011588
[email protected]8093a542011-05-13 07:29:321589 BrowserThread::PostTask(
1590 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031591 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431592 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011593 return allow;
1594}
1595
1596bool ChromeContentBrowserClient::AllowSetCookie(
1597 const GURL& url,
1598 const GURL& first_party,
1599 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201600 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011601 int render_process_id,
1602 int render_view_id,
1603 net::CookieOptions* options) {
1604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201605 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051606 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1607 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1608
[email protected]8093a542011-05-13 07:29:321609 BrowserThread::PostTask(
1610 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031611 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431612 render_view_id, url, first_party, cookie_line, *options,
1613 !allow));
[email protected]ed24fad2011-05-10 22:44:011614 return allow;
1615}
1616
[email protected]d5a19162011-06-30 18:51:541617bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201618 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201620 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431621 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1622 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261623
[email protected]bf510ed2012-06-05 08:31:431624 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1625 // Could we even support per-origin settings?
1626 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541627}
1628
[email protected]5c5a88e2011-11-12 00:45:351629bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351630 const GURL& url,
1631 const string16& name,
1632 const string16& display_name,
1633 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201634 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481635 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201637 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351638 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1639 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1640
[email protected]62151052012-02-01 18:40:481641 // Record access to database for potential display in UI.
1642 std::vector<std::pair<int, int> >::const_iterator i;
1643 for (i = render_views.begin(); i != render_views.end(); ++i) {
1644 BrowserThread::PostTask(
1645 BrowserThread::UI, FROM_HERE,
1646 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1647 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351648 }
1649
1650 return allow;
1651}
1652
1653bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351654 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201655 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481656 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201658 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351659 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1660 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1661
[email protected]62151052012-02-01 18:40:481662 // Record access to file system for potential display in UI.
1663 std::vector<std::pair<int, int> >::const_iterator i;
1664 for (i = render_views.begin(); i != render_views.end(); ++i) {
1665 BrowserThread::PostTask(
1666 BrowserThread::UI, FROM_HERE,
1667 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1668 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351669 }
1670
1671 return allow;
1672}
1673
[email protected]7c5ff9a2012-03-02 07:42:491674bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1675 const GURL& url,
1676 const string16& name,
1677 content::ResourceContext* context,
1678 const std::vector<std::pair<int, int> >& render_views) {
1679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1680 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1681 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1682 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1683
1684 // Record access to IndexedDB for potential display in UI.
1685 std::vector<std::pair<int, int> >::const_iterator i;
1686 for (i = render_views.begin(); i != render_views.end(); ++i) {
1687 BrowserThread::PostTask(
1688 BrowserThread::UI, FROM_HERE,
1689 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1690 i->first, i->second, url, name, !allow));
1691 }
1692
1693 return allow;
1694}
1695
[email protected]6133f922011-07-01 21:34:341696net::URLRequestContext*
1697ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201698 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421700 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201701 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341702 return io_data->extensions_request_context();
1703 }
1704
1705 return NULL;
1706}
1707
[email protected]317f96c92011-05-31 06:53:411708QuotaPermissionContext*
1709ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1710 return new ChromeQuotaPermissionContext();
1711}
1712
[email protected]848dd042011-06-04 18:24:031713void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171714 int render_process_id,
1715 int render_view_id,
1716 int cert_error,
1717 const net::SSLInfo& ssl_info,
1718 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021719 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031720 bool overridable,
[email protected]d9be47702012-05-16 03:41:221721 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171722 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001723 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021724 if (resource_type != ResourceType::MAIN_FRAME) {
1725 // A sub-resource has a certificate error. The user doesn't really
1726 // have a context for making the right decision, so block the
1727 // request hard, without an info bar to allow showing the insecure
1728 // content.
[email protected]8c965c22013-05-23 19:28:001729 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021730 return;
1731 }
1732
[email protected]f9034cf2011-07-21 12:43:411733 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131734 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171735 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411736 if (!tab) {
1737 NOTREACHED();
1738 return;
1739 }
1740 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501741 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301742 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011743 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1744 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411745 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171746 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411747 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001748 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411749 return;
1750 }
1751 }
1752
[email protected]1e87df32012-09-12 04:53:191753#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231754 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1755 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1756 if (captive_portal_tab_helper)
1757 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191758#endif
1759
[email protected]f9034cf2011-07-21 12:43:411760 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221761 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1762 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031763}
1764
[email protected]c99c442e2011-08-24 11:37:301765void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451766 int render_process_id,
1767 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401768 const net::HttpNetworkSession* network_session,
1769 net::SSLCertRequestInfo* cert_request_info,
1770 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131771 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451772 render_process_id, render_view_id);
1773 if (!tab) {
1774 NOTREACHED();
1775 return;
1776 }
1777
[email protected]6786bf402011-12-03 15:19:451778 GURL requesting_url("https://" + cert_request_info->host_and_port);
1779 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1780 << cert_request_info->host_and_port;
1781
[email protected]627e0512011-12-21 22:55:301782 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451783 scoped_ptr<Value> filter(
1784 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1785 requesting_url,
1786 requesting_url,
1787 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1788 std::string(), NULL));
1789
1790 if (filter.get()) {
1791 // Try to automatically select a client certificate.
1792 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1793 DictionaryValue* filter_dict =
1794 static_cast<DictionaryValue*>(filter.get());
1795
1796 const std::vector<scoped_refptr<net::X509Certificate> >&
1797 all_client_certs = cert_request_info->client_certs;
1798 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091799 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451800 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091801 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451802 return;
1803 }
1804 }
1805 } else {
1806 NOTREACHED();
1807 }
1808 }
1809
[email protected]11feec322012-09-18 03:58:521810 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1811 if (!ssl_tab_helper) {
1812 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451813 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141814 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401815 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451816 return;
1817 }
[email protected]11feec322012-09-18 03:58:521818 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401819 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451820}
1821
[email protected]3b455502012-12-11 18:22:581822void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451823 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581824 net::CertificateMimeType cert_type,
1825 const void* cert_data,
1826 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451827 int render_process_id,
1828 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581829 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1830 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451831}
1832
[email protected]dc73a7b2012-03-25 15:27:181833content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561834 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181835}
1836
[email protected]941623e2011-06-07 23:06:041837void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1838 const GURL& source_origin,
1839 int callback_context,
1840 int render_process_id,
1841 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111842#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021843 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1844 WebContents* contents =
1845 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1846 if (!contents) {
[email protected]941623e2011-06-07 23:06:041847 NOTREACHED();
1848 return;
1849 }
1850
[email protected]d0d9c3ee2012-06-19 03:07:021851 // Skip showing the infobar if the request comes from an extension, and that
1852 // extension has the 'notify' permission. (If the extension does not have the
1853 // permission, the user will still be prompted.)
1854 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011855 ExtensionInfoMap* extension_info_map =
1856 extensions::ExtensionSystem::Get(profile)->info_map();
1857 DesktopNotificationService* notification_service =
1858 DesktopNotificationServiceFactory::GetForProfile(profile);
1859 const Extension* extension = NULL;
1860 if (extension_info_map) {
1861 ExtensionSet extensions;
1862 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1863 source_origin, render_process_id,
1864 extensions::APIPermission::kNotification, &extensions);
1865 for (ExtensionSet::const_iterator iter = extensions.begin();
1866 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381867 if (notification_service->IsNotifierEnabled(NotifierId(
1868 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361869 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011870 break;
1871 }
1872 }
1873 }
[email protected]eb4832a2012-12-08 01:57:521874 RenderViewHost* rvh =
1875 RenderViewHost::FromID(render_process_id, render_view_id);
1876 if (IsExtensionWithPermissionOrSuggestInConsole(
1877 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021878 if (rvh)
1879 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1880 return;
1881 }
1882
[email protected]c7cd5942013-04-30 03:31:011883 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021884 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111885#else
1886 NOTIMPLEMENTED();
1887#endif
[email protected]941623e2011-06-07 23:06:041888}
1889
1890WebKit::WebNotificationPresenter::Permission
1891 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021892 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201893 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021894 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111895#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041896 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481897 // Sometimes a notification may be invoked during the shutdown.
1898 // See http://crbug.com/256638
1899 if (browser_shutdown::IsTryingToQuit())
1900 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
1901
[email protected]df02aca2012-02-09 21:03:201902 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041903
[email protected]c7cd5942013-04-30 03:31:011904 DesktopNotificationService* notification_service =
1905 io_data->GetNotificationService();
1906 if (notification_service) {
1907 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1908 ExtensionSet extensions;
1909 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1910 source_origin, render_process_id,
1911 extensions::APIPermission::kNotification, &extensions);
1912 for (ExtensionSet::const_iterator iter = extensions.begin();
1913 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381914 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
1915 if (notification_service->IsNotifierEnabled(notifier_id))
[email protected]c7cd5942013-04-30 03:31:011916 return WebKit::WebNotificationPresenter::PermissionAllowed;
1917 }
1918
1919 return notification_service->HasPermission(source_origin);
1920 }
1921
1922 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111923#else
1924 return WebKit::WebNotificationPresenter::PermissionAllowed;
1925#endif
[email protected]941623e2011-06-07 23:06:041926}
1927
1928void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171929 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041930 int render_process_id,
1931 int render_view_id,
1932 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111933#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041934 RenderViewHost* rvh = RenderViewHost::FromID(
1935 render_process_id, render_view_id);
1936 if (!rvh) {
1937 NOTREACHED();
1938 return;
1939 }
1940
[email protected]9f76c1e2012-03-05 15:15:581941 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301942 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041943 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371944 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041945 service->ShowDesktopNotification(
1946 params, render_process_id, render_view_id,
1947 worker ? DesktopNotificationService::WorkerNotification :
1948 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111949#else
1950 NOTIMPLEMENTED();
1951#endif
[email protected]941623e2011-06-07 23:06:041952}
1953
1954void ChromeContentBrowserClient::CancelDesktopNotification(
1955 int render_process_id,
1956 int render_view_id,
1957 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111958#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041959 RenderViewHost* rvh = RenderViewHost::FromID(
1960 render_process_id, render_view_id);
1961 if (!rvh) {
1962 NOTREACHED();
1963 return;
1964 }
1965
[email protected]9f76c1e2012-03-05 15:15:581966 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301967 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041968 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371969 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041970 service->CancelDesktopNotification(
1971 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111972#else
1973 NOTIMPLEMENTED();
1974#endif
[email protected]941623e2011-06-07 23:06:041975}
1976
[email protected]9f3fba52011-06-08 20:37:191977bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351978 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021979 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191980 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:231981 const GURL& target_url,
1982 const content::Referrer& referrer,
1983 WindowOpenDisposition disposition,
1984 const WebWindowFeatures& features,
1985 bool user_gesture,
1986 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:201987 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011988 int render_process_id,
[email protected]190e5e22013-07-27 05:59:231989 bool is_guest,
1990 int opener_id,
[email protected]03b6d552012-03-29 04:03:011991 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191992 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011993
1994 *no_javascript_access = false;
1995
[email protected]9f3fba52011-06-08 20:37:191996 // If the opener is trying to create a background window but doesn't have
1997 // the appropriate permission, fail the attempt.
1998 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201999 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:532000 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
2001
[email protected]03b6d552012-03-29 04:03:012002 if (!map->SecurityOriginHasAPIPermission(
2003 source_origin,
2004 render_process_id,
[email protected]c2e66e12012-06-27 06:27:062005 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:012006 return false;
2007 }
2008
[email protected]7b54ca02012-03-02 18:06:532009 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
2010 // return a recently installed Extension even if this CanCreateWindow call
2011 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:012012 // because the permission check above would have caused an early return
2013 // already. We must use the full URL to find hosted apps, though, and not
2014 // just the origin.
[email protected]be9915fb2013-07-18 09:28:552015 const Extension* extension =
2016 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:292017 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:012018 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:232019
2020 return true;
[email protected]9f3fba52011-06-08 20:37:192021 }
[email protected]056efdc2013-04-06 00:14:532022
2023 // No new browser window (popup or tab) in app mode.
2024 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
2025 chrome::IsRunningInForcedAppMode()) {
2026 return false;
2027 }
2028
[email protected]190e5e22013-07-27 05:59:232029#if !defined(OS_ANDROID)
2030 if (CommandLine::ForCurrentProcess()->HasSwitch(
2031 switches::kDisableBetterPopupBlocking)) {
2032 return true;
2033 }
2034
2035 if (is_guest)
2036 return true;
2037
2038 LOG(ERROR) << "opener " << opener_url << " - " << source_origin;
2039
2040 HostContentSettingsMap* content_settings =
2041 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
2042
2043 if ((disposition == NEW_POPUP || disposition == NEW_FOREGROUND_TAB ||
2044 disposition == NEW_BACKGROUND_TAB) && !user_gesture &&
2045 !CommandLine::ForCurrentProcess()->HasSwitch(
2046 switches::kDisablePopupBlocking)) {
2047 if (content_settings->GetContentSetting(opener_url,
2048 opener_url,
2049 CONTENT_SETTINGS_TYPE_POPUPS,
2050 std::string()) ==
2051 CONTENT_SETTING_ALLOW) {
2052 return true;
2053 }
2054
2055 BrowserThread::PostTask(BrowserThread::UI,
2056 FROM_HERE,
2057 base::Bind(&HandleBlockedPopupOnUIThread,
2058 BlockedPopupParams(target_url,
2059 referrer,
2060 disposition,
2061 features,
2062 user_gesture,
2063 opener_suppressed,
2064 render_process_id,
2065 opener_id)));
2066 return false;
2067 }
2068#endif
2069
[email protected]9f3fba52011-06-08 20:37:192070 return true;
2071}
2072
2073std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202074 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192075 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2076 // Check if it's an extension-created worker, in which case we want to use
2077 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202078 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192079 const Extension* extension =
2080 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2081 return extension ? extension->name() : std::string();
2082}
2083
[email protected]99907362012-01-11 05:41:402084void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2085 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172086}
2087
[email protected]7a06d282013-05-03 04:39:332088// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022089content::SpeechRecognitionManagerDelegate*
2090 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002091#if defined(ENABLE_INPUT_SPEECH)
2092 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322093#else
[email protected]855e18b2013-07-08 21:02:002094 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2095 // need the base delegate without the bubble UI.
2096 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322097#endif
[email protected]66cfec62012-02-24 17:57:512098}
2099
[email protected]ae6e9912011-07-27 01:18:282100net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2101 return g_browser_process->net_log();
2102}
2103
[email protected]32538d92011-08-25 00:09:232104AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2105 return new ChromeAccessTokenStore();
2106}
2107
[email protected]dbae6b02011-06-29 23:51:412108bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012109 return true;
[email protected]dbae6b02011-06-29 23:51:412110}
2111
[email protected]64d69de42012-02-06 00:19:542112void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322113 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062114 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582115 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062116 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062117
[email protected]f3986f82012-01-03 20:00:062118 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542119 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062120 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542121 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062122 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542123 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062124 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542125 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062126 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542127 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062128 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542129 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032130 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2131 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:062132
[email protected]64d69de42012-02-06 00:19:542133 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402134 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542135 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402136 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542137 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402138 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542139 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402140 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062141
[email protected]ddf72142012-05-22 04:52:402142 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062143
[email protected]64d69de42012-02-06 00:19:542144 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402145 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542146 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062147 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542148 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062149 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2150 const DictionaryValue* inspector_settings =
2151 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2152 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182153 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2154 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062155 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182156 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542157 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182158 std::make_pair(iter.key(), value));
2159 }
[email protected]f3986f82012-01-03 20:00:062160 }
2161 }
[email protected]64d69de42012-02-06 00:19:542162 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062163
[email protected]ddf72142012-05-22 04:52:402164 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542165 web_prefs->javascript_enabled = false;
2166 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2167 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402168 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542169 web_prefs->plugins_enabled = false;
2170 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2171 web_prefs->java_enabled = false;
2172 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402173 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062174
[email protected]64d69de42012-02-06 00:19:542175 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2176 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062177
[email protected]64d69de42012-02-06 00:19:542178 web_prefs->memory_info_enabled =
2179 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2180 web_prefs->allow_displaying_insecure_content =
2181 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2182 web_prefs->allow_running_insecure_content =
2183 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322184#if defined(OS_ANDROID)
2185 web_prefs->font_scale_factor =
2186 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2187 web_prefs->force_enable_zoom =
2188 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:452189#if defined(GOOGLE_TV)
2190 web_prefs->user_gesture_required_for_media_playback = false;
2191#endif
[email protected]d3b935f2012-10-19 23:14:322192#endif
[email protected]5c915252013-05-07 13:15:392193
[email protected]af4256d52013-06-04 20:39:072194#if defined(OS_ANDROID)
2195 web_prefs->password_echo_enabled =
2196 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2197#else
[email protected]9d06d88d2012-02-23 22:37:082198 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072199#endif
2200
[email protected]5c915252013-05-07 13:15:392201#if defined(OS_CHROMEOS)
2202 // Enable password echo during OOBE when keyboard driven flag is set.
2203 if (chromeos::UserManager::IsInitialized() &&
2204 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
[email protected]c94ac692013-07-27 00:50:102205 !chromeos::StartupUtils::IsOobeCompleted() &&
2206 chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation()) {
2207 web_prefs->password_echo_enabled = true;
[email protected]5c915252013-05-07 13:15:392208 }
2209#endif
[email protected]f3986f82012-01-03 20:00:062210
[email protected]46f8e742013-05-03 18:37:142211#if defined(OS_ANDROID)
2212 web_prefs->user_style_sheet_enabled = false;
2213#else
[email protected]64d69de42012-02-06 00:19:542214 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152215 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362216 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152217 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542218 web_prefs->user_style_sheet_enabled = true;
2219 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152220 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542221 } else {
2222 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062223 }
[email protected]46f8e742013-05-03 18:37:142224#endif
[email protected]f3986f82012-01-03 20:00:062225
[email protected]cfadadd2013-04-03 04:43:022226 web_prefs->asynchronous_spell_checking_enabled = true;
2227 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572228
[email protected]64d69de42012-02-06 00:19:542229 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062230 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542231 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062232 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542233 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062234 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2235
2236 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542237 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062238 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542239 web_prefs->default_encoding);
2240 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402241 prefs->ClearPref(prefs::kDefaultCharset);
2242 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062243 }
[email protected]64d69de42012-02-06 00:19:542244 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062245
[email protected]88ecf66d2012-12-11 22:53:472246 if (content::IsForceCompositingModeEnabled())
2247 web_prefs->force_compositing_mode = true;
2248
[email protected]299d7f12012-05-23 05:31:152249 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232250 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132251 ExtensionService* service =
2252 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062253 if (service) {
[email protected]1bc28312012-11-08 08:31:532254 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2255 const Extension* extension = service->extensions()->GetByID(url.host());
2256 // Ensure that we are only granting extension preferences to URLs with
2257 // the correct scheme. Without this check, chrome-guest:// schemes used by
2258 // webview tags as well as hosts that happen to match the id of an
2259 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422260 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532261 extension_webkit_preferences::SetPreferences(
2262 extension, view_type, web_prefs);
2263 }
[email protected]f3986f82012-01-03 20:00:062264 }
2265
[email protected]cb2edf22013-04-01 20:25:232266 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542267 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232268 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062269 // Disable all kinds of acceleration for background pages.
2270 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542271 web_prefs->force_compositing_mode = false;
2272 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062273 }
[email protected]2e21fe292012-03-02 22:52:322274
2275#if defined(FILE_MANAGER_EXTENSION)
2276 // Override the default of suppressing HW compositing for WebUI pages for the
2277 // file manager, which is implemented using WebUI but wants HW acceleration
2278 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532279 if (url.SchemeIs(extensions::kExtensionScheme) &&
2280 url.host() == kFileBrowserDomain) {
[email protected]2e21fe292012-03-02 22:52:322281 web_prefs->accelerated_compositing_enabled = true;
2282 web_prefs->accelerated_2d_canvas_enabled = true;
2283 }
2284#endif
[email protected]181a95ee2011-07-12 19:26:362285}
2286
2287void ChromeContentBrowserClient::UpdateInspectorSetting(
2288 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062289 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582290 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062291 DictionaryPrefUpdate update(
2292 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2293 prefs::kWebKitInspectorSettings);
2294 DictionaryValue* inspector_settings = update.Get();
2295 inspector_settings->SetWithoutPathExpansion(key,
2296 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362297}
2298
[email protected]b8148ac2011-07-13 22:03:252299void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2300 BrowserURLHandler* handler) {
2301 // Add the default URL handlers.
2302 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2303 BrowserURLHandler::null_handler());
2304 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2305 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2306
[email protected]b3adbd02011-11-30 22:23:272307 // about: handler. Must come before chrome: handler, since it will
2308 // rewrite about: urls to chrome: URLs and then expect chrome: to
2309 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252310 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2311 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032312
2313 // Handler to rewrite chrome://newtab for InstantExtended.
2314 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2315 &chrome::HandleNewTabURLReverseRewrite);
2316
[email protected]b8148ac2011-07-13 22:03:252317 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242318 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252319}
2320
2321void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372322 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582323 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472324 BrowsingDataRemover* remover =
2325 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552326 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2327 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252328 // BrowsingDataRemover takes care of deleting itself when done.
2329}
2330
2331void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372332 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582333 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472334 BrowsingDataRemover* remover =
2335 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232336 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552337 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252338 // BrowsingDataRemover takes care of deleting itself when done.
2339}
2340
[email protected]650b2d52013-02-10 03:41:452341base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322342 return download_util::GetDefaultDownloadDirectory();
2343}
2344
[email protected]c9b6eb62011-10-18 20:49:392345std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2346 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2347}
2348
[email protected]b7631cc2012-09-15 05:08:382349void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2350 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542351#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382352 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2353 scoped_ptr<ppapi::host::HostFactory>(
2354 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542355#endif
[email protected]b7631cc2012-09-15 05:08:382356}
2357
[email protected]0c7193742012-11-07 19:05:032358content::BrowserPpapiHost*
2359 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2360 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132361 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032362 while (!iter.Done()) {
2363 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2364 if (host->process() &&
2365 host->process()->GetData().id == plugin_process_id) {
2366 // Found the plugin.
2367 return host->browser_ppapi_host();
2368 }
2369 ++iter;
2370 }
2371 return NULL;
2372}
2373
[email protected]7b38b192013-03-23 18:39:312374bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2375 content::BrowserContext* browser_context, const GURL& site_url) {
2376 if (CommandLine::ForCurrentProcess()->HasSwitch(
2377 switches::kEnableBrowserPluginForAllViewTypes))
2378 return true;
2379
2380 Profile* profile = Profile::FromBrowserContext(browser_context);
2381 ExtensionService* service =
2382 extensions::ExtensionSystem::Get(profile)->extension_service();
2383 if (!service)
2384 return false;
2385
[email protected]be9915fb2013-07-18 09:28:552386 const Extension* extension =
2387 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312388 if (!extension)
2389 return false;
2390
[email protected]c2d2f102013-04-29 16:42:582391 return extension->HasAPIPermission(APIPermission::kWebView) ||
2392 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312393}
2394
[email protected]38cd8f7f2012-06-15 22:06:072395bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582396 content::BrowserContext* browser_context,
2397 const GURL& url,
[email protected]dda54822013-06-15 01:26:392398 bool private_api,
[email protected]157cc902012-11-02 06:31:582399 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402400#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372401 Profile* profile = Profile::FromBrowserContext(browser_context);
2402 const ExtensionSet* extension_set = NULL;
2403 if (profile) {
2404 extension_set = extensions::ExtensionSystem::Get(profile)->
2405 extension_service()->extensions();
2406 }
[email protected]dda54822013-06-15 01:26:392407
2408 if (private_api) {
2409 // Access to private socket APIs is controlled by the whitelist.
2410 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2411 allowed_socket_origins_)) {
2412 return true;
2413 }
2414 } else {
2415 // Access to public socket APIs is controlled by extension permissions.
2416 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2417 extension_set) {
2418 const Extension* extension = extension_set->GetByID(url.host());
2419 if (extension) {
2420 extensions::SocketPermission::CheckParam check_params(
2421 params.type, params.host, params.port);
2422 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2423 extension, extensions::APIPermission::kSocket, &check_params)) {
2424 return true;
2425 }
2426 }
2427 }
2428 }
2429
2430 // Allow both public and private APIs if the command line says so.
2431 return IsHostAllowedByCommandLine(url, extension_set,
2432 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402433#else
[email protected]a658d452012-03-02 12:45:292434 return false;
[email protected]93f72062013-05-29 20:29:402435#endif
[email protected]e461da2f2012-02-16 19:06:402436}
2437
[email protected]650b2d52013-02-10 03:41:452438base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2439 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142440 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2441 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2442}
2443
[email protected]a28e3302013-02-03 03:50:432444ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2445 WebContents* web_contents) {
2446 return new ChromeSelectFilePolicy(web_contents);
2447}
2448
[email protected]7d9424702013-04-14 13:14:162449void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2450 std::vector<std::string>* additional_allowed_schemes) {
2451 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2452 additional_allowed_schemes);
2453 additional_allowed_schemes->push_back(kChromeUIScheme);
2454 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2455}
2456
[email protected]f19bbf62013-07-09 01:22:322457void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312458 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532459 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322460 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532461#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032462 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322463 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032464 storage_partition_path,
2465 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322466 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532467#endif
[email protected]b40015c2013-06-26 08:13:312468#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312469 fileapi::ExternalMountPoints* external_mount_points =
2470 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312471 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322472 chromeos::FileSystemBackend* backend =
2473 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312474 new drive::FileSystemBackendDelegate(browser_context),
2475 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312476 external_mount_points,
2477 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322478 backend->AddSystemMountPoints();
2479 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2480 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312481#endif
[email protected]02250952013-04-24 23:52:532482}
2483
[email protected]e60c0232011-11-11 19:56:352484#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182485void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2486 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382487 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082488 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392489#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452490 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392491 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2492 DCHECK(!data_path.empty());
2493
2494 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452495 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392496 base::PlatformFile f =
2497 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2498 DCHECK(f != base::kInvalidPlatformFileValue);
2499 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2500 FileDescriptor(f, true)));
2501
[email protected]650b2d52013-02-10 03:41:452502 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392503 data_path.AppendASCII("chrome_100_percent.pak");
2504 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2505 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372506 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392507 FileDescriptor(f, true)));
2508
2509 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452510 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392511 GetLocaleFilePath(locale, false);
2512 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2513 DCHECK(f != base::kInvalidPlatformFileValue);
2514 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2515 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382516
[email protected]650b2d52013-02-10 03:41:452517 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372518 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2519 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2520 DCHECK(f != base::kInvalidPlatformFileValue);
2521 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2522 FileDescriptor(f, true)));
2523
[email protected]82174aa2013-01-22 21:53:432524 if (IsCrashReporterEnabled()) {
2525 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2526 if (f == base::kInvalidPlatformFileValue) {
2527 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2528 "be disabled for this process.";
2529 } else {
2530 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2531 FileDescriptor(f, true)));
2532 }
[email protected]40da3e0c2012-10-24 22:03:382533 }
[email protected]40da3e0c2012-10-24 22:03:382534
2535#else
2536 int crash_signal_fd = GetCrashSignalFD(command_line);
2537 if (crash_signal_fd >= 0) {
2538 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2539 FileDescriptor(crash_signal_fd,
2540 false)));
2541 }
[email protected]29699c22012-10-03 23:57:392542#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302543}
[email protected]e60c0232011-11-11 19:56:352544#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302545
[email protected]4a65826d2011-08-25 16:04:012546#if defined(OS_WIN)
2547const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2548 return chrome::kBrowserResourcesDll;
2549}
[email protected]34f48682013-03-20 00:30:182550
2551void ChromeContentBrowserClient::PreSpawnRenderer(
2552 sandbox::TargetPolicy* policy,
2553 bool* success) {
2554 // This code is duplicated in nacl_exe_win_64.cc.
2555 // Allow the server side of a pipe restricted to the "chrome.nacl."
2556 // namespace so that it cannot impersonate other system or other chrome
2557 // service pipes.
2558 sandbox::ResultCode result = policy->AddRule(
2559 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2560 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2561 L"\\\\.\\pipe\\chrome.nacl.*");
2562 if (result != sandbox::SBOX_ALL_OK) {
2563 *success = false;
2564 return;
2565 }
2566
2567 // Renderers need to send named pipe handles and shared memory
2568 // segment handles to NaCl loader processes.
2569 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2570 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2571 L"File");
2572 if (result != sandbox::SBOX_ALL_OK) {
2573 *success = false;
2574 return;
2575 }
2576}
[email protected]4a65826d2011-08-25 16:04:012577#endif
2578
[email protected]37a72af2011-06-13 05:42:012579#if defined(USE_NSS)
2580crypto::CryptoModuleBlockingPasswordDelegate*
2581 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2582 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292583 return chrome::NewCryptoModuleBlockingDialogDelegate(
2584 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012585}
2586#endif
2587
[email protected]d977f9c2011-03-14 16:10:262588} // namespace chrome