blob: a47541a8492f9bb09ce823ed1b4e87dd2eb79a66 [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]f9034cf2011-07-21 12:43:4161#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5062#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0763#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4164#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1465#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0366#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1467#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3268#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0669#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1470#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3871#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4372#include "chrome/browser/search/instant_service.h"
73#include "chrome/browser/search/instant_service_factory.h"
74#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1475#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0276#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3377#include "chrome/browser/speech/tts_message_filter.h"
[email protected]8ec71262011-07-28 08:12:4678#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5879#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0380#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5281#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4582#include "chrome/browser/tab_contents/tab_util.h"
[email protected]a28e3302013-02-03 03:50:4383#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2584#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4485#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5086#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0687#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1588#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2789#include "chrome/browser/validation_message_message_filter.h"
[email protected]b80f68432011-05-02 17:22:3090#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0191#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1492#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3093#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2994#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0495#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3896#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4497#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4398#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:2999#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]dda54822013-06-15 01:26:39100#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]157cc902012-11-02 06:31:58101#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:34102#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37103#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12104#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38105#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09106#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53107#include "chromeos/chromeos_constants.h"
[email protected]d5d383252013-07-04 14:44:32108#include "components/nacl/common/nacl_process_type.h"
[email protected]75fee372013-03-06 00:42:44109#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43110#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30111#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38112#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03113#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31114#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03115#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59116#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36117#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30118#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33119#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05120#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33121#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19122#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10123#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43124#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18125#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23126#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42127#include "extensions/common/constants.h"
[email protected]49d9b142013-07-19 08:50:27128#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39129#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23130#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53131#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58132#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34133#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06134#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57135#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38136#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39137#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08138#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24139#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31140#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18141#include "webkit/common/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04142#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26143
[email protected]b48c9182011-10-26 18:03:30144#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38145#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18146#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38147#elif defined(OS_MACOSX)
148#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56149#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30150#elif defined(OS_CHROMEOS)
151#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]f19bbf62013-07-09 01:22:32152#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h"
153#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39154#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49155#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]5c915252013-05-07 13:15:39156#include "chrome/browser/chromeos/system/statistics_provider.h"
[email protected]931d1042013-04-05 17:50:44157#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26158#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30159#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09160#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38161#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09162#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39163#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30164#elif defined(OS_POSIX)
165#include "chrome/browser/chrome_browser_main_posix.h"
166#endif
167
[email protected]6653c192012-04-10 22:52:44168#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30169#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12170#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43171#endif
[email protected]b80f68432011-05-02 17:22:30172
[email protected]1e87df32012-09-12 04:53:19173#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
174#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
175#endif
176
[email protected]29699c22012-10-03 23:57:39177#if defined(OS_ANDROID)
178#include "ui/base/ui_base_paths.h"
179#endif
180
[email protected]37a72af2011-06-13 05:42:01181#if defined(USE_NSS)
182#include "chrome/browser/ui/crypto_module_password_dialog.h"
183#endif
184
[email protected]d5bcd06f2013-04-21 08:07:24185#if !defined(OS_CHROMEOS)
186#include "chrome/browser/signin/signin_manager.h"
187#include "chrome/browser/signin/signin_manager_factory.h"
188#endif
189
[email protected]02250952013-04-24 23:52:53190#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32191#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53192#endif
193
[email protected]6ef98b5a2013-05-31 23:58:31194#if defined(ENABLE_WEBRTC)
195#include "chrome/browser/media/webrtc_logging_handler_host.h"
196#endif
197
[email protected]855e18b2013-07-08 21:02:00198#if defined(ENABLE_INPUT_SPEECH)
199#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
200#endif
201
[email protected]02a3dc122013-06-13 15:07:53202#if defined(FILE_MANAGER_EXTENSION)
203#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
204#endif
205
[email protected]e8b6ca02013-07-10 18:00:51206#if defined(TOOLKIT_GTK)
207#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
208#endif
209
210#if defined(TOOLKIT_VIEWS)
211#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
212#endif
213
214#if defined(USE_ASH)
215#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
216#endif
217
218#if defined(USE_AURA)
219#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
220#endif
221
222#if defined(USE_X11)
223#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
224#endif
225
[email protected]c7abd422012-09-25 00:20:08226using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47227using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03228using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39229using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31230using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59231using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08232using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00233using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11234using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33235using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13236using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06237using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34238using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40239using extensions::Manifest;
[email protected]631bb742011-11-02 11:29:39240
[email protected]c5dbef02011-05-13 05:06:09241namespace {
242
[email protected]eabbfb12013-04-05 23:28:35243// Cached version of the locale so we can return the locale on the I/O
244// thread.
245base::LazyInstance<std::string> g_io_thread_application_locale;
246
[email protected]93f72062013-05-29 20:29:40247#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40248const char* kPredefinedAllowedSocketOrigins[] = {
249 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18250 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45251 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
252 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
253 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
254 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35255 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54256 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
257 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
258 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
259 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
260 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
261 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38262 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58263 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29264 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]f6599915a2013-06-20 20:03:50265 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
[email protected]b71313232013-05-06 06:16:29266 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
267 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
268 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
269 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40270};
[email protected]93f72062013-05-29 20:29:40271#endif
[email protected]e461da2f2012-02-16 19:06:40272
[email protected]f8f93eb2012-09-25 03:06:24273// Returns a copy of the given url with its host set to given host and path set
274// to given path. Other parts of the url will be the same.
275GURL ReplaceURLHostAndPath(const GURL& url,
276 const std::string& host,
277 const std::string& path) {
278 url_canon::Replacements<char> replacements;
279 replacements.SetHost(host.c_str(),
280 url_parse::Component(0, host.length()));
281 replacements.SetPath(path.c_str(),
282 url_parse::Component(0, path.length()));
283 return url.ReplaceComponents(replacements);
284}
285
286// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
287GURL AddUberHost(const GURL& url) {
288 const std::string uber_host = chrome::kChromeUIUberHost;
289 const std::string new_path = url.host() + url.path();
290
291 return ReplaceURLHostAndPath(url, uber_host, new_path);
292}
293
[email protected]045bf7c2012-09-28 20:27:36294// If url->host() is "chrome" and url->path() has characters other than the
295// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
296// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24297bool RemoveUberHost(GURL* url) {
298 if (url->host() != chrome::kChromeUIUberHost)
299 return false;
300
[email protected]045bf7c2012-09-28 20:27:36301 if (url->path().empty() || url->path() == "/")
302 return false;
303
[email protected]f8f93eb2012-09-25 03:06:24304 const std::string old_path = url->path();
305
306 const std::string::size_type separator = old_path.find('/', 1);
307 std::string new_host;
308 std::string new_path;
309 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36310 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24311 } else {
312 new_host = old_path.substr(1, separator - 1);
313 new_path = old_path.substr(separator);
314 }
315
[email protected]44e8add2013-06-13 17:29:15316 // Do not allow URLs with paths empty before the first slash since we can't
317 // have an empty host. (e.g "foo://chrome//")
318 if (new_host.empty())
319 return false;
320
[email protected]f8f93eb2012-09-25 03:06:24321 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
322
[email protected]44e8add2013-06-13 17:29:15323 DCHECK(url->is_valid());
324
[email protected]f8f93eb2012-09-25 03:06:24325 return true;
326}
327
[email protected]b8148ac2011-07-13 22:03:25328// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42329bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24330 // Do not handle special URLs such as "about:foo"
331 if (!url->host().empty()) {
332 const GURL chrome_url = AddUberHost(*url);
333
334 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
335 // be called.
336 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
337 browser_context, chrome_url))
338 return true;
339 }
340
[email protected]863f70a2012-01-27 02:05:50341 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
342 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25343 return false;
344
[email protected]fe69558d2012-03-12 11:34:49345#if defined(OS_CHROMEOS)
346 // Special case : in ChromeOS in Guest mode bookmarks and history are
347 // disabled for security reasons. New tab page explains the reasons, so
348 // we redirect user to new tab page.
349 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
350 if (url->SchemeIs(chrome::kChromeUIScheme) &&
351 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
352 url->DomainIs(chrome::kChromeUIHistoryHost))) {
353 // Rewrite with new tab URL
354 *url = GURL(chrome::kChromeUINewTabURL);
355 }
356 }
357#endif
358
[email protected]b8148ac2011-07-13 22:03:25359 // Special case the new tab page. In older versions of Chrome, the new tab
360 // page was hosted at chrome-internal:<blah>. This might be in people's saved
361 // sessions or bookmarks, so we say any URL with that scheme triggers the new
362 // tab page.
363 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
364 // Rewrite it with the proper new tab URL.
365 *url = GURL(chrome::kChromeUINewTabURL);
366 }
367
368 return true;
369}
370
[email protected]f8f93eb2012-09-25 03:06:24371// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
372// "chrome://foo/".
373bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
374 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
375 return false;
376
377 return RemoveUberHost(url);
378}
379
[email protected]8d3132f62011-10-12 07:13:42380// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
381// below. Extension, and isolated apps require different privileges to be
382// granted to their RenderProcessHosts. This classification allows us to make
383// sure URLs are served by hosts with the right set of privileges.
384enum RenderProcessHostPrivilege {
385 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45386 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42387 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45388 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42389};
390
391RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
392 const GURL& url,
393 ExtensionService* service) {
394 // Default to a normal renderer cause it is lower privileged. This should only
395 // occur if the URL on a site instance is either malformed, or uninitialized.
396 // If it is malformed, then there is no need for better privileges anyways.
397 // If it is uninitialized, but eventually settles on being an a scheme other
398 // than normal webrenderer, the navigation logic will correct us out of band
399 // anyways.
400 if (!url.is_valid())
401 return PRIV_NORMAL;
402
[email protected]885c0e92012-11-13 20:27:42403 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44404 const Extension* extension =
405 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43406 if (extension &&
407 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42408 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45409 if (extension && extension->is_hosted_app())
410 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42411
412 return PRIV_EXTENSION;
413 }
414
415 return PRIV_NORMAL;
416}
417
418RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30419 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46420 extensions::ProcessMap* process_map,
421 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46422 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30423 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46424 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21425 return PRIV_NORMAL;
426
[email protected]6f371442011-11-09 06:45:46427 for (std::set<std::string>::iterator iter = extension_ids.begin();
428 iter != extension_ids.end(); ++iter) {
429 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43430 if (extension &&
431 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42432 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45433 if (extension && extension->is_hosted_app())
434 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42435 }
436
[email protected]676f6ab2011-10-19 20:23:21437 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42438}
439
[email protected]6786bf402011-12-03 15:19:45440bool CertMatchesFilter(const net::X509Certificate& cert,
441 const base::DictionaryValue& filter) {
442 // TODO(markusheintz): This is the minimal required filter implementation.
443 // Implement a better matcher.
444
445 // An empty filter matches any client certificate since no requirements are
446 // specified at all.
447 if (filter.empty())
448 return true;
449
450 std::string common_name;
451 if (filter.GetString("ISSUER.CN", &common_name) &&
452 (cert.issuer().common_name == common_name)) {
453 return true;
454 }
455 return false;
456}
457
[email protected]f3986f82012-01-03 20:00:06458// Fills |map| with the per-script font prefs under path |map_name|.
459void FillFontFamilyMap(const PrefService* prefs,
460 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53461 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06462 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
463 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
464 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
465 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23466 if (!font_family.empty())
467 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06468 }
469}
470
[email protected]a1733df2012-06-22 11:24:18471#if defined(OS_POSIX) && !defined(OS_MACOSX)
472int GetCrashSignalFD(const CommandLine& command_line) {
473 if (command_line.HasSwitch(switches::kExtensionProcess)) {
474 ExtensionCrashHandlerHostLinux* crash_handler =
475 ExtensionCrashHandlerHostLinux::GetInstance();
476 return crash_handler->GetDeathSignalSocket();
477 }
478
479 std::string process_type =
480 command_line.GetSwitchValueASCII(switches::kProcessType);
481
482 if (process_type == switches::kRendererProcess)
483 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
484
485 if (process_type == switches::kPluginProcess)
486 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
487
488 if (process_type == switches::kPpapiPluginProcess)
489 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
490
491 if (process_type == switches::kGpuProcess)
492 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
493
494 return -1;
495}
496#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
497
[email protected]d5bcd06f2013-04-21 08:07:24498#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30499GURL GetEffectiveURLForSignin(const GURL& url) {
500 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
501
502 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03503 // Copy the path because the argument to SetPathStr must outlive
504 // the Replacements object.
505 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30506 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03507 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30508 effective_url = effective_url.ReplaceComponents(replacements);
509 return effective_url;
510}
[email protected]d5bcd06f2013-04-21 08:07:24511#endif
[email protected]970c63e2013-03-07 00:25:30512
[email protected]eabbfb12013-04-05 23:28:35513void SetApplicationLocaleOnIOThread(const std::string& locale) {
514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
515 g_io_thread_application_locale.Get() = locale;
516}
517
[email protected]9dbfff12011-07-01 19:37:07518} // namespace
[email protected]c5dbef02011-05-13 05:06:09519
[email protected]d977f9c2011-03-14 16:10:26520namespace chrome {
521
[email protected]e461da2f2012-02-16 19:06:40522ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40523#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40524 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
525 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40526#endif
[email protected]1deace22013-05-22 06:14:46527
528 permissions_policy_delegate_.reset(
529 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40530}
531
532ChromeContentBrowserClient::~ChromeContentBrowserClient() {
533}
534
[email protected]bca18382012-06-25 19:15:23535// static
[email protected]37ca3fe02013-07-05 15:32:44536void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34537 user_prefs::PrefRegistrySyncable* registry) {
538 registry->RegisterBooleanPref(
539 prefs::kDisable3DAPIs,
540 false,
541 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
542 registry->RegisterBooleanPref(
543 prefs::kEnableHyperlinkAuditing,
544 true,
545 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
546 registry->RegisterBooleanPref(
547 prefs::kEnableMemoryInfo,
548 false,
549 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23550}
551
[email protected]eabbfb12013-04-05 23:28:35552// static
553void ChromeContentBrowserClient::SetApplicationLocale(
554 const std::string& locale) {
555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
556
557 // This object is guaranteed to outlive all threads so we don't have to
558 // worry about the lack of refcounting and can just post as Unretained.
559 //
560 // The common case is that this function is called early in Chrome startup
561 // before any threads are created (it will also be called later if the user
562 // changes the pref). In this case, there will be no threads created and
563 // posting will fail. When there are no threads, we can just set the string
564 // without worrying about threadsafety.
565 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
566 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
567 g_io_thread_application_locale.Get() = locale;
568 }
569}
570
[email protected]50462bf02011-11-21 19:13:31571content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
572 const content::MainFunctionParams& parameters) {
573 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30574 // Construct the Main browser parts based on the OS type.
575#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31576 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04577#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31578 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30579#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22580 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26581#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31582 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14583#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09584 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30585#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31586 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04587#else
[email protected]b48c9182011-10-26 18:03:30588 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31589 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30590#endif
591
[email protected]7e75e4a2013-05-17 17:20:03592 chrome::AddProfilesExtraParts(main_parts);
593
[email protected]c7480942011-11-08 19:18:27594 // Construct additional browser parts. Stages are called in the order in
595 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22596#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51597 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04598#endif
[email protected]c7480942011-11-08 19:18:27599
600#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51601 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27602#endif
603
[email protected]dc04be7c2012-03-15 23:57:49604#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51605 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49606#endif
607
[email protected]e050ef142012-03-21 01:04:24608#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51609 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
610#endif
611
612#if defined(USE_X11)
613 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24614#endif
615
[email protected]95132f52013-04-12 02:19:04616 chrome::AddMetricsExtraParts(main_parts);
617
[email protected]50462bf02011-11-21 19:13:31618 return main_parts;
[email protected]f967b722011-09-07 00:58:04619}
620
[email protected]e94bbcb2012-09-07 05:33:57621std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19622 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57623 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53624 std::string partition_id;
625
626 // The partition ID for webview guest processes is the string value of its
627 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
628 if (site.SchemeIs(chrome::kGuestScheme))
629 partition_id = site.spec();
630
[email protected]056efdc2013-04-06 00:14:53631 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53632 return partition_id;
633}
634
635bool ChromeContentBrowserClient::IsValidStoragePartitionId(
636 content::BrowserContext* browser_context,
637 const std::string& partition_id) {
638 // The default ID is empty and is always valid.
639 if (partition_id.empty())
640 return true;
641
642 return GURL(partition_id).is_valid();
643}
644
645void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
646 content::BrowserContext* browser_context,
647 const GURL& site,
[email protected]14acc642012-11-17 12:20:10648 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53649 std::string* partition_domain,
650 std::string* partition_name,
651 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10652 // Default to the browser-wide storage partition and override based on |site|
653 // below.
654 partition_domain->clear();
655 partition_name->clear();
656 *in_memory = false;
657
[email protected]1bc28312012-11-08 08:31:53658 // For the webview tag, we create special guest processes, which host the
659 // tag content separately from the main application that embeds the tag.
660 // A webview tag can specify both the partition name and whether the storage
661 // for that partition should be persisted. Each tag gets a SiteInstance with
662 // a specially formatted URL, based on the application it is hosted by and
663 // the partition requested by it. The format for that URL is:
664 // chrome-guest://partition_domain/persist?partition_name
665 if (site.SchemeIs(chrome::kGuestScheme)) {
666 // Since guest URLs are only used for packaged apps, there must be an app
667 // id in the URL.
668 CHECK(site.has_host());
669 *partition_domain = site.host();
670 // Since persistence is optional, the path must either be empty or the
671 // literal string.
672 *in_memory = (site.path() != "/persist");
673 // The partition name is user supplied value, which we have encoded when the
674 // URL was created, so it needs to be decoded.
675 *partition_name = net::UnescapeURLComponent(site.query(),
676 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10677 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
678 // If |can_be_default| is false, the caller is stating that the |site|
679 // should be parsed as if it had isolated storage. In particular it is
680 // important to NOT check ExtensionService for the is_storage_isolated()
681 // attribute because this code path is run during Extension uninstall
682 // to do cleanup after the Extension has already been unloaded from the
683 // ExtensionService.
684 bool is_isolated = !can_be_default;
685 if (can_be_default) {
686 const Extension* extension = NULL;
687 Profile* profile = Profile::FromBrowserContext(browser_context);
688 ExtensionService* extension_service =
689 extensions::ExtensionSystem::Get(profile)->extension_service();
690 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55691 extension =
692 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43693 if (extension &&
694 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10695 is_isolated = true;
696 }
697 }
698 }
[email protected]1bc28312012-11-08 08:31:53699
[email protected]14acc642012-11-17 12:20:10700 if (is_isolated) {
701 CHECK(site.has_host());
702 // For extensions with isolated storage, the the host of the |site| is
703 // the |partition_domain|. The |in_memory| and |partition_name| are only
704 // used in guest schemes so they are cleared here.
705 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53706 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10707 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53708 }
[email protected]d1198fd2012-08-13 22:50:19709 }
710
[email protected]14acc642012-11-17 12:20:10711 // Assert that if |can_be_default| is false, the code above must have found a
712 // non-default partition. If this fails, the caller has a serious logic
713 // error about which StoragePartition they expect to be in and it is not
714 // safe to continue.
715 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44716}
717
[email protected]38b098f2012-03-14 21:11:57718content::WebContentsViewDelegate*
719 ChromeContentBrowserClient::GetWebContentsViewDelegate(
720 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27721 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32722}
723
[email protected]24665682013-02-25 20:59:38724// Check if the extension activity log is enabled for the profile.
725static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33726 // crbug.com/247908 - This should be IsLogEnabled except for an issue
727 // in chrome_frame_net_tests
728 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38729}
730
[email protected]738f57a2013-06-29 21:06:54731void ChromeContentBrowserClient::GuestWebContentsCreated(
732 WebContents* guest_web_contents,
733 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22734 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54735 scoped_ptr<base::DictionaryValue> extra_params) {
736 if (opener_web_contents) {
737 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
738 if (!guest) {
739 NOTREACHED();
740 return;
741 }
742
743 switch (guest->GetViewType()) {
744 case GuestView::WEBVIEW: {
[email protected]4c0e8272013-07-03 23:39:22745 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54746 break;
747 }
748 case GuestView::ADVIEW: {
[email protected]4c0e8272013-07-03 23:39:22749 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54750 break;
751 }
752 default:
753 NOTREACHED();
754 break;
755 }
756 return;
757 }
758
759 if (!extra_params) {
760 NOTREACHED();
761 return;
762 }
763 std::string api_type;
764 extra_params->GetString(guestview::kAttributeApi, &api_type);
765
766 if (api_type == "adview") {
[email protected]4c0e8272013-07-03 23:39:22767 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54768 } else if (api_type == "webview") {
[email protected]4c0e8272013-07-03 23:39:22769 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54770 } else {
771 NOTREACHED();
772 }
773}
774
[email protected]44295a12013-06-05 08:45:46775void ChromeContentBrowserClient::GuestWebContentsAttached(
776 WebContents* guest_web_contents,
777 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53778 int browser_plugin_instance_id,
779 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06780 Profile* profile = Profile::FromBrowserContext(
781 embedder_web_contents->GetBrowserContext());
782 ExtensionService* service =
783 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54784 if (!service) {
785 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06786 return;
[email protected]738f57a2013-06-29 21:06:54787 }
[email protected]44703cc72013-01-24 04:56:06788 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
[email protected]be9915fb2013-07-18 09:28:55789 const Extension* extension =
790 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]738f57a2013-06-29 21:06:54791 if (!extension) {
[email protected]18699372013-06-25 20:42:55792 NOTREACHED();
[email protected]738f57a2013-06-29 21:06:54793 return;
[email protected]18699372013-06-25 20:42:55794 }
[email protected]738f57a2013-06-29 21:06:54795
796 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
797 if (!guest) {
798 NOTREACHED();
799 return;
800 }
801 guest->Attach(embedder_web_contents,
802 extension->id(),
803 browser_plugin_instance_id,
804 extra_params);
[email protected]44703cc72013-01-24 04:56:06805}
806
[email protected]f3b1a082011-11-18 00:34:30807void ChromeContentBrowserClient::RenderProcessHostCreated(
808 content::RenderProcessHost* host) {
809 int id = host->GetID();
810 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41811 net::URLRequestContextGetter* context =
812 profile->GetRequestContextForRenderProcess(id);
813
[email protected]f3b1a082011-11-18 00:34:30814 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41815 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55816#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30817 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55818#endif
[email protected]658677f2012-06-09 06:04:02819#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08820 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03821#endif
[email protected]f3b1a082011-11-18 00:34:30822 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02823 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30824 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56825#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21826 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56827#endif
[email protected]43535512013-02-20 20:41:41828 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
829 id, profile, context));
[email protected]2736c032012-05-11 18:06:07830 host->GetChannel()->AddFilter(
831 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27832 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33833 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31834#if defined(ENABLE_WEBRTC)
835 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
836#endif
[email protected]01e59752013-06-18 00:17:35837#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03838 ExtensionInfoMap* extension_info_map =
839 extensions::ExtensionSystem::Get(profile)->info_map();
840 host->GetChannel()->AddFilter(new NaClHostMessageFilter(
841 id, profile->IsOffTheRecord(),
842 profile->GetPath(), extension_info_map,
843 context));
[email protected]01e59752013-06-18 00:17:35844#endif
[email protected]3e69bc82011-05-26 23:22:38845
[email protected]2ccf45c2011-08-19 23:35:50846 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
847 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07848
[email protected]24665682013-02-25 20:59:38849 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
850 IsExtensionActivityLogEnabledForProfile(profile)));
851
[email protected]39a5b532011-10-22 01:47:07852 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56853
854 RendererContentSettingRules rules;
855 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
856 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14857}
858
[email protected]95c95552013-05-03 04:21:22859GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
860 content::BrowserContext* browser_context,
861 const GURL& url,
862 bool is_renderer_initiated,
863 content::SiteInstance* current_instance) {
864 Profile* profile = Profile::FromBrowserContext(browser_context);
865 if (!profile)
866 return url;
867
868 // Only return the privileged instant URL if we are entering from a browser-
869 // initiated navigation or if we are already in the instant process.
870 bool is_instant_process = false;
871 int process_id = current_instance->GetProcess()->GetID();
872 InstantService* instant_service =
873 InstantServiceFactory::GetForProfile(profile);
874 if (instant_service)
875 is_instant_process = instant_service->IsInstantProcess(process_id);
876
877 DCHECK_EQ(is_instant_process,
878 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
879 if (!is_renderer_initiated || is_instant_process) {
880 // If the input |url| should be assigned to the Instant renderer, make its
881 // privileged URL distinct from other URLs on the search provider's domain.
882 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
883 return chrome::GetPrivilegedURLForInstant(url, profile);
884 }
885
886 return url;
887}
888
[email protected]3d7474ff2011-07-27 17:47:37889GURL ChromeContentBrowserClient::GetEffectiveURL(
890 content::BrowserContext* browser_context, const GURL& url) {
891 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52892 if (!profile)
893 return url;
894
[email protected]d5bcd06f2013-04-21 08:07:24895#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30896 // If the input |url| should be assigned to the Signin renderer, make its
897 // effective URL distinct from other URLs on the signin service's domain.
898 // Note that the signin renderer will be allowed to sign the user in to
899 // Chrome.
900 if (SigninManager::IsWebBasedSigninFlowURL(url))
901 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24902#endif
[email protected]970c63e2013-03-07 00:25:30903
[email protected]c5dec6292013-01-25 04:54:52904 // If the input |url| is part of an installed app, the effective URL is an
905 // extension URL with the ID of that extension as the host. This has the
906 // effect of grouping apps together in a common SiteInstance.
907 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13908 extensions::ExtensionSystem::Get(profile)->extension_service();
909 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08910 return url;
911
[email protected]06bdd2b2012-11-30 18:47:13912 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55913 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08914 if (!extension)
915 return url;
916
[email protected]15877ca2011-11-18 22:40:52917 // Bookmark apps do not use the hosted app process model, and should be
918 // treated as normal URLs.
919 if (extension->from_bookmark())
920 return url;
921
[email protected]36fb2c7c2011-04-04 15:49:08922 // If the URL is part of an extension's web extent, convert it to an
923 // extension URL.
924 return extension->GetResourceURL(url.path());
925}
926
[email protected]056ad2a2011-07-12 02:13:55927bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37928 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52929 // Non-extension, non-Instant URLs should generally use
930 // process-per-site-instance. Because we expect to use the effective URL,
931 // URLs for hosted apps (apart from bookmark apps) should have an extension
932 // scheme by now.
933
934 Profile* profile = Profile::FromBrowserContext(browser_context);
935 if (!profile)
936 return false;
937
[email protected]df113a12013-07-24 04:56:08938 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52939 return true;
940
[email protected]d5bcd06f2013-04-21 08:07:24941#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30942 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
943 return true;
[email protected]d5bcd06f2013-04-21 08:07:24944#endif
[email protected]970c63e2013-03-07 00:25:30945
[email protected]885c0e92012-11-13 20:27:42946 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55947 return false;
948
[email protected]c5dec6292013-01-25 04:54:52949 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13950 extensions::ExtensionSystem::Get(profile)->extension_service();
951 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55952 return false;
953
[email protected]be9915fb2013-07-18 09:28:55954 const Extension* extension =
955 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:55956 if (!extension)
957 return false;
958
959 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53960 // permission, or that does not allow JavaScript access to the background
961 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55962 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40963 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06964 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29965 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53966 return false;
967 }
968 }
[email protected]056ad2a2011-07-12 02:13:55969
[email protected]7b54ca02012-03-02 18:06:53970 // Hosted apps that have script access to their background page must use
971 // process per site, since all instances can make synchronous calls to the
972 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55973 return true;
974}
975
[email protected]672c8c12013-03-07 12:30:06976// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41977void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
978 std::vector<std::string>* additional_schemes) {
979 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06980}
981
[email protected]6bd30072013-02-08 18:17:11982net::URLRequestContextGetter*
983ChromeContentBrowserClient::CreateRequestContext(
984 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06985 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11986 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06987 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11988}
989
990net::URLRequestContextGetter*
991ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
992 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40993 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11994 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06995 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11996 Profile* profile = Profile::FromBrowserContext(browser_context);
997 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06998 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11999}
1000
[email protected]46fb9442011-12-09 17:57:471001bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1002 return ProfileIOData::IsHandledURL(url);
1003}
1004
[email protected]c4365fa42013-05-14 01:08:241005bool ChromeContentBrowserClient::CanCommitURL(
1006 content::RenderProcessHost* process_host,
1007 const GURL& url) {
1008 // We need to let most extension URLs commit in any process, since this can
1009 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1010 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1011 // cannot be loaded in iframes and should never be requested outside its
1012 // process.
1013 Profile* profile =
1014 Profile::FromBrowserContext(process_host->GetBrowserContext());
1015 ExtensionService* service =
1016 extensions::ExtensionSystem::Get(profile)->extension_service();
1017 if (!service)
1018 return true;
1019 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551020 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241021 if (new_extension &&
1022 new_extension->is_hosted_app() &&
1023 new_extension->id() == extension_misc::kWebStoreAppId &&
1024 !service->process_map()->Contains(new_extension->id(),
1025 process_host->GetID())) {
1026 return false;
1027 }
1028
1029 return true;
1030}
1031
[email protected]2a5221b2011-09-27 23:07:311032bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301033 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311034 const GURL& site_url) {
1035 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301036 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521037 // This may be NULL during tests. In that case, just assume any site can
1038 // share any host.
1039 if (!profile)
1040 return true;
1041
[email protected]d43f99fe2013-04-03 00:20:141042 // Instant URLs should only be in the instant process and instant process
1043 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521044 InstantService* instant_service =
1045 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141046 if (instant_service) {
1047 bool is_instant_process = instant_service->IsInstantProcess(
1048 process_host->GetID());
1049 bool should_be_in_instant_process =
1050 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1051 if (is_instant_process || should_be_in_instant_process)
1052 return is_instant_process && should_be_in_instant_process;
1053 }
[email protected]c5dec6292013-01-25 04:54:521054
[email protected]d5bcd06f2013-04-21 08:07:241055#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301056 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1057 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1058 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241059#endif
[email protected]970c63e2013-03-07 00:25:301060
[email protected]06bdd2b2012-11-30 18:47:131061 ExtensionService* service =
1062 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461063 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311064
[email protected]ffa97602011-11-17 17:55:521065 // Don't allow the Task Manager to share a process with anything else.
1066 // Otherwise it can affect the renderers it is observing.
1067 // Note: we could create another RenderProcessHostPrivilege bucket for
1068 // this to allow multiple chrome://tasks instances to share, but that's
1069 // a very unlikely case without serious consequences.
1070 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1071 return false;
1072
[email protected]8d3132f62011-10-12 07:13:421073 // These may be NULL during tests. In that case, just assume any site can
1074 // share any host.
[email protected]6f371442011-11-09 06:45:461075 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311076 return true;
1077
[email protected]eec0b33c2011-12-05 22:09:451078 // Otherwise, just make sure the process privilege matches the privilege
1079 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571080 RenderProcessHostPrivilege privilege_required =
1081 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451082 return GetProcessPrivilege(process_host, process_map, service) ==
1083 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311084}
1085
[email protected]76411f412012-02-22 18:56:061086// This function is trying to limit the amount of processes used by extensions
1087// with background pages. It uses a globally set percentage of processes to
1088// run such extensions and if the limit is exceeded, it returns true, to
1089// indicate to the content module to group extensions together.
1090bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1091 content::BrowserContext* browser_context, const GURL& url) {
1092 // It has to be a valid URL for us to check for an extension.
1093 if (!url.is_valid())
1094 return false;
1095
1096 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191097 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131098 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061099 if (!service)
1100 return false;
1101
1102 // We have to have a valid extension with background page to proceed.
1103 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551104 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061105 if (!extension)
1106 return false;
[email protected]9367eabc2013-03-01 01:29:291107 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061108 return false;
1109
1110 std::set<int> process_ids;
1111 size_t max_process_count =
1112 content::RenderProcessHost::GetMaxRendererProcessCount();
1113
1114 // Go through all profiles to ensure we have total count of extension
1115 // processes containing background pages, otherwise one profile can
1116 // starve the other.
1117 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1118 GetLoadedProfiles();
1119 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031120 ExtensionProcessManager* epm =
1121 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321122 for (ExtensionProcessManager::const_iterator iter =
1123 epm->background_hosts().begin();
1124 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131125 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321126 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061127 }
1128 }
1129
1130 if (process_ids.size() >
1131 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1132 return true;
1133 }
1134
1135 return false;
1136}
1137
[email protected]6f371442011-11-09 06:45:461138void ChromeContentBrowserClient::SiteInstanceGotProcess(
1139 SiteInstance* site_instance) {
1140 CHECK(site_instance->HasProcess());
1141
1142 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021143 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521144 if (!profile)
1145 return;
1146
1147 // Remember the ID of the Instant process to signal the renderer process
1148 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031149 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321150 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521151 InstantService* instant_service =
1152 InstantServiceFactory::GetForProfile(profile);
1153 if (instant_service)
1154 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1155 }
1156
[email protected]d5bcd06f2013-04-21 08:07:241157#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301158 // We only expect there to be one signin process as we use process-per-site
1159 // for signin URLs. The signin process will be cleared from SigninManager
1160 // when the renderer is destroyed.
1161 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1162 SigninManager* signin_manager =
1163 SigninManagerFactory::GetForProfile(profile);
1164 if (signin_manager)
1165 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461166 BrowserThread::PostTask(
1167 BrowserThread::IO, FROM_HERE,
1168 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1169 extensions::ExtensionSystem::Get(profile)->info_map(),
1170 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301171 }
[email protected]d5bcd06f2013-04-21 08:07:241172#endif
[email protected]970c63e2013-03-07 00:25:301173
[email protected]06bdd2b2012-11-30 18:47:131174 ExtensionService* service =
1175 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461176 if (!service)
1177 return;
1178
[email protected]be9915fb2013-07-18 09:28:551179 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1180 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461181 if (!extension)
1182 return;
1183
[email protected]6bc04fd82011-12-04 02:29:351184 service->process_map()->Insert(extension->id(),
1185 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331186 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461187 BrowserThread::PostTask(
1188 BrowserThread::IO, FROM_HERE,
1189 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591190 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461191 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351192 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331193 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461194}
1195
1196void ChromeContentBrowserClient::SiteInstanceDeleting(
1197 SiteInstance* site_instance) {
1198 if (!site_instance->HasProcess())
1199 return;
1200
1201 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021202 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131203 ExtensionService* service =
1204 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461205 if (!service)
1206 return;
1207
[email protected]be9915fb2013-07-18 09:28:551208 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1209 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461210 if (!extension)
1211 return;
1212
[email protected]6bc04fd82011-12-04 02:29:351213 service->process_map()->Remove(extension->id(),
1214 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331215 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461216 BrowserThread::PostTask(
1217 BrowserThread::IO, FROM_HERE,
1218 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591219 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461220 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351221 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331222 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461223}
1224
[email protected]f05763972012-06-06 18:17:261225bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141226 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081227 const GURL& current_url,
1228 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261229 if (current_url.is_empty()) {
1230 // Always choose a new process when navigating to extension URLs. The
1231 // process grouping logic will combine all of a given extension's pages
1232 // into the same process.
[email protected]885c0e92012-11-13 20:27:421233 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261234 return true;
[email protected]e3daf3c2011-10-05 21:17:081235
[email protected]f05763972012-06-06 18:17:261236 return false;
1237 }
1238
1239 // Also, we must switch if one is an extension and the other is not the exact
1240 // same extension.
[email protected]885c0e92012-11-13 20:27:421241 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1242 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261243 if (current_url.GetOrigin() != new_url.GetOrigin())
1244 return true;
1245 }
1246
[email protected]e9841fbd2013-02-22 23:12:141247 // The checks below only matter if we can retrieve which extensions are
1248 // installed.
1249 Profile* profile =
1250 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1251 ExtensionService* service =
1252 extensions::ExtensionSystem::Get(profile)->extension_service();
1253 if (!service)
1254 return false;
1255
1256 // We must swap if the URL is for an extension and we are not using an
1257 // extension process.
1258 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551259 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141260 // Ignore all hosted apps except the Chrome Web Store, since they do not
1261 // require their own BrowsingInstance (e.g., postMessage is ok).
1262 if (new_extension &&
1263 new_extension->is_hosted_app() &&
1264 new_extension->id() != extension_misc::kWebStoreAppId)
1265 new_extension = NULL;
1266 if (new_extension &&
1267 site_instance->HasProcess() &&
1268 !service->process_map()->Contains(new_extension->id(),
1269 site_instance->GetProcess()->GetID()))
1270 return true;
1271
[email protected]f05763972012-06-06 18:17:261272 return false;
[email protected]e3daf3c2011-10-05 21:17:081273}
1274
[email protected]395045c2012-05-22 15:04:381275bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1276 content::ResourceContext* resource_context, const GURL& current_url,
1277 const GURL& new_url) {
1278 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1279 return extensions::CrossesExtensionProcessBoundary(
1280 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551281 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381282}
1283
[email protected]3d831992013-07-04 01:13:291284bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1285 return !url.SchemeIs(chrome::kChromeNativeScheme);
1286}
1287
[email protected]763ec4ca2011-04-29 15:48:121288std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1289 const std::string& alias_name) {
1290 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1291}
1292
[email protected]b80f68432011-05-02 17:22:301293void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1294 CommandLine* command_line, int child_process_id) {
[email protected]97425082013-07-16 03:10:071295#if defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301296 if (IsCrashReporterEnabled()) {
1297 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1298 child_process_logging::GetClientId());
1299 }
[email protected]97425082013-07-16 03:10:071300#elif defined(OS_POSIX)
1301 if (IsCrashReporterEnabled()) {
1302 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1303 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1304 }
1305
[email protected]b80f68432011-05-02 17:22:301306#endif // OS_MACOSX
1307
[email protected]f1933792011-06-14 00:49:341308 if (logging::DialogsAreSuppressed())
1309 command_line->AppendSwitch(switches::kNoErrorDialogs);
1310
[email protected]b80f68432011-05-02 17:22:301311 std::string process_type =
1312 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171313 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321314
1315 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1316 command_line->AppendSwitch(switches::kChromeFrame);
1317
[email protected]718eab62011-10-05 21:16:521318 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451319 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301320 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1321 if (!user_data_dir.empty())
1322 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1323#if defined(OS_CHROMEOS)
1324 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441325 browser_command_line.GetSwitchValueASCII(
1326 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301327 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441328 command_line->AppendSwitchASCII(
1329 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301330#endif
1331
[email protected]f3b1a082011-11-18 00:34:301332 content::RenderProcessHost* process =
1333 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371334 if (process) {
1335 Profile* profile = Profile::FromBrowserContext(
1336 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131337 ExtensionService* extension_service =
1338 extensions::ExtensionSystem::Get(profile)->extension_service();
1339 if (extension_service) {
1340 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001341 if (process_map && process_map->Contains(process->GetID()))
1342 command_line->AppendSwitch(switches::kExtensionProcess);
1343 }
[email protected]b80f68432011-05-02 17:22:301344
[email protected]a8d851f82011-12-21 00:32:371345 PrefService* prefs = profile->GetPrefs();
1346 // Currently this pref is only registered if applied via a policy.
1347 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1348 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1349 // Turn this policy into a command line switch.
1350 command_line->AppendSwitch(switches::kDisable3DAPIs);
1351 }
[email protected]718eab62011-10-05 21:16:521352
[email protected]a8d851f82011-12-21 00:32:371353 // Disable client-side phishing detection in the renderer if it is
1354 // disabled in the Profile preferences or the browser process.
1355 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1356 !g_browser_process->safe_browsing_detection_service()) {
1357 command_line->AppendSwitch(
1358 switches::kDisableClientSidePhishingDetection);
1359 }
[email protected]0045b0f42012-07-26 11:52:081360
1361 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211362 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521363
1364 InstantService* instant_service =
1365 InstantServiceFactory::GetForProfile(profile);
1366 if (instant_service &&
1367 instant_service->IsInstantProcess(process->GetID()))
1368 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301369
[email protected]d5bcd06f2013-04-21 08:07:241370#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301371 SigninManager* signin_manager =
1372 SigninManagerFactory::GetForProfile(profile);
1373 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1374 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241375#endif
[email protected]47c7ec82012-01-18 03:29:211376 }
[email protected]4287a3d2011-06-13 23:56:511377
[email protected]87552982012-11-02 17:21:401378 if (content::IsThreadedCompositingEnabled())
1379 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1380
[email protected]16dc42452013-04-09 04:37:191381 if (message_center::IsRichNotificationEnabled())
1382 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191383
[email protected]47c7ec82012-01-18 03:29:211384 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511385 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171386 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481387 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171388 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]49d9b142013-07-19 08:50:271389 extensions::switches::kAllowLegacyExtensionManifests,
1390 extensions::switches::kAllowScriptingGallery,
1391 extensions::switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511392 switches::kAllowHTTPBackgroundPage,
[email protected]9d450492013-06-13 23:08:371393 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1394 // to browser.
1395 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511396 switches::kAppsCheckoutURL,
1397 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311398 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511399 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501400 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531401 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111402 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531403 switches::kEnableAdview,
1404 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441405 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211406 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511407 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511408 switches::kEnableIPCFuzzing,
1409 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451410 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481411 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051412 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511413 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511414 switches::kMemoryProfiling,
1415 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371416 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371417 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511418 switches::kPpapiFlashArgs,
1419 switches::kPpapiFlashInProcess,
1420 switches::kPpapiFlashPath,
1421 switches::kPpapiFlashVersion,
1422 switches::kProfilingAtStart,
1423 switches::kProfilingFile,
1424 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371425 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511426 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291427 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381428 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511429 };
1430
1431 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1432 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171433 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381434 static const char* const kSwitchNames[] = {
[email protected]49d9b142013-07-19 08:50:271435 extensions::switches::kExtensionsOnChromeURLs,
[email protected]eb653f82012-05-24 02:31:351436 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381437 switches::kEnableExperimentalExtensionApis,
1438 switches::kWhitelistedExtensionID,
1439 };
1440
1441 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1442 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511443 } else if (process_type == switches::kPluginProcess) {
1444 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441445#if defined(OS_CHROMEOS)
1446 chromeos::switches::kLoginProfile,
1447#endif
[email protected]4287a3d2011-06-13 23:56:511448 switches::kMemoryProfiling,
1449 switches::kSilentDumpOnDCHECK,
1450 switches::kUserDataDir,
1451 };
1452
1453 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1454 arraysize(kSwitchNames));
1455 } else if (process_type == switches::kZygoteProcess) {
1456 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511457 switches::kUserDataDir, // Make logs go to the right file.
1458 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501459 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511460 switches::kPpapiFlashInProcess,
1461 switches::kPpapiFlashPath,
1462 switches::kPpapiFlashVersion,
1463 };
1464
1465 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1466 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111467 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001468 base::FilePath user_data_dir =
1469 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1470 if (!user_data_dir.empty())
1471 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111472 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1473 // because GPU is expected to be unreliable.
1474 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1475 !command_line->HasSwitch(switches::kDisableBreakpad))
1476 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301477 }
[email protected]6f08af82011-09-15 01:19:031478
1479 // The command line switch kEnableBenchmarking needs to be specified along
1480 // with the kEnableStatsTable switch to ensure that the stats table global
1481 // is initialized correctly.
1482 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1483 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301484}
1485
1486std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431487 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351488 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301489 return g_browser_process->GetApplicationLocale();
1490}
1491
[email protected]597a867b2011-11-18 18:31:201492std::string ChromeContentBrowserClient::GetAcceptLangs(
1493 content::BrowserContext* context) {
1494 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371495 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081496}
1497
[email protected]9ec0f452012-05-31 15:58:531498gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221499 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531500 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081501}
1502
[email protected]a2176792011-05-08 19:30:491503bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091504 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191505 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201506 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201508 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051509 return io_data->GetCookieSettings()->
1510 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491511}
1512
[email protected]ed24fad2011-05-10 22:44:011513bool ChromeContentBrowserClient::AllowGetCookie(
1514 const GURL& url,
1515 const GURL& first_party,
1516 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201517 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011518 int render_process_id,
1519 int render_view_id) {
1520 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201521 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051522 bool allow = io_data->GetCookieSettings()->
1523 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011524
[email protected]8093a542011-05-13 07:29:321525 BrowserThread::PostTask(
1526 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031527 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431528 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011529 return allow;
1530}
1531
1532bool ChromeContentBrowserClient::AllowSetCookie(
1533 const GURL& url,
1534 const GURL& first_party,
1535 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201536 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011537 int render_process_id,
1538 int render_view_id,
1539 net::CookieOptions* options) {
1540 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201541 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051542 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1543 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1544
[email protected]8093a542011-05-13 07:29:321545 BrowserThread::PostTask(
1546 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031547 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431548 render_view_id, url, first_party, cookie_line, *options,
1549 !allow));
[email protected]ed24fad2011-05-10 22:44:011550 return allow;
1551}
1552
[email protected]d5a19162011-06-30 18:51:541553bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201554 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201556 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431557 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1558 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261559
[email protected]bf510ed2012-06-05 08:31:431560 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1561 // Could we even support per-origin settings?
1562 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541563}
1564
[email protected]5c5a88e2011-11-12 00:45:351565bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351566 const GURL& url,
1567 const string16& name,
1568 const string16& display_name,
1569 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201570 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481571 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201573 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351574 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1575 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1576
[email protected]62151052012-02-01 18:40:481577 // Record access to database for potential display in UI.
1578 std::vector<std::pair<int, int> >::const_iterator i;
1579 for (i = render_views.begin(); i != render_views.end(); ++i) {
1580 BrowserThread::PostTask(
1581 BrowserThread::UI, FROM_HERE,
1582 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1583 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351584 }
1585
1586 return allow;
1587}
1588
1589bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351590 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201591 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481592 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201594 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351595 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1596 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1597
[email protected]62151052012-02-01 18:40:481598 // Record access to file system for potential display in UI.
1599 std::vector<std::pair<int, int> >::const_iterator i;
1600 for (i = render_views.begin(); i != render_views.end(); ++i) {
1601 BrowserThread::PostTask(
1602 BrowserThread::UI, FROM_HERE,
1603 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1604 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351605 }
1606
1607 return allow;
1608}
1609
[email protected]7c5ff9a2012-03-02 07:42:491610bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1611 const GURL& url,
1612 const string16& name,
1613 content::ResourceContext* context,
1614 const std::vector<std::pair<int, int> >& render_views) {
1615 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1616 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1617 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1618 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1619
1620 // Record access to IndexedDB for potential display in UI.
1621 std::vector<std::pair<int, int> >::const_iterator i;
1622 for (i = render_views.begin(); i != render_views.end(); ++i) {
1623 BrowserThread::PostTask(
1624 BrowserThread::UI, FROM_HERE,
1625 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1626 i->first, i->second, url, name, !allow));
1627 }
1628
1629 return allow;
1630}
1631
[email protected]6133f922011-07-01 21:34:341632net::URLRequestContext*
1633ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201634 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341635 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421636 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201637 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341638 return io_data->extensions_request_context();
1639 }
1640
1641 return NULL;
1642}
1643
[email protected]317f96c92011-05-31 06:53:411644QuotaPermissionContext*
1645ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1646 return new ChromeQuotaPermissionContext();
1647}
1648
[email protected]848dd042011-06-04 18:24:031649void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171650 int render_process_id,
1651 int render_view_id,
1652 int cert_error,
1653 const net::SSLInfo& ssl_info,
1654 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021655 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031656 bool overridable,
[email protected]d9be47702012-05-16 03:41:221657 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171658 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001659 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021660 if (resource_type != ResourceType::MAIN_FRAME) {
1661 // A sub-resource has a certificate error. The user doesn't really
1662 // have a context for making the right decision, so block the
1663 // request hard, without an info bar to allow showing the insecure
1664 // content.
[email protected]8c965c22013-05-23 19:28:001665 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021666 return;
1667 }
1668
[email protected]f9034cf2011-07-21 12:43:411669 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131670 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171671 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411672 if (!tab) {
1673 NOTREACHED();
1674 return;
1675 }
1676 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501677 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301678 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011679 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1680 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411681 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171682 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411683 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001684 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411685 return;
1686 }
1687 }
1688
[email protected]1e87df32012-09-12 04:53:191689#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231690 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1691 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1692 if (captive_portal_tab_helper)
1693 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191694#endif
1695
[email protected]f9034cf2011-07-21 12:43:411696 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221697 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1698 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031699}
1700
[email protected]c99c442e2011-08-24 11:37:301701void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451702 int render_process_id,
1703 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401704 const net::HttpNetworkSession* network_session,
1705 net::SSLCertRequestInfo* cert_request_info,
1706 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131707 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451708 render_process_id, render_view_id);
1709 if (!tab) {
1710 NOTREACHED();
1711 return;
1712 }
1713
[email protected]6786bf402011-12-03 15:19:451714 GURL requesting_url("https://" + cert_request_info->host_and_port);
1715 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1716 << cert_request_info->host_and_port;
1717
[email protected]627e0512011-12-21 22:55:301718 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451719 scoped_ptr<Value> filter(
1720 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1721 requesting_url,
1722 requesting_url,
1723 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1724 std::string(), NULL));
1725
1726 if (filter.get()) {
1727 // Try to automatically select a client certificate.
1728 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1729 DictionaryValue* filter_dict =
1730 static_cast<DictionaryValue*>(filter.get());
1731
1732 const std::vector<scoped_refptr<net::X509Certificate> >&
1733 all_client_certs = cert_request_info->client_certs;
1734 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091735 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451736 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091737 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451738 return;
1739 }
1740 }
1741 } else {
1742 NOTREACHED();
1743 }
1744 }
1745
[email protected]11feec322012-09-18 03:58:521746 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1747 if (!ssl_tab_helper) {
1748 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451749 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141750 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401751 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451752 return;
1753 }
[email protected]11feec322012-09-18 03:58:521754 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401755 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451756}
1757
[email protected]3b455502012-12-11 18:22:581758void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451759 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581760 net::CertificateMimeType cert_type,
1761 const void* cert_data,
1762 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451763 int render_process_id,
1764 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581765 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1766 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451767}
1768
[email protected]dc73a7b2012-03-25 15:27:181769content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561770 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181771}
1772
[email protected]941623e2011-06-07 23:06:041773void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1774 const GURL& source_origin,
1775 int callback_context,
1776 int render_process_id,
1777 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111778#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021779 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1780 WebContents* contents =
1781 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1782 if (!contents) {
[email protected]941623e2011-06-07 23:06:041783 NOTREACHED();
1784 return;
1785 }
1786
[email protected]d0d9c3ee2012-06-19 03:07:021787 // Skip showing the infobar if the request comes from an extension, and that
1788 // extension has the 'notify' permission. (If the extension does not have the
1789 // permission, the user will still be prompted.)
1790 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011791 ExtensionInfoMap* extension_info_map =
1792 extensions::ExtensionSystem::Get(profile)->info_map();
1793 DesktopNotificationService* notification_service =
1794 DesktopNotificationServiceFactory::GetForProfile(profile);
1795 const Extension* extension = NULL;
1796 if (extension_info_map) {
1797 ExtensionSet extensions;
1798 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1799 source_origin, render_process_id,
1800 extensions::APIPermission::kNotification, &extensions);
1801 for (ExtensionSet::const_iterator iter = extensions.begin();
1802 iter != extensions.end(); ++iter) {
1803 if (notification_service->IsExtensionEnabled((*iter)->id())) {
[email protected]cadac622013-06-11 16:46:361804 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011805 break;
1806 }
1807 }
1808 }
[email protected]eb4832a2012-12-08 01:57:521809 RenderViewHost* rvh =
1810 RenderViewHost::FromID(render_process_id, render_view_id);
1811 if (IsExtensionWithPermissionOrSuggestInConsole(
1812 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021813 if (rvh)
1814 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1815 return;
1816 }
1817
[email protected]c7cd5942013-04-30 03:31:011818 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021819 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111820#else
1821 NOTIMPLEMENTED();
1822#endif
[email protected]941623e2011-06-07 23:06:041823}
1824
1825WebKit::WebNotificationPresenter::Permission
1826 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021827 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201828 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021829 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111830#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041831 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481832 // Sometimes a notification may be invoked during the shutdown.
1833 // See http://crbug.com/256638
1834 if (browser_shutdown::IsTryingToQuit())
1835 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
1836
[email protected]df02aca2012-02-09 21:03:201837 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041838
[email protected]c7cd5942013-04-30 03:31:011839 DesktopNotificationService* notification_service =
1840 io_data->GetNotificationService();
1841 if (notification_service) {
1842 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1843 ExtensionSet extensions;
1844 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1845 source_origin, render_process_id,
1846 extensions::APIPermission::kNotification, &extensions);
1847 for (ExtensionSet::const_iterator iter = extensions.begin();
1848 iter != extensions.end(); ++iter) {
1849 if (notification_service->IsExtensionEnabled((*iter)->id()))
1850 return WebKit::WebNotificationPresenter::PermissionAllowed;
1851 }
1852
1853 return notification_service->HasPermission(source_origin);
1854 }
1855
1856 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111857#else
1858 return WebKit::WebNotificationPresenter::PermissionAllowed;
1859#endif
[email protected]941623e2011-06-07 23:06:041860}
1861
1862void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171863 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041864 int render_process_id,
1865 int render_view_id,
1866 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111867#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041868 RenderViewHost* rvh = RenderViewHost::FromID(
1869 render_process_id, render_view_id);
1870 if (!rvh) {
1871 NOTREACHED();
1872 return;
1873 }
1874
[email protected]9f76c1e2012-03-05 15:15:581875 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301876 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041877 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371878 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041879 service->ShowDesktopNotification(
1880 params, render_process_id, render_view_id,
1881 worker ? DesktopNotificationService::WorkerNotification :
1882 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111883#else
1884 NOTIMPLEMENTED();
1885#endif
[email protected]941623e2011-06-07 23:06:041886}
1887
1888void ChromeContentBrowserClient::CancelDesktopNotification(
1889 int render_process_id,
1890 int render_view_id,
1891 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111892#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041893 RenderViewHost* rvh = RenderViewHost::FromID(
1894 render_process_id, render_view_id);
1895 if (!rvh) {
1896 NOTREACHED();
1897 return;
1898 }
1899
[email protected]9f76c1e2012-03-05 15:15:581900 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301901 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041902 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371903 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041904 service->CancelDesktopNotification(
1905 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111906#else
1907 NOTIMPLEMENTED();
1908#endif
[email protected]941623e2011-06-07 23:06:041909}
1910
[email protected]9f3fba52011-06-08 20:37:191911bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351912 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021913 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191914 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201915 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011916 int render_process_id,
1917 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011919
1920 *no_javascript_access = false;
1921
[email protected]9f3fba52011-06-08 20:37:191922 // If the opener is trying to create a background window but doesn't have
1923 // the appropriate permission, fail the attempt.
1924 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201925 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531926 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1927
[email protected]03b6d552012-03-29 04:03:011928 if (!map->SecurityOriginHasAPIPermission(
1929 source_origin,
1930 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061931 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011932 return false;
1933 }
1934
[email protected]7b54ca02012-03-02 18:06:531935 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1936 // return a recently installed Extension even if this CanCreateWindow call
1937 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011938 // because the permission check above would have caused an early return
1939 // already. We must use the full URL to find hosted apps, though, and not
1940 // just the origin.
[email protected]be9915fb2013-07-18 09:28:551941 const Extension* extension =
1942 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:291943 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011944 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191945 }
[email protected]056efdc2013-04-06 00:14:531946
1947 // No new browser window (popup or tab) in app mode.
1948 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1949 chrome::IsRunningInForcedAppMode()) {
1950 return false;
1951 }
1952
[email protected]9f3fba52011-06-08 20:37:191953 return true;
1954}
1955
1956std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201957 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191958 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1959 // Check if it's an extension-created worker, in which case we want to use
1960 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201961 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191962 const Extension* extension =
1963 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1964 return extension ? extension->name() : std::string();
1965}
1966
[email protected]99907362012-01-11 05:41:401967void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1968 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171969}
1970
[email protected]7a06d282013-05-03 04:39:331971// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021972content::SpeechRecognitionManagerDelegate*
1973 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:001974#if defined(ENABLE_INPUT_SPEECH)
1975 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:321976#else
[email protected]855e18b2013-07-08 21:02:001977 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
1978 // need the base delegate without the bubble UI.
1979 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321980#endif
[email protected]66cfec62012-02-24 17:57:511981}
1982
[email protected]ae6e9912011-07-27 01:18:281983net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1984 return g_browser_process->net_log();
1985}
1986
[email protected]32538d92011-08-25 00:09:231987AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1988 return new ChromeAccessTokenStore();
1989}
1990
[email protected]dbae6b02011-06-29 23:51:411991bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011992 return true;
[email protected]dbae6b02011-06-29 23:51:411993}
1994
[email protected]64d69de42012-02-06 00:19:541995void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321996 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061997 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581998 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061999 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062000
[email protected]f3986f82012-01-03 20:00:062001 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542002 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062003 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542004 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062005 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542006 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062007 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542008 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062009 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542010 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062011 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542012 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032013 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2014 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:062015
[email protected]64d69de42012-02-06 00:19:542016 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402017 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542018 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402019 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542020 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402021 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542022 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402023 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062024
[email protected]ddf72142012-05-22 04:52:402025 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062026
[email protected]64d69de42012-02-06 00:19:542027 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402028 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542029 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062030 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542031 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062032 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2033 const DictionaryValue* inspector_settings =
2034 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2035 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182036 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2037 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062038 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182039 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542040 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182041 std::make_pair(iter.key(), value));
2042 }
[email protected]f3986f82012-01-03 20:00:062043 }
2044 }
[email protected]64d69de42012-02-06 00:19:542045 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062046
[email protected]ddf72142012-05-22 04:52:402047 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542048 web_prefs->javascript_enabled = false;
2049 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2050 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402051 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542052 web_prefs->plugins_enabled = false;
2053 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2054 web_prefs->java_enabled = false;
2055 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402056 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062057
[email protected]64d69de42012-02-06 00:19:542058 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2059 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062060
[email protected]64d69de42012-02-06 00:19:542061 web_prefs->memory_info_enabled =
2062 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2063 web_prefs->allow_displaying_insecure_content =
2064 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2065 web_prefs->allow_running_insecure_content =
2066 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322067#if defined(OS_ANDROID)
2068 web_prefs->font_scale_factor =
2069 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2070 web_prefs->force_enable_zoom =
2071 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:452072#if defined(GOOGLE_TV)
2073 web_prefs->user_gesture_required_for_media_playback = false;
2074#endif
[email protected]d3b935f2012-10-19 23:14:322075#endif
[email protected]5c915252013-05-07 13:15:392076
[email protected]af4256d52013-06-04 20:39:072077#if defined(OS_ANDROID)
2078 web_prefs->password_echo_enabled =
2079 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2080#else
[email protected]9d06d88d2012-02-23 22:37:082081 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072082#endif
2083
[email protected]5c915252013-05-07 13:15:392084#if defined(OS_CHROMEOS)
2085 // Enable password echo during OOBE when keyboard driven flag is set.
2086 if (chromeos::UserManager::IsInitialized() &&
2087 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
2088 !chromeos::StartupUtils::IsOobeCompleted()) {
2089 bool keyboard_driven_oobe = false;
2090 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]0071aed32013-06-19 13:39:552091 chromeos::system::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:392092 if (keyboard_driven_oobe)
2093 web_prefs->password_echo_enabled = true;
2094 }
2095#endif
[email protected]f3986f82012-01-03 20:00:062096
[email protected]46f8e742013-05-03 18:37:142097#if defined(OS_ANDROID)
2098 web_prefs->user_style_sheet_enabled = false;
2099#else
[email protected]64d69de42012-02-06 00:19:542100 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152101 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362102 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152103 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542104 web_prefs->user_style_sheet_enabled = true;
2105 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152106 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542107 } else {
2108 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062109 }
[email protected]46f8e742013-05-03 18:37:142110#endif
[email protected]f3986f82012-01-03 20:00:062111
[email protected]cfadadd2013-04-03 04:43:022112 web_prefs->asynchronous_spell_checking_enabled = true;
2113 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572114
[email protected]64d69de42012-02-06 00:19:542115 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062116 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542117 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062118 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542119 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062120 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2121
2122 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542123 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062124 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542125 web_prefs->default_encoding);
2126 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402127 prefs->ClearPref(prefs::kDefaultCharset);
2128 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062129 }
[email protected]64d69de42012-02-06 00:19:542130 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062131
[email protected]88ecf66d2012-12-11 22:53:472132 if (content::IsForceCompositingModeEnabled())
2133 web_prefs->force_compositing_mode = true;
2134
[email protected]299d7f12012-05-23 05:31:152135 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232136 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132137 ExtensionService* service =
2138 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062139 if (service) {
[email protected]1bc28312012-11-08 08:31:532140 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2141 const Extension* extension = service->extensions()->GetByID(url.host());
2142 // Ensure that we are only granting extension preferences to URLs with
2143 // the correct scheme. Without this check, chrome-guest:// schemes used by
2144 // webview tags as well as hosts that happen to match the id of an
2145 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422146 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532147 extension_webkit_preferences::SetPreferences(
2148 extension, view_type, web_prefs);
2149 }
[email protected]f3986f82012-01-03 20:00:062150 }
2151
[email protected]cb2edf22013-04-01 20:25:232152 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542153 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232154 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062155 // Disable all kinds of acceleration for background pages.
2156 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542157 web_prefs->force_compositing_mode = false;
2158 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062159 }
[email protected]2e21fe292012-03-02 22:52:322160
2161#if defined(FILE_MANAGER_EXTENSION)
2162 // Override the default of suppressing HW compositing for WebUI pages for the
2163 // file manager, which is implemented using WebUI but wants HW acceleration
2164 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532165 if (url.SchemeIs(extensions::kExtensionScheme) &&
2166 url.host() == kFileBrowserDomain) {
[email protected]2e21fe292012-03-02 22:52:322167 web_prefs->accelerated_compositing_enabled = true;
2168 web_prefs->accelerated_2d_canvas_enabled = true;
2169 }
2170#endif
[email protected]181a95ee2011-07-12 19:26:362171}
2172
2173void ChromeContentBrowserClient::UpdateInspectorSetting(
2174 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062175 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582176 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062177 DictionaryPrefUpdate update(
2178 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2179 prefs::kWebKitInspectorSettings);
2180 DictionaryValue* inspector_settings = update.Get();
2181 inspector_settings->SetWithoutPathExpansion(key,
2182 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362183}
2184
[email protected]b8148ac2011-07-13 22:03:252185void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2186 BrowserURLHandler* handler) {
2187 // Add the default URL handlers.
2188 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2189 BrowserURLHandler::null_handler());
2190 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2191 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2192
[email protected]b3adbd02011-11-30 22:23:272193 // about: handler. Must come before chrome: handler, since it will
2194 // rewrite about: urls to chrome: URLs and then expect chrome: to
2195 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252196 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2197 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032198
2199 // Handler to rewrite chrome://newtab for InstantExtended.
2200 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2201 &chrome::HandleNewTabURLReverseRewrite);
2202
[email protected]b8148ac2011-07-13 22:03:252203 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242204 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252205}
2206
2207void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372208 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582209 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472210 BrowsingDataRemover* remover =
2211 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552212 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2213 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252214 // BrowsingDataRemover takes care of deleting itself when done.
2215}
2216
2217void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372218 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582219 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472220 BrowsingDataRemover* remover =
2221 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232222 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552223 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252224 // BrowsingDataRemover takes care of deleting itself when done.
2225}
2226
[email protected]650b2d52013-02-10 03:41:452227base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322228 return download_util::GetDefaultDownloadDirectory();
2229}
2230
[email protected]c9b6eb62011-10-18 20:49:392231std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2232 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2233}
2234
[email protected]b7631cc2012-09-15 05:08:382235void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2236 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542237#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382238 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2239 scoped_ptr<ppapi::host::HostFactory>(
2240 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542241#endif
[email protected]b7631cc2012-09-15 05:08:382242}
2243
[email protected]0c7193742012-11-07 19:05:032244content::BrowserPpapiHost*
2245 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2246 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132247 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032248 while (!iter.Done()) {
2249 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2250 if (host->process() &&
2251 host->process()->GetData().id == plugin_process_id) {
2252 // Found the plugin.
2253 return host->browser_ppapi_host();
2254 }
2255 ++iter;
2256 }
2257 return NULL;
2258}
2259
[email protected]7b38b192013-03-23 18:39:312260bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2261 content::BrowserContext* browser_context, const GURL& site_url) {
2262 if (CommandLine::ForCurrentProcess()->HasSwitch(
2263 switches::kEnableBrowserPluginForAllViewTypes))
2264 return true;
2265
2266 Profile* profile = Profile::FromBrowserContext(browser_context);
2267 ExtensionService* service =
2268 extensions::ExtensionSystem::Get(profile)->extension_service();
2269 if (!service)
2270 return false;
2271
[email protected]be9915fb2013-07-18 09:28:552272 const Extension* extension =
2273 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312274 if (!extension)
2275 return false;
2276
[email protected]c2d2f102013-04-29 16:42:582277 return extension->HasAPIPermission(APIPermission::kWebView) ||
2278 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312279}
2280
[email protected]38cd8f7f2012-06-15 22:06:072281bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582282 content::BrowserContext* browser_context,
2283 const GURL& url,
[email protected]dda54822013-06-15 01:26:392284 bool private_api,
[email protected]157cc902012-11-02 06:31:582285 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402286#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372287 Profile* profile = Profile::FromBrowserContext(browser_context);
2288 const ExtensionSet* extension_set = NULL;
2289 if (profile) {
2290 extension_set = extensions::ExtensionSystem::Get(profile)->
2291 extension_service()->extensions();
2292 }
[email protected]dda54822013-06-15 01:26:392293
2294 if (private_api) {
2295 // Access to private socket APIs is controlled by the whitelist.
2296 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2297 allowed_socket_origins_)) {
2298 return true;
2299 }
2300 } else {
2301 // Access to public socket APIs is controlled by extension permissions.
2302 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2303 extension_set) {
2304 const Extension* extension = extension_set->GetByID(url.host());
2305 if (extension) {
2306 extensions::SocketPermission::CheckParam check_params(
2307 params.type, params.host, params.port);
2308 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2309 extension, extensions::APIPermission::kSocket, &check_params)) {
2310 return true;
2311 }
2312 }
2313 }
2314 }
2315
2316 // Allow both public and private APIs if the command line says so.
2317 return IsHostAllowedByCommandLine(url, extension_set,
2318 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402319#else
[email protected]a658d452012-03-02 12:45:292320 return false;
[email protected]93f72062013-05-29 20:29:402321#endif
[email protected]e461da2f2012-02-16 19:06:402322}
2323
[email protected]650b2d52013-02-10 03:41:452324base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2325 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142326 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2327 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2328}
2329
[email protected]a28e3302013-02-03 03:50:432330ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2331 WebContents* web_contents) {
2332 return new ChromeSelectFilePolicy(web_contents);
2333}
2334
[email protected]7d9424702013-04-14 13:14:162335void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2336 std::vector<std::string>* additional_allowed_schemes) {
2337 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2338 additional_allowed_schemes);
2339 additional_allowed_schemes->push_back(kChromeUIScheme);
2340 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2341}
2342
[email protected]f19bbf62013-07-09 01:22:322343void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312344 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532345 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322346 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532347#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032348 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322349 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032350 storage_partition_path,
2351 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322352 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532353#endif
[email protected]b40015c2013-06-26 08:13:312354#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312355 fileapi::ExternalMountPoints* external_mount_points =
2356 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312357 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322358 chromeos::FileSystemBackend* backend =
2359 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312360 new drive::FileSystemBackendDelegate(browser_context),
2361 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312362 external_mount_points,
2363 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322364 backend->AddSystemMountPoints();
2365 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2366 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312367#endif
[email protected]02250952013-04-24 23:52:532368}
2369
[email protected]e60c0232011-11-11 19:56:352370#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182371void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2372 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382373 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082374 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392375#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452376 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392377 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2378 DCHECK(!data_path.empty());
2379
2380 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452381 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392382 base::PlatformFile f =
2383 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2384 DCHECK(f != base::kInvalidPlatformFileValue);
2385 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2386 FileDescriptor(f, true)));
2387
[email protected]650b2d52013-02-10 03:41:452388 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392389 data_path.AppendASCII("chrome_100_percent.pak");
2390 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2391 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372392 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392393 FileDescriptor(f, true)));
2394
2395 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452396 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392397 GetLocaleFilePath(locale, false);
2398 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2399 DCHECK(f != base::kInvalidPlatformFileValue);
2400 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2401 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382402
[email protected]650b2d52013-02-10 03:41:452403 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372404 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2405 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2406 DCHECK(f != base::kInvalidPlatformFileValue);
2407 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2408 FileDescriptor(f, true)));
2409
[email protected]82174aa2013-01-22 21:53:432410 if (IsCrashReporterEnabled()) {
2411 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2412 if (f == base::kInvalidPlatformFileValue) {
2413 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2414 "be disabled for this process.";
2415 } else {
2416 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2417 FileDescriptor(f, true)));
2418 }
[email protected]40da3e0c2012-10-24 22:03:382419 }
[email protected]40da3e0c2012-10-24 22:03:382420
2421#else
2422 int crash_signal_fd = GetCrashSignalFD(command_line);
2423 if (crash_signal_fd >= 0) {
2424 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2425 FileDescriptor(crash_signal_fd,
2426 false)));
2427 }
[email protected]29699c22012-10-03 23:57:392428#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302429}
[email protected]e60c0232011-11-11 19:56:352430#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302431
[email protected]4a65826d2011-08-25 16:04:012432#if defined(OS_WIN)
2433const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2434 return chrome::kBrowserResourcesDll;
2435}
[email protected]34f48682013-03-20 00:30:182436
2437void ChromeContentBrowserClient::PreSpawnRenderer(
2438 sandbox::TargetPolicy* policy,
2439 bool* success) {
2440 // This code is duplicated in nacl_exe_win_64.cc.
2441 // Allow the server side of a pipe restricted to the "chrome.nacl."
2442 // namespace so that it cannot impersonate other system or other chrome
2443 // service pipes.
2444 sandbox::ResultCode result = policy->AddRule(
2445 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2446 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2447 L"\\\\.\\pipe\\chrome.nacl.*");
2448 if (result != sandbox::SBOX_ALL_OK) {
2449 *success = false;
2450 return;
2451 }
2452
2453 // Renderers need to send named pipe handles and shared memory
2454 // segment handles to NaCl loader processes.
2455 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2456 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2457 L"File");
2458 if (result != sandbox::SBOX_ALL_OK) {
2459 *success = false;
2460 return;
2461 }
2462}
[email protected]4a65826d2011-08-25 16:04:012463#endif
2464
[email protected]37a72af2011-06-13 05:42:012465#if defined(USE_NSS)
2466crypto::CryptoModuleBlockingPasswordDelegate*
2467 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2468 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292469 return chrome::NewCryptoModuleBlockingDialogDelegate(
2470 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012471}
2472#endif
2473
[email protected]d977f9c2011-03-14 16:10:262474} // namespace chrome