blob: 2dad6ffe20865c807cab668f0853019de81d62fc [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]593d2a72013-07-26 08:48:38240using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39241
[email protected]c5dbef02011-05-13 05:06:09242namespace {
243
[email protected]eabbfb12013-04-05 23:28:35244// Cached version of the locale so we can return the locale on the I/O
245// thread.
246base::LazyInstance<std::string> g_io_thread_application_locale;
247
[email protected]93f72062013-05-29 20:29:40248#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40249const char* kPredefinedAllowedSocketOrigins[] = {
250 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18251 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45252 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
253 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
254 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
255 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35256 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54257 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
258 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
259 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
260 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
261 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
262 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38263 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58264 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29265 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]f6599915a2013-06-20 20:03:50266 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
[email protected]b71313232013-05-06 06:16:29267 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
268 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
269 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
270 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40271};
[email protected]93f72062013-05-29 20:29:40272#endif
[email protected]e461da2f2012-02-16 19:06:40273
[email protected]f8f93eb2012-09-25 03:06:24274// Returns a copy of the given url with its host set to given host and path set
275// to given path. Other parts of the url will be the same.
276GURL ReplaceURLHostAndPath(const GURL& url,
277 const std::string& host,
278 const std::string& path) {
279 url_canon::Replacements<char> replacements;
280 replacements.SetHost(host.c_str(),
281 url_parse::Component(0, host.length()));
282 replacements.SetPath(path.c_str(),
283 url_parse::Component(0, path.length()));
284 return url.ReplaceComponents(replacements);
285}
286
287// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
288GURL AddUberHost(const GURL& url) {
289 const std::string uber_host = chrome::kChromeUIUberHost;
290 const std::string new_path = url.host() + url.path();
291
292 return ReplaceURLHostAndPath(url, uber_host, new_path);
293}
294
[email protected]045bf7c2012-09-28 20:27:36295// If url->host() is "chrome" and url->path() has characters other than the
296// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
297// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24298bool RemoveUberHost(GURL* url) {
299 if (url->host() != chrome::kChromeUIUberHost)
300 return false;
301
[email protected]045bf7c2012-09-28 20:27:36302 if (url->path().empty() || url->path() == "/")
303 return false;
304
[email protected]f8f93eb2012-09-25 03:06:24305 const std::string old_path = url->path();
306
307 const std::string::size_type separator = old_path.find('/', 1);
308 std::string new_host;
309 std::string new_path;
310 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36311 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24312 } else {
313 new_host = old_path.substr(1, separator - 1);
314 new_path = old_path.substr(separator);
315 }
316
[email protected]44e8add2013-06-13 17:29:15317 // Do not allow URLs with paths empty before the first slash since we can't
318 // have an empty host. (e.g "foo://chrome//")
319 if (new_host.empty())
320 return false;
321
[email protected]f8f93eb2012-09-25 03:06:24322 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
323
[email protected]44e8add2013-06-13 17:29:15324 DCHECK(url->is_valid());
325
[email protected]f8f93eb2012-09-25 03:06:24326 return true;
327}
328
[email protected]b8148ac2011-07-13 22:03:25329// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42330bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24331 // Do not handle special URLs such as "about:foo"
332 if (!url->host().empty()) {
333 const GURL chrome_url = AddUberHost(*url);
334
335 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
336 // be called.
337 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
338 browser_context, chrome_url))
339 return true;
340 }
341
[email protected]863f70a2012-01-27 02:05:50342 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
343 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25344 return false;
345
[email protected]fe69558d2012-03-12 11:34:49346#if defined(OS_CHROMEOS)
347 // Special case : in ChromeOS in Guest mode bookmarks and history are
348 // disabled for security reasons. New tab page explains the reasons, so
349 // we redirect user to new tab page.
350 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
351 if (url->SchemeIs(chrome::kChromeUIScheme) &&
352 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
353 url->DomainIs(chrome::kChromeUIHistoryHost))) {
354 // Rewrite with new tab URL
355 *url = GURL(chrome::kChromeUINewTabURL);
356 }
357 }
358#endif
359
[email protected]b8148ac2011-07-13 22:03:25360 // Special case the new tab page. In older versions of Chrome, the new tab
361 // page was hosted at chrome-internal:<blah>. This might be in people's saved
362 // sessions or bookmarks, so we say any URL with that scheme triggers the new
363 // tab page.
364 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
365 // Rewrite it with the proper new tab URL.
366 *url = GURL(chrome::kChromeUINewTabURL);
367 }
368
369 return true;
370}
371
[email protected]f8f93eb2012-09-25 03:06:24372// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
373// "chrome://foo/".
374bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
375 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
376 return false;
377
378 return RemoveUberHost(url);
379}
380
[email protected]8d3132f62011-10-12 07:13:42381// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
382// below. Extension, and isolated apps require different privileges to be
383// granted to their RenderProcessHosts. This classification allows us to make
384// sure URLs are served by hosts with the right set of privileges.
385enum RenderProcessHostPrivilege {
386 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45387 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42388 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45389 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42390};
391
392RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
393 const GURL& url,
394 ExtensionService* service) {
395 // Default to a normal renderer cause it is lower privileged. This should only
396 // occur if the URL on a site instance is either malformed, or uninitialized.
397 // If it is malformed, then there is no need for better privileges anyways.
398 // If it is uninitialized, but eventually settles on being an a scheme other
399 // than normal webrenderer, the navigation logic will correct us out of band
400 // anyways.
401 if (!url.is_valid())
402 return PRIV_NORMAL;
403
[email protected]885c0e92012-11-13 20:27:42404 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44405 const Extension* extension =
406 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43407 if (extension &&
408 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42409 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45410 if (extension && extension->is_hosted_app())
411 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42412
413 return PRIV_EXTENSION;
414 }
415
416 return PRIV_NORMAL;
417}
418
419RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30420 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46421 extensions::ProcessMap* process_map,
422 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46423 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30424 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46425 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21426 return PRIV_NORMAL;
427
[email protected]6f371442011-11-09 06:45:46428 for (std::set<std::string>::iterator iter = extension_ids.begin();
429 iter != extension_ids.end(); ++iter) {
430 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43431 if (extension &&
432 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42433 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45434 if (extension && extension->is_hosted_app())
435 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42436 }
437
[email protected]676f6ab2011-10-19 20:23:21438 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42439}
440
[email protected]6786bf402011-12-03 15:19:45441bool CertMatchesFilter(const net::X509Certificate& cert,
442 const base::DictionaryValue& filter) {
443 // TODO(markusheintz): This is the minimal required filter implementation.
444 // Implement a better matcher.
445
446 // An empty filter matches any client certificate since no requirements are
447 // specified at all.
448 if (filter.empty())
449 return true;
450
451 std::string common_name;
452 if (filter.GetString("ISSUER.CN", &common_name) &&
453 (cert.issuer().common_name == common_name)) {
454 return true;
455 }
456 return false;
457}
458
[email protected]f3986f82012-01-03 20:00:06459// Fills |map| with the per-script font prefs under path |map_name|.
460void FillFontFamilyMap(const PrefService* prefs,
461 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53462 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06463 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
464 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
465 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
466 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23467 if (!font_family.empty())
468 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06469 }
470}
471
[email protected]a1733df2012-06-22 11:24:18472#if defined(OS_POSIX) && !defined(OS_MACOSX)
473int GetCrashSignalFD(const CommandLine& command_line) {
474 if (command_line.HasSwitch(switches::kExtensionProcess)) {
475 ExtensionCrashHandlerHostLinux* crash_handler =
476 ExtensionCrashHandlerHostLinux::GetInstance();
477 return crash_handler->GetDeathSignalSocket();
478 }
479
480 std::string process_type =
481 command_line.GetSwitchValueASCII(switches::kProcessType);
482
483 if (process_type == switches::kRendererProcess)
484 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
485
486 if (process_type == switches::kPluginProcess)
487 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
488
489 if (process_type == switches::kPpapiPluginProcess)
490 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
491
492 if (process_type == switches::kGpuProcess)
493 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
494
495 return -1;
496}
497#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
498
[email protected]d5bcd06f2013-04-21 08:07:24499#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30500GURL GetEffectiveURLForSignin(const GURL& url) {
501 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
502
503 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03504 // Copy the path because the argument to SetPathStr must outlive
505 // the Replacements object.
506 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30507 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03508 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30509 effective_url = effective_url.ReplaceComponents(replacements);
510 return effective_url;
511}
[email protected]d5bcd06f2013-04-21 08:07:24512#endif
[email protected]970c63e2013-03-07 00:25:30513
[email protected]eabbfb12013-04-05 23:28:35514void SetApplicationLocaleOnIOThread(const std::string& locale) {
515 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
516 g_io_thread_application_locale.Get() = locale;
517}
518
[email protected]9dbfff12011-07-01 19:37:07519} // namespace
[email protected]c5dbef02011-05-13 05:06:09520
[email protected]d977f9c2011-03-14 16:10:26521namespace chrome {
522
[email protected]e461da2f2012-02-16 19:06:40523ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40524#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40525 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
526 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40527#endif
[email protected]1deace22013-05-22 06:14:46528
529 permissions_policy_delegate_.reset(
530 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40531}
532
533ChromeContentBrowserClient::~ChromeContentBrowserClient() {
534}
535
[email protected]bca18382012-06-25 19:15:23536// static
[email protected]37ca3fe02013-07-05 15:32:44537void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34538 user_prefs::PrefRegistrySyncable* registry) {
539 registry->RegisterBooleanPref(
540 prefs::kDisable3DAPIs,
541 false,
542 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
543 registry->RegisterBooleanPref(
544 prefs::kEnableHyperlinkAuditing,
545 true,
546 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
547 registry->RegisterBooleanPref(
548 prefs::kEnableMemoryInfo,
549 false,
550 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23551}
552
[email protected]eabbfb12013-04-05 23:28:35553// static
554void ChromeContentBrowserClient::SetApplicationLocale(
555 const std::string& locale) {
556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
557
558 // This object is guaranteed to outlive all threads so we don't have to
559 // worry about the lack of refcounting and can just post as Unretained.
560 //
561 // The common case is that this function is called early in Chrome startup
562 // before any threads are created (it will also be called later if the user
563 // changes the pref). In this case, there will be no threads created and
564 // posting will fail. When there are no threads, we can just set the string
565 // without worrying about threadsafety.
566 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
567 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
568 g_io_thread_application_locale.Get() = locale;
569 }
570}
571
[email protected]50462bf02011-11-21 19:13:31572content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
573 const content::MainFunctionParams& parameters) {
574 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30575 // Construct the Main browser parts based on the OS type.
576#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31577 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04578#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31579 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30580#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22581 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26582#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31583 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14584#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09585 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30586#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31587 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04588#else
[email protected]b48c9182011-10-26 18:03:30589 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31590 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30591#endif
592
[email protected]7e75e4a2013-05-17 17:20:03593 chrome::AddProfilesExtraParts(main_parts);
594
[email protected]c7480942011-11-08 19:18:27595 // Construct additional browser parts. Stages are called in the order in
596 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22597#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51598 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04599#endif
[email protected]c7480942011-11-08 19:18:27600
601#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51602 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27603#endif
604
[email protected]dc04be7c2012-03-15 23:57:49605#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51606 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49607#endif
608
[email protected]e050ef142012-03-21 01:04:24609#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51610 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
611#endif
612
613#if defined(USE_X11)
614 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24615#endif
616
[email protected]95132f52013-04-12 02:19:04617 chrome::AddMetricsExtraParts(main_parts);
618
[email protected]50462bf02011-11-21 19:13:31619 return main_parts;
[email protected]f967b722011-09-07 00:58:04620}
621
[email protected]e94bbcb2012-09-07 05:33:57622std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19623 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57624 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53625 std::string partition_id;
626
627 // The partition ID for webview guest processes is the string value of its
628 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
629 if (site.SchemeIs(chrome::kGuestScheme))
630 partition_id = site.spec();
631
[email protected]056efdc2013-04-06 00:14:53632 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53633 return partition_id;
634}
635
636bool ChromeContentBrowserClient::IsValidStoragePartitionId(
637 content::BrowserContext* browser_context,
638 const std::string& partition_id) {
639 // The default ID is empty and is always valid.
640 if (partition_id.empty())
641 return true;
642
643 return GURL(partition_id).is_valid();
644}
645
646void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
647 content::BrowserContext* browser_context,
648 const GURL& site,
[email protected]14acc642012-11-17 12:20:10649 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53650 std::string* partition_domain,
651 std::string* partition_name,
652 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10653 // Default to the browser-wide storage partition and override based on |site|
654 // below.
655 partition_domain->clear();
656 partition_name->clear();
657 *in_memory = false;
658
[email protected]1bc28312012-11-08 08:31:53659 // For the webview tag, we create special guest processes, which host the
660 // tag content separately from the main application that embeds the tag.
661 // A webview tag can specify both the partition name and whether the storage
662 // for that partition should be persisted. Each tag gets a SiteInstance with
663 // a specially formatted URL, based on the application it is hosted by and
664 // the partition requested by it. The format for that URL is:
665 // chrome-guest://partition_domain/persist?partition_name
666 if (site.SchemeIs(chrome::kGuestScheme)) {
667 // Since guest URLs are only used for packaged apps, there must be an app
668 // id in the URL.
669 CHECK(site.has_host());
670 *partition_domain = site.host();
671 // Since persistence is optional, the path must either be empty or the
672 // literal string.
673 *in_memory = (site.path() != "/persist");
674 // The partition name is user supplied value, which we have encoded when the
675 // URL was created, so it needs to be decoded.
676 *partition_name = net::UnescapeURLComponent(site.query(),
677 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10678 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
679 // If |can_be_default| is false, the caller is stating that the |site|
680 // should be parsed as if it had isolated storage. In particular it is
681 // important to NOT check ExtensionService for the is_storage_isolated()
682 // attribute because this code path is run during Extension uninstall
683 // to do cleanup after the Extension has already been unloaded from the
684 // ExtensionService.
685 bool is_isolated = !can_be_default;
686 if (can_be_default) {
687 const Extension* extension = NULL;
688 Profile* profile = Profile::FromBrowserContext(browser_context);
689 ExtensionService* extension_service =
690 extensions::ExtensionSystem::Get(profile)->extension_service();
691 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55692 extension =
693 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43694 if (extension &&
695 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10696 is_isolated = true;
697 }
698 }
699 }
[email protected]1bc28312012-11-08 08:31:53700
[email protected]14acc642012-11-17 12:20:10701 if (is_isolated) {
702 CHECK(site.has_host());
703 // For extensions with isolated storage, the the host of the |site| is
704 // the |partition_domain|. The |in_memory| and |partition_name| are only
705 // used in guest schemes so they are cleared here.
706 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53707 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10708 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53709 }
[email protected]d1198fd2012-08-13 22:50:19710 }
711
[email protected]14acc642012-11-17 12:20:10712 // Assert that if |can_be_default| is false, the code above must have found a
713 // non-default partition. If this fails, the caller has a serious logic
714 // error about which StoragePartition they expect to be in and it is not
715 // safe to continue.
716 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44717}
718
[email protected]38b098f2012-03-14 21:11:57719content::WebContentsViewDelegate*
720 ChromeContentBrowserClient::GetWebContentsViewDelegate(
721 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27722 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32723}
724
[email protected]24665682013-02-25 20:59:38725// Check if the extension activity log is enabled for the profile.
726static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33727 // crbug.com/247908 - This should be IsLogEnabled except for an issue
728 // in chrome_frame_net_tests
729 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38730}
731
[email protected]738f57a2013-06-29 21:06:54732void ChromeContentBrowserClient::GuestWebContentsCreated(
733 WebContents* guest_web_contents,
734 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22735 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54736 scoped_ptr<base::DictionaryValue> extra_params) {
737 if (opener_web_contents) {
738 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
739 if (!guest) {
740 NOTREACHED();
741 return;
742 }
743
744 switch (guest->GetViewType()) {
745 case GuestView::WEBVIEW: {
[email protected]4c0e8272013-07-03 23:39:22746 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54747 break;
748 }
749 case GuestView::ADVIEW: {
[email protected]4c0e8272013-07-03 23:39:22750 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54751 break;
752 }
753 default:
754 NOTREACHED();
755 break;
756 }
757 return;
758 }
759
760 if (!extra_params) {
761 NOTREACHED();
762 return;
763 }
764 std::string api_type;
765 extra_params->GetString(guestview::kAttributeApi, &api_type);
766
767 if (api_type == "adview") {
[email protected]4c0e8272013-07-03 23:39:22768 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54769 } else if (api_type == "webview") {
[email protected]4c0e8272013-07-03 23:39:22770 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54771 } else {
772 NOTREACHED();
773 }
774}
775
[email protected]44295a12013-06-05 08:45:46776void ChromeContentBrowserClient::GuestWebContentsAttached(
777 WebContents* guest_web_contents,
778 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53779 int browser_plugin_instance_id,
780 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06781 Profile* profile = Profile::FromBrowserContext(
782 embedder_web_contents->GetBrowserContext());
783 ExtensionService* service =
784 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54785 if (!service) {
786 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06787 return;
[email protected]738f57a2013-06-29 21:06:54788 }
[email protected]44703cc72013-01-24 04:56:06789 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
[email protected]be9915fb2013-07-18 09:28:55790 const Extension* extension =
791 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]738f57a2013-06-29 21:06:54792 if (!extension) {
[email protected]18699372013-06-25 20:42:55793 NOTREACHED();
[email protected]738f57a2013-06-29 21:06:54794 return;
[email protected]18699372013-06-25 20:42:55795 }
[email protected]738f57a2013-06-29 21:06:54796
797 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
798 if (!guest) {
799 NOTREACHED();
800 return;
801 }
802 guest->Attach(embedder_web_contents,
803 extension->id(),
804 browser_plugin_instance_id,
805 extra_params);
[email protected]44703cc72013-01-24 04:56:06806}
807
[email protected]f3b1a082011-11-18 00:34:30808void ChromeContentBrowserClient::RenderProcessHostCreated(
809 content::RenderProcessHost* host) {
810 int id = host->GetID();
811 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41812 net::URLRequestContextGetter* context =
813 profile->GetRequestContextForRenderProcess(id);
814
[email protected]f3b1a082011-11-18 00:34:30815 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41816 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55817#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30818 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55819#endif
[email protected]658677f2012-06-09 06:04:02820#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08821 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03822#endif
[email protected]f3b1a082011-11-18 00:34:30823 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02824 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30825 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56826#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21827 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56828#endif
[email protected]43535512013-02-20 20:41:41829 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
830 id, profile, context));
[email protected]2736c032012-05-11 18:06:07831 host->GetChannel()->AddFilter(
832 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27833 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33834 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31835#if defined(ENABLE_WEBRTC)
836 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
837#endif
[email protected]01e59752013-06-18 00:17:35838#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03839 ExtensionInfoMap* extension_info_map =
840 extensions::ExtensionSystem::Get(profile)->info_map();
841 host->GetChannel()->AddFilter(new NaClHostMessageFilter(
842 id, profile->IsOffTheRecord(),
843 profile->GetPath(), extension_info_map,
844 context));
[email protected]01e59752013-06-18 00:17:35845#endif
[email protected]3e69bc82011-05-26 23:22:38846
[email protected]2ccf45c2011-08-19 23:35:50847 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
848 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07849
[email protected]24665682013-02-25 20:59:38850 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
851 IsExtensionActivityLogEnabledForProfile(profile)));
852
[email protected]39a5b532011-10-22 01:47:07853 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56854
855 RendererContentSettingRules rules;
856 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
857 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14858}
859
[email protected]95c95552013-05-03 04:21:22860GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
861 content::BrowserContext* browser_context,
862 const GURL& url,
863 bool is_renderer_initiated,
864 content::SiteInstance* current_instance) {
865 Profile* profile = Profile::FromBrowserContext(browser_context);
866 if (!profile)
867 return url;
868
869 // Only return the privileged instant URL if we are entering from a browser-
870 // initiated navigation or if we are already in the instant process.
871 bool is_instant_process = false;
872 int process_id = current_instance->GetProcess()->GetID();
873 InstantService* instant_service =
874 InstantServiceFactory::GetForProfile(profile);
875 if (instant_service)
876 is_instant_process = instant_service->IsInstantProcess(process_id);
877
878 DCHECK_EQ(is_instant_process,
879 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
880 if (!is_renderer_initiated || is_instant_process) {
881 // If the input |url| should be assigned to the Instant renderer, make its
882 // privileged URL distinct from other URLs on the search provider's domain.
883 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
884 return chrome::GetPrivilegedURLForInstant(url, profile);
885 }
886
887 return url;
888}
889
[email protected]3d7474ff2011-07-27 17:47:37890GURL ChromeContentBrowserClient::GetEffectiveURL(
891 content::BrowserContext* browser_context, const GURL& url) {
892 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52893 if (!profile)
894 return url;
895
[email protected]d5bcd06f2013-04-21 08:07:24896#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30897 // If the input |url| should be assigned to the Signin renderer, make its
898 // effective URL distinct from other URLs on the signin service's domain.
899 // Note that the signin renderer will be allowed to sign the user in to
900 // Chrome.
901 if (SigninManager::IsWebBasedSigninFlowURL(url))
902 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24903#endif
[email protected]970c63e2013-03-07 00:25:30904
[email protected]c5dec6292013-01-25 04:54:52905 // If the input |url| is part of an installed app, the effective URL is an
906 // extension URL with the ID of that extension as the host. This has the
907 // effect of grouping apps together in a common SiteInstance.
908 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13909 extensions::ExtensionSystem::Get(profile)->extension_service();
910 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08911 return url;
912
[email protected]06bdd2b2012-11-30 18:47:13913 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55914 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08915 if (!extension)
916 return url;
917
[email protected]15877ca2011-11-18 22:40:52918 // Bookmark apps do not use the hosted app process model, and should be
919 // treated as normal URLs.
920 if (extension->from_bookmark())
921 return url;
922
[email protected]36fb2c7c2011-04-04 15:49:08923 // If the URL is part of an extension's web extent, convert it to an
924 // extension URL.
925 return extension->GetResourceURL(url.path());
926}
927
[email protected]056ad2a2011-07-12 02:13:55928bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37929 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52930 // Non-extension, non-Instant URLs should generally use
931 // process-per-site-instance. Because we expect to use the effective URL,
932 // URLs for hosted apps (apart from bookmark apps) should have an extension
933 // scheme by now.
934
935 Profile* profile = Profile::FromBrowserContext(browser_context);
936 if (!profile)
937 return false;
938
[email protected]df113a12013-07-24 04:56:08939 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52940 return true;
941
[email protected]d5bcd06f2013-04-21 08:07:24942#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30943 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
944 return true;
[email protected]d5bcd06f2013-04-21 08:07:24945#endif
[email protected]970c63e2013-03-07 00:25:30946
[email protected]885c0e92012-11-13 20:27:42947 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55948 return false;
949
[email protected]c5dec6292013-01-25 04:54:52950 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13951 extensions::ExtensionSystem::Get(profile)->extension_service();
952 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55953 return false;
954
[email protected]be9915fb2013-07-18 09:28:55955 const Extension* extension =
956 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:55957 if (!extension)
958 return false;
959
960 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53961 // permission, or that does not allow JavaScript access to the background
962 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55963 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40964 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06965 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29966 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53967 return false;
968 }
969 }
[email protected]056ad2a2011-07-12 02:13:55970
[email protected]7b54ca02012-03-02 18:06:53971 // Hosted apps that have script access to their background page must use
972 // process per site, since all instances can make synchronous calls to the
973 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55974 return true;
975}
976
[email protected]672c8c12013-03-07 12:30:06977// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41978void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
979 std::vector<std::string>* additional_schemes) {
980 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06981}
982
[email protected]6bd30072013-02-08 18:17:11983net::URLRequestContextGetter*
984ChromeContentBrowserClient::CreateRequestContext(
985 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06986 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11987 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06988 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11989}
990
991net::URLRequestContextGetter*
992ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
993 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40994 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11995 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06996 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11997 Profile* profile = Profile::FromBrowserContext(browser_context);
998 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06999 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111000}
1001
[email protected]46fb9442011-12-09 17:57:471002bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1003 return ProfileIOData::IsHandledURL(url);
1004}
1005
[email protected]c4365fa42013-05-14 01:08:241006bool ChromeContentBrowserClient::CanCommitURL(
1007 content::RenderProcessHost* process_host,
1008 const GURL& url) {
1009 // We need to let most extension URLs commit in any process, since this can
1010 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1011 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1012 // cannot be loaded in iframes and should never be requested outside its
1013 // process.
1014 Profile* profile =
1015 Profile::FromBrowserContext(process_host->GetBrowserContext());
1016 ExtensionService* service =
1017 extensions::ExtensionSystem::Get(profile)->extension_service();
1018 if (!service)
1019 return true;
1020 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551021 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241022 if (new_extension &&
1023 new_extension->is_hosted_app() &&
1024 new_extension->id() == extension_misc::kWebStoreAppId &&
1025 !service->process_map()->Contains(new_extension->id(),
1026 process_host->GetID())) {
1027 return false;
1028 }
1029
1030 return true;
1031}
1032
[email protected]2a5221b2011-09-27 23:07:311033bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301034 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311035 const GURL& site_url) {
1036 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301037 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521038 // This may be NULL during tests. In that case, just assume any site can
1039 // share any host.
1040 if (!profile)
1041 return true;
1042
[email protected]d43f99fe2013-04-03 00:20:141043 // Instant URLs should only be in the instant process and instant process
1044 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521045 InstantService* instant_service =
1046 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141047 if (instant_service) {
1048 bool is_instant_process = instant_service->IsInstantProcess(
1049 process_host->GetID());
1050 bool should_be_in_instant_process =
1051 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1052 if (is_instant_process || should_be_in_instant_process)
1053 return is_instant_process && should_be_in_instant_process;
1054 }
[email protected]c5dec6292013-01-25 04:54:521055
[email protected]d5bcd06f2013-04-21 08:07:241056#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301057 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1058 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1059 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241060#endif
[email protected]970c63e2013-03-07 00:25:301061
[email protected]06bdd2b2012-11-30 18:47:131062 ExtensionService* service =
1063 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461064 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311065
[email protected]ffa97602011-11-17 17:55:521066 // Don't allow the Task Manager to share a process with anything else.
1067 // Otherwise it can affect the renderers it is observing.
1068 // Note: we could create another RenderProcessHostPrivilege bucket for
1069 // this to allow multiple chrome://tasks instances to share, but that's
1070 // a very unlikely case without serious consequences.
1071 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1072 return false;
1073
[email protected]8d3132f62011-10-12 07:13:421074 // These may be NULL during tests. In that case, just assume any site can
1075 // share any host.
[email protected]6f371442011-11-09 06:45:461076 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311077 return true;
1078
[email protected]eec0b33c2011-12-05 22:09:451079 // Otherwise, just make sure the process privilege matches the privilege
1080 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571081 RenderProcessHostPrivilege privilege_required =
1082 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451083 return GetProcessPrivilege(process_host, process_map, service) ==
1084 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311085}
1086
[email protected]76411f412012-02-22 18:56:061087// This function is trying to limit the amount of processes used by extensions
1088// with background pages. It uses a globally set percentage of processes to
1089// run such extensions and if the limit is exceeded, it returns true, to
1090// indicate to the content module to group extensions together.
1091bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1092 content::BrowserContext* browser_context, const GURL& url) {
1093 // It has to be a valid URL for us to check for an extension.
1094 if (!url.is_valid())
1095 return false;
1096
1097 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191098 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131099 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061100 if (!service)
1101 return false;
1102
1103 // We have to have a valid extension with background page to proceed.
1104 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551105 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061106 if (!extension)
1107 return false;
[email protected]9367eabc2013-03-01 01:29:291108 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061109 return false;
1110
1111 std::set<int> process_ids;
1112 size_t max_process_count =
1113 content::RenderProcessHost::GetMaxRendererProcessCount();
1114
1115 // Go through all profiles to ensure we have total count of extension
1116 // processes containing background pages, otherwise one profile can
1117 // starve the other.
1118 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1119 GetLoadedProfiles();
1120 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031121 ExtensionProcessManager* epm =
1122 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321123 for (ExtensionProcessManager::const_iterator iter =
1124 epm->background_hosts().begin();
1125 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131126 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321127 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061128 }
1129 }
1130
1131 if (process_ids.size() >
1132 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1133 return true;
1134 }
1135
1136 return false;
1137}
1138
[email protected]6f371442011-11-09 06:45:461139void ChromeContentBrowserClient::SiteInstanceGotProcess(
1140 SiteInstance* site_instance) {
1141 CHECK(site_instance->HasProcess());
1142
1143 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021144 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521145 if (!profile)
1146 return;
1147
1148 // Remember the ID of the Instant process to signal the renderer process
1149 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031150 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321151 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521152 InstantService* instant_service =
1153 InstantServiceFactory::GetForProfile(profile);
1154 if (instant_service)
1155 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1156 }
1157
[email protected]d5bcd06f2013-04-21 08:07:241158#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301159 // We only expect there to be one signin process as we use process-per-site
1160 // for signin URLs. The signin process will be cleared from SigninManager
1161 // when the renderer is destroyed.
1162 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1163 SigninManager* signin_manager =
1164 SigninManagerFactory::GetForProfile(profile);
1165 if (signin_manager)
1166 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461167 BrowserThread::PostTask(
1168 BrowserThread::IO, FROM_HERE,
1169 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1170 extensions::ExtensionSystem::Get(profile)->info_map(),
1171 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301172 }
[email protected]d5bcd06f2013-04-21 08:07:241173#endif
[email protected]970c63e2013-03-07 00:25:301174
[email protected]06bdd2b2012-11-30 18:47:131175 ExtensionService* service =
1176 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461177 if (!service)
1178 return;
1179
[email protected]be9915fb2013-07-18 09:28:551180 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1181 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461182 if (!extension)
1183 return;
1184
[email protected]6bc04fd82011-12-04 02:29:351185 service->process_map()->Insert(extension->id(),
1186 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331187 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461188 BrowserThread::PostTask(
1189 BrowserThread::IO, FROM_HERE,
1190 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591191 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461192 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351193 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331194 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461195}
1196
1197void ChromeContentBrowserClient::SiteInstanceDeleting(
1198 SiteInstance* site_instance) {
1199 if (!site_instance->HasProcess())
1200 return;
1201
1202 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021203 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131204 ExtensionService* service =
1205 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461206 if (!service)
1207 return;
1208
[email protected]be9915fb2013-07-18 09:28:551209 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1210 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461211 if (!extension)
1212 return;
1213
[email protected]6bc04fd82011-12-04 02:29:351214 service->process_map()->Remove(extension->id(),
1215 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331216 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461217 BrowserThread::PostTask(
1218 BrowserThread::IO, FROM_HERE,
1219 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591220 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461221 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351222 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331223 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461224}
1225
[email protected]f05763972012-06-06 18:17:261226bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141227 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081228 const GURL& current_url,
1229 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261230 if (current_url.is_empty()) {
1231 // Always choose a new process when navigating to extension URLs. The
1232 // process grouping logic will combine all of a given extension's pages
1233 // into the same process.
[email protected]885c0e92012-11-13 20:27:421234 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261235 return true;
[email protected]e3daf3c2011-10-05 21:17:081236
[email protected]f05763972012-06-06 18:17:261237 return false;
1238 }
1239
1240 // Also, we must switch if one is an extension and the other is not the exact
1241 // same extension.
[email protected]885c0e92012-11-13 20:27:421242 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1243 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261244 if (current_url.GetOrigin() != new_url.GetOrigin())
1245 return true;
1246 }
1247
[email protected]e9841fbd2013-02-22 23:12:141248 // The checks below only matter if we can retrieve which extensions are
1249 // installed.
1250 Profile* profile =
1251 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1252 ExtensionService* service =
1253 extensions::ExtensionSystem::Get(profile)->extension_service();
1254 if (!service)
1255 return false;
1256
1257 // We must swap if the URL is for an extension and we are not using an
1258 // extension process.
1259 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551260 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141261 // Ignore all hosted apps except the Chrome Web Store, since they do not
1262 // require their own BrowsingInstance (e.g., postMessage is ok).
1263 if (new_extension &&
1264 new_extension->is_hosted_app() &&
1265 new_extension->id() != extension_misc::kWebStoreAppId)
1266 new_extension = NULL;
1267 if (new_extension &&
1268 site_instance->HasProcess() &&
1269 !service->process_map()->Contains(new_extension->id(),
1270 site_instance->GetProcess()->GetID()))
1271 return true;
1272
[email protected]f05763972012-06-06 18:17:261273 return false;
[email protected]e3daf3c2011-10-05 21:17:081274}
1275
[email protected]395045c2012-05-22 15:04:381276bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1277 content::ResourceContext* resource_context, const GURL& current_url,
1278 const GURL& new_url) {
1279 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1280 return extensions::CrossesExtensionProcessBoundary(
1281 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551282 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381283}
1284
[email protected]3d831992013-07-04 01:13:291285bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1286 return !url.SchemeIs(chrome::kChromeNativeScheme);
1287}
1288
[email protected]763ec4ca2011-04-29 15:48:121289std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1290 const std::string& alias_name) {
1291 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1292}
1293
[email protected]b80f68432011-05-02 17:22:301294void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1295 CommandLine* command_line, int child_process_id) {
[email protected]97425082013-07-16 03:10:071296#if defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301297 if (IsCrashReporterEnabled()) {
1298 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1299 child_process_logging::GetClientId());
1300 }
[email protected]97425082013-07-16 03:10:071301#elif defined(OS_POSIX)
1302 if (IsCrashReporterEnabled()) {
1303 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1304 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1305 }
1306
[email protected]b80f68432011-05-02 17:22:301307#endif // OS_MACOSX
1308
[email protected]f1933792011-06-14 00:49:341309 if (logging::DialogsAreSuppressed())
1310 command_line->AppendSwitch(switches::kNoErrorDialogs);
1311
[email protected]b80f68432011-05-02 17:22:301312 std::string process_type =
1313 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171314 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321315
1316 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1317 command_line->AppendSwitch(switches::kChromeFrame);
1318
[email protected]718eab62011-10-05 21:16:521319 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451320 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301321 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1322 if (!user_data_dir.empty())
1323 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1324#if defined(OS_CHROMEOS)
1325 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441326 browser_command_line.GetSwitchValueASCII(
1327 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301328 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441329 command_line->AppendSwitchASCII(
1330 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301331#endif
1332
[email protected]f3b1a082011-11-18 00:34:301333 content::RenderProcessHost* process =
1334 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371335 if (process) {
1336 Profile* profile = Profile::FromBrowserContext(
1337 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131338 ExtensionService* extension_service =
1339 extensions::ExtensionSystem::Get(profile)->extension_service();
1340 if (extension_service) {
1341 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001342 if (process_map && process_map->Contains(process->GetID()))
1343 command_line->AppendSwitch(switches::kExtensionProcess);
1344 }
[email protected]b80f68432011-05-02 17:22:301345
[email protected]a8d851f82011-12-21 00:32:371346 PrefService* prefs = profile->GetPrefs();
1347 // Currently this pref is only registered if applied via a policy.
1348 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1349 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1350 // Turn this policy into a command line switch.
1351 command_line->AppendSwitch(switches::kDisable3DAPIs);
1352 }
[email protected]718eab62011-10-05 21:16:521353
[email protected]a8d851f82011-12-21 00:32:371354 // Disable client-side phishing detection in the renderer if it is
1355 // disabled in the Profile preferences or the browser process.
1356 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1357 !g_browser_process->safe_browsing_detection_service()) {
1358 command_line->AppendSwitch(
1359 switches::kDisableClientSidePhishingDetection);
1360 }
[email protected]0045b0f42012-07-26 11:52:081361
1362 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211363 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521364
1365 InstantService* instant_service =
1366 InstantServiceFactory::GetForProfile(profile);
1367 if (instant_service &&
1368 instant_service->IsInstantProcess(process->GetID()))
1369 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301370
[email protected]d5bcd06f2013-04-21 08:07:241371#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301372 SigninManager* signin_manager =
1373 SigninManagerFactory::GetForProfile(profile);
1374 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1375 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241376#endif
[email protected]47c7ec82012-01-18 03:29:211377 }
[email protected]4287a3d2011-06-13 23:56:511378
[email protected]87552982012-11-02 17:21:401379 if (content::IsThreadedCompositingEnabled())
1380 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1381
[email protected]16dc42452013-04-09 04:37:191382 if (message_center::IsRichNotificationEnabled())
1383 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191384
[email protected]47c7ec82012-01-18 03:29:211385 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511386 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171387 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481388 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171389 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]49d9b142013-07-19 08:50:271390 extensions::switches::kAllowLegacyExtensionManifests,
1391 extensions::switches::kAllowScriptingGallery,
1392 extensions::switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511393 switches::kAllowHTTPBackgroundPage,
[email protected]9d450492013-06-13 23:08:371394 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1395 // to browser.
1396 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511397 switches::kAppsCheckoutURL,
1398 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311399 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511400 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501401 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531402 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111403 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531404 switches::kEnableAdview,
1405 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441406 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211407 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511408 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511409 switches::kEnableIPCFuzzing,
1410 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451411 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481412 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051413 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511414 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511415 switches::kMemoryProfiling,
1416 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371417 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371418 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511419 switches::kPpapiFlashArgs,
1420 switches::kPpapiFlashInProcess,
1421 switches::kPpapiFlashPath,
1422 switches::kPpapiFlashVersion,
1423 switches::kProfilingAtStart,
1424 switches::kProfilingFile,
1425 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371426 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511427 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291428 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381429 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511430 };
1431
1432 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1433 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171434 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381435 static const char* const kSwitchNames[] = {
[email protected]49d9b142013-07-19 08:50:271436 extensions::switches::kExtensionsOnChromeURLs,
[email protected]eb653f82012-05-24 02:31:351437 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381438 switches::kEnableExperimentalExtensionApis,
1439 switches::kWhitelistedExtensionID,
1440 };
1441
1442 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1443 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511444 } else if (process_type == switches::kPluginProcess) {
1445 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441446#if defined(OS_CHROMEOS)
1447 chromeos::switches::kLoginProfile,
1448#endif
[email protected]4287a3d2011-06-13 23:56:511449 switches::kMemoryProfiling,
1450 switches::kSilentDumpOnDCHECK,
1451 switches::kUserDataDir,
1452 };
1453
1454 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1455 arraysize(kSwitchNames));
1456 } else if (process_type == switches::kZygoteProcess) {
1457 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511458 switches::kUserDataDir, // Make logs go to the right file.
1459 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501460 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511461 switches::kPpapiFlashInProcess,
1462 switches::kPpapiFlashPath,
1463 switches::kPpapiFlashVersion,
1464 };
1465
1466 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1467 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111468 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001469 base::FilePath user_data_dir =
1470 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1471 if (!user_data_dir.empty())
1472 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111473 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1474 // because GPU is expected to be unreliable.
1475 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1476 !command_line->HasSwitch(switches::kDisableBreakpad))
1477 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301478 }
[email protected]6f08af82011-09-15 01:19:031479
1480 // The command line switch kEnableBenchmarking needs to be specified along
1481 // with the kEnableStatsTable switch to ensure that the stats table global
1482 // is initialized correctly.
1483 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1484 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301485}
1486
1487std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431488 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351489 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301490 return g_browser_process->GetApplicationLocale();
1491}
1492
[email protected]597a867b2011-11-18 18:31:201493std::string ChromeContentBrowserClient::GetAcceptLangs(
1494 content::BrowserContext* context) {
1495 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371496 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081497}
1498
[email protected]9ec0f452012-05-31 15:58:531499gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221500 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531501 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081502}
1503
[email protected]a2176792011-05-08 19:30:491504bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091505 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191506 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201507 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201509 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051510 return io_data->GetCookieSettings()->
1511 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491512}
1513
[email protected]ed24fad2011-05-10 22:44:011514bool ChromeContentBrowserClient::AllowGetCookie(
1515 const GURL& url,
1516 const GURL& first_party,
1517 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201518 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011519 int render_process_id,
1520 int render_view_id) {
1521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201522 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051523 bool allow = io_data->GetCookieSettings()->
1524 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011525
[email protected]8093a542011-05-13 07:29:321526 BrowserThread::PostTask(
1527 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031528 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431529 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011530 return allow;
1531}
1532
1533bool ChromeContentBrowserClient::AllowSetCookie(
1534 const GURL& url,
1535 const GURL& first_party,
1536 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201537 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011538 int render_process_id,
1539 int render_view_id,
1540 net::CookieOptions* options) {
1541 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201542 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051543 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1544 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1545
[email protected]8093a542011-05-13 07:29:321546 BrowserThread::PostTask(
1547 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031548 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431549 render_view_id, url, first_party, cookie_line, *options,
1550 !allow));
[email protected]ed24fad2011-05-10 22:44:011551 return allow;
1552}
1553
[email protected]d5a19162011-06-30 18:51:541554bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201555 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201557 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431558 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1559 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261560
[email protected]bf510ed2012-06-05 08:31:431561 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1562 // Could we even support per-origin settings?
1563 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541564}
1565
[email protected]5c5a88e2011-11-12 00:45:351566bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351567 const GURL& url,
1568 const string16& name,
1569 const string16& display_name,
1570 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201571 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481572 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201574 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351575 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1576 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1577
[email protected]62151052012-02-01 18:40:481578 // Record access to database for potential display in UI.
1579 std::vector<std::pair<int, int> >::const_iterator i;
1580 for (i = render_views.begin(); i != render_views.end(); ++i) {
1581 BrowserThread::PostTask(
1582 BrowserThread::UI, FROM_HERE,
1583 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1584 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351585 }
1586
1587 return allow;
1588}
1589
1590bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351591 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201592 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481593 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201595 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351596 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1597 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1598
[email protected]62151052012-02-01 18:40:481599 // Record access to file system for potential display in UI.
1600 std::vector<std::pair<int, int> >::const_iterator i;
1601 for (i = render_views.begin(); i != render_views.end(); ++i) {
1602 BrowserThread::PostTask(
1603 BrowserThread::UI, FROM_HERE,
1604 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1605 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351606 }
1607
1608 return allow;
1609}
1610
[email protected]7c5ff9a2012-03-02 07:42:491611bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1612 const GURL& url,
1613 const string16& name,
1614 content::ResourceContext* context,
1615 const std::vector<std::pair<int, int> >& render_views) {
1616 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1617 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1618 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1619 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1620
1621 // Record access to IndexedDB for potential display in UI.
1622 std::vector<std::pair<int, int> >::const_iterator i;
1623 for (i = render_views.begin(); i != render_views.end(); ++i) {
1624 BrowserThread::PostTask(
1625 BrowserThread::UI, FROM_HERE,
1626 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1627 i->first, i->second, url, name, !allow));
1628 }
1629
1630 return allow;
1631}
1632
[email protected]6133f922011-07-01 21:34:341633net::URLRequestContext*
1634ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201635 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421637 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201638 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341639 return io_data->extensions_request_context();
1640 }
1641
1642 return NULL;
1643}
1644
[email protected]317f96c92011-05-31 06:53:411645QuotaPermissionContext*
1646ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1647 return new ChromeQuotaPermissionContext();
1648}
1649
[email protected]848dd042011-06-04 18:24:031650void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171651 int render_process_id,
1652 int render_view_id,
1653 int cert_error,
1654 const net::SSLInfo& ssl_info,
1655 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021656 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031657 bool overridable,
[email protected]d9be47702012-05-16 03:41:221658 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171659 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001660 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021661 if (resource_type != ResourceType::MAIN_FRAME) {
1662 // A sub-resource has a certificate error. The user doesn't really
1663 // have a context for making the right decision, so block the
1664 // request hard, without an info bar to allow showing the insecure
1665 // content.
[email protected]8c965c22013-05-23 19:28:001666 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021667 return;
1668 }
1669
[email protected]f9034cf2011-07-21 12:43:411670 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131671 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171672 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411673 if (!tab) {
1674 NOTREACHED();
1675 return;
1676 }
1677 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501678 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301679 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011680 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1681 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411682 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171683 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411684 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001685 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411686 return;
1687 }
1688 }
1689
[email protected]1e87df32012-09-12 04:53:191690#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231691 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1692 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1693 if (captive_portal_tab_helper)
1694 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191695#endif
1696
[email protected]f9034cf2011-07-21 12:43:411697 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221698 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1699 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031700}
1701
[email protected]c99c442e2011-08-24 11:37:301702void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451703 int render_process_id,
1704 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401705 const net::HttpNetworkSession* network_session,
1706 net::SSLCertRequestInfo* cert_request_info,
1707 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131708 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451709 render_process_id, render_view_id);
1710 if (!tab) {
1711 NOTREACHED();
1712 return;
1713 }
1714
[email protected]6786bf402011-12-03 15:19:451715 GURL requesting_url("https://" + cert_request_info->host_and_port);
1716 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1717 << cert_request_info->host_and_port;
1718
[email protected]627e0512011-12-21 22:55:301719 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451720 scoped_ptr<Value> filter(
1721 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1722 requesting_url,
1723 requesting_url,
1724 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1725 std::string(), NULL));
1726
1727 if (filter.get()) {
1728 // Try to automatically select a client certificate.
1729 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1730 DictionaryValue* filter_dict =
1731 static_cast<DictionaryValue*>(filter.get());
1732
1733 const std::vector<scoped_refptr<net::X509Certificate> >&
1734 all_client_certs = cert_request_info->client_certs;
1735 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091736 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451737 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091738 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451739 return;
1740 }
1741 }
1742 } else {
1743 NOTREACHED();
1744 }
1745 }
1746
[email protected]11feec322012-09-18 03:58:521747 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1748 if (!ssl_tab_helper) {
1749 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451750 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141751 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401752 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451753 return;
1754 }
[email protected]11feec322012-09-18 03:58:521755 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401756 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451757}
1758
[email protected]3b455502012-12-11 18:22:581759void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451760 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581761 net::CertificateMimeType cert_type,
1762 const void* cert_data,
1763 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451764 int render_process_id,
1765 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581766 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1767 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451768}
1769
[email protected]dc73a7b2012-03-25 15:27:181770content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561771 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181772}
1773
[email protected]941623e2011-06-07 23:06:041774void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1775 const GURL& source_origin,
1776 int callback_context,
1777 int render_process_id,
1778 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111779#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021780 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1781 WebContents* contents =
1782 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1783 if (!contents) {
[email protected]941623e2011-06-07 23:06:041784 NOTREACHED();
1785 return;
1786 }
1787
[email protected]d0d9c3ee2012-06-19 03:07:021788 // Skip showing the infobar if the request comes from an extension, and that
1789 // extension has the 'notify' permission. (If the extension does not have the
1790 // permission, the user will still be prompted.)
1791 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011792 ExtensionInfoMap* extension_info_map =
1793 extensions::ExtensionSystem::Get(profile)->info_map();
1794 DesktopNotificationService* notification_service =
1795 DesktopNotificationServiceFactory::GetForProfile(profile);
1796 const Extension* extension = NULL;
1797 if (extension_info_map) {
1798 ExtensionSet extensions;
1799 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1800 source_origin, render_process_id,
1801 extensions::APIPermission::kNotification, &extensions);
1802 for (ExtensionSet::const_iterator iter = extensions.begin();
1803 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381804 if (notification_service->IsNotifierEnabled(NotifierId(
1805 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361806 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011807 break;
1808 }
1809 }
1810 }
[email protected]eb4832a2012-12-08 01:57:521811 RenderViewHost* rvh =
1812 RenderViewHost::FromID(render_process_id, render_view_id);
1813 if (IsExtensionWithPermissionOrSuggestInConsole(
1814 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021815 if (rvh)
1816 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1817 return;
1818 }
1819
[email protected]c7cd5942013-04-30 03:31:011820 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021821 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111822#else
1823 NOTIMPLEMENTED();
1824#endif
[email protected]941623e2011-06-07 23:06:041825}
1826
1827WebKit::WebNotificationPresenter::Permission
1828 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021829 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201830 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021831 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111832#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481834 // Sometimes a notification may be invoked during the shutdown.
1835 // See http://crbug.com/256638
1836 if (browser_shutdown::IsTryingToQuit())
1837 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
1838
[email protected]df02aca2012-02-09 21:03:201839 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041840
[email protected]c7cd5942013-04-30 03:31:011841 DesktopNotificationService* notification_service =
1842 io_data->GetNotificationService();
1843 if (notification_service) {
1844 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1845 ExtensionSet extensions;
1846 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1847 source_origin, render_process_id,
1848 extensions::APIPermission::kNotification, &extensions);
1849 for (ExtensionSet::const_iterator iter = extensions.begin();
1850 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381851 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
1852 if (notification_service->IsNotifierEnabled(notifier_id))
[email protected]c7cd5942013-04-30 03:31:011853 return WebKit::WebNotificationPresenter::PermissionAllowed;
1854 }
1855
1856 return notification_service->HasPermission(source_origin);
1857 }
1858
1859 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111860#else
1861 return WebKit::WebNotificationPresenter::PermissionAllowed;
1862#endif
[email protected]941623e2011-06-07 23:06:041863}
1864
1865void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171866 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041867 int render_process_id,
1868 int render_view_id,
1869 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111870#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041871 RenderViewHost* rvh = RenderViewHost::FromID(
1872 render_process_id, render_view_id);
1873 if (!rvh) {
1874 NOTREACHED();
1875 return;
1876 }
1877
[email protected]9f76c1e2012-03-05 15:15:581878 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301879 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041880 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371881 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041882 service->ShowDesktopNotification(
1883 params, render_process_id, render_view_id,
1884 worker ? DesktopNotificationService::WorkerNotification :
1885 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111886#else
1887 NOTIMPLEMENTED();
1888#endif
[email protected]941623e2011-06-07 23:06:041889}
1890
1891void ChromeContentBrowserClient::CancelDesktopNotification(
1892 int render_process_id,
1893 int render_view_id,
1894 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111895#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041896 RenderViewHost* rvh = RenderViewHost::FromID(
1897 render_process_id, render_view_id);
1898 if (!rvh) {
1899 NOTREACHED();
1900 return;
1901 }
1902
[email protected]9f76c1e2012-03-05 15:15:581903 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301904 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041905 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371906 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041907 service->CancelDesktopNotification(
1908 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111909#else
1910 NOTIMPLEMENTED();
1911#endif
[email protected]941623e2011-06-07 23:06:041912}
1913
[email protected]9f3fba52011-06-08 20:37:191914bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351915 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021916 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191917 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201918 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011919 int render_process_id,
1920 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191921 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011922
1923 *no_javascript_access = false;
1924
[email protected]9f3fba52011-06-08 20:37:191925 // If the opener is trying to create a background window but doesn't have
1926 // the appropriate permission, fail the attempt.
1927 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201928 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531929 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1930
[email protected]03b6d552012-03-29 04:03:011931 if (!map->SecurityOriginHasAPIPermission(
1932 source_origin,
1933 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061934 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011935 return false;
1936 }
1937
[email protected]7b54ca02012-03-02 18:06:531938 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1939 // return a recently installed Extension even if this CanCreateWindow call
1940 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011941 // because the permission check above would have caused an early return
1942 // already. We must use the full URL to find hosted apps, though, and not
1943 // just the origin.
[email protected]be9915fb2013-07-18 09:28:551944 const Extension* extension =
1945 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:291946 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011947 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191948 }
[email protected]056efdc2013-04-06 00:14:531949
1950 // No new browser window (popup or tab) in app mode.
1951 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1952 chrome::IsRunningInForcedAppMode()) {
1953 return false;
1954 }
1955
[email protected]9f3fba52011-06-08 20:37:191956 return true;
1957}
1958
1959std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201960 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1962 // Check if it's an extension-created worker, in which case we want to use
1963 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201964 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191965 const Extension* extension =
1966 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1967 return extension ? extension->name() : std::string();
1968}
1969
[email protected]99907362012-01-11 05:41:401970void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1971 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171972}
1973
[email protected]7a06d282013-05-03 04:39:331974// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021975content::SpeechRecognitionManagerDelegate*
1976 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:001977#if defined(ENABLE_INPUT_SPEECH)
1978 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:321979#else
[email protected]855e18b2013-07-08 21:02:001980 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
1981 // need the base delegate without the bubble UI.
1982 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321983#endif
[email protected]66cfec62012-02-24 17:57:511984}
1985
[email protected]ae6e9912011-07-27 01:18:281986net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1987 return g_browser_process->net_log();
1988}
1989
[email protected]32538d92011-08-25 00:09:231990AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1991 return new ChromeAccessTokenStore();
1992}
1993
[email protected]dbae6b02011-06-29 23:51:411994bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011995 return true;
[email protected]dbae6b02011-06-29 23:51:411996}
1997
[email protected]64d69de42012-02-06 00:19:541998void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321999 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062000 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582001 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062002 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062003
[email protected]f3986f82012-01-03 20:00:062004 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542005 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062006 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542007 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062008 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542009 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062010 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542011 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062012 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542013 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062014 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542015 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032016 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2017 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:062018
[email protected]64d69de42012-02-06 00:19:542019 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402020 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542021 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402022 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542023 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402024 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542025 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402026 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062027
[email protected]ddf72142012-05-22 04:52:402028 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062029
[email protected]64d69de42012-02-06 00:19:542030 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402031 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542032 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062033 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542034 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062035 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2036 const DictionaryValue* inspector_settings =
2037 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2038 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182039 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2040 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062041 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182042 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542043 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182044 std::make_pair(iter.key(), value));
2045 }
[email protected]f3986f82012-01-03 20:00:062046 }
2047 }
[email protected]64d69de42012-02-06 00:19:542048 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062049
[email protected]ddf72142012-05-22 04:52:402050 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542051 web_prefs->javascript_enabled = false;
2052 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2053 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402054 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542055 web_prefs->plugins_enabled = false;
2056 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2057 web_prefs->java_enabled = false;
2058 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402059 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062060
[email protected]64d69de42012-02-06 00:19:542061 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2062 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062063
[email protected]64d69de42012-02-06 00:19:542064 web_prefs->memory_info_enabled =
2065 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2066 web_prefs->allow_displaying_insecure_content =
2067 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2068 web_prefs->allow_running_insecure_content =
2069 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322070#if defined(OS_ANDROID)
2071 web_prefs->font_scale_factor =
2072 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2073 web_prefs->force_enable_zoom =
2074 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:452075#if defined(GOOGLE_TV)
2076 web_prefs->user_gesture_required_for_media_playback = false;
2077#endif
[email protected]d3b935f2012-10-19 23:14:322078#endif
[email protected]5c915252013-05-07 13:15:392079
[email protected]af4256d52013-06-04 20:39:072080#if defined(OS_ANDROID)
2081 web_prefs->password_echo_enabled =
2082 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2083#else
[email protected]9d06d88d2012-02-23 22:37:082084 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072085#endif
2086
[email protected]5c915252013-05-07 13:15:392087#if defined(OS_CHROMEOS)
2088 // Enable password echo during OOBE when keyboard driven flag is set.
2089 if (chromeos::UserManager::IsInitialized() &&
2090 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
2091 !chromeos::StartupUtils::IsOobeCompleted()) {
2092 bool keyboard_driven_oobe = false;
2093 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]0071aed32013-06-19 13:39:552094 chromeos::system::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:392095 if (keyboard_driven_oobe)
2096 web_prefs->password_echo_enabled = true;
2097 }
2098#endif
[email protected]f3986f82012-01-03 20:00:062099
[email protected]46f8e742013-05-03 18:37:142100#if defined(OS_ANDROID)
2101 web_prefs->user_style_sheet_enabled = false;
2102#else
[email protected]64d69de42012-02-06 00:19:542103 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152104 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362105 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152106 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542107 web_prefs->user_style_sheet_enabled = true;
2108 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152109 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542110 } else {
2111 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062112 }
[email protected]46f8e742013-05-03 18:37:142113#endif
[email protected]f3986f82012-01-03 20:00:062114
[email protected]cfadadd2013-04-03 04:43:022115 web_prefs->asynchronous_spell_checking_enabled = true;
2116 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572117
[email protected]64d69de42012-02-06 00:19:542118 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062119 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542120 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062121 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542122 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062123 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2124
2125 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542126 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062127 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542128 web_prefs->default_encoding);
2129 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402130 prefs->ClearPref(prefs::kDefaultCharset);
2131 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062132 }
[email protected]64d69de42012-02-06 00:19:542133 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062134
[email protected]88ecf66d2012-12-11 22:53:472135 if (content::IsForceCompositingModeEnabled())
2136 web_prefs->force_compositing_mode = true;
2137
[email protected]299d7f12012-05-23 05:31:152138 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232139 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132140 ExtensionService* service =
2141 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062142 if (service) {
[email protected]1bc28312012-11-08 08:31:532143 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2144 const Extension* extension = service->extensions()->GetByID(url.host());
2145 // Ensure that we are only granting extension preferences to URLs with
2146 // the correct scheme. Without this check, chrome-guest:// schemes used by
2147 // webview tags as well as hosts that happen to match the id of an
2148 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422149 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532150 extension_webkit_preferences::SetPreferences(
2151 extension, view_type, web_prefs);
2152 }
[email protected]f3986f82012-01-03 20:00:062153 }
2154
[email protected]cb2edf22013-04-01 20:25:232155 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542156 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232157 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062158 // Disable all kinds of acceleration for background pages.
2159 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542160 web_prefs->force_compositing_mode = false;
2161 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062162 }
[email protected]2e21fe292012-03-02 22:52:322163
2164#if defined(FILE_MANAGER_EXTENSION)
2165 // Override the default of suppressing HW compositing for WebUI pages for the
2166 // file manager, which is implemented using WebUI but wants HW acceleration
2167 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532168 if (url.SchemeIs(extensions::kExtensionScheme) &&
2169 url.host() == kFileBrowserDomain) {
[email protected]2e21fe292012-03-02 22:52:322170 web_prefs->accelerated_compositing_enabled = true;
2171 web_prefs->accelerated_2d_canvas_enabled = true;
2172 }
2173#endif
[email protected]181a95ee2011-07-12 19:26:362174}
2175
2176void ChromeContentBrowserClient::UpdateInspectorSetting(
2177 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062178 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582179 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062180 DictionaryPrefUpdate update(
2181 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2182 prefs::kWebKitInspectorSettings);
2183 DictionaryValue* inspector_settings = update.Get();
2184 inspector_settings->SetWithoutPathExpansion(key,
2185 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362186}
2187
[email protected]b8148ac2011-07-13 22:03:252188void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2189 BrowserURLHandler* handler) {
2190 // Add the default URL handlers.
2191 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2192 BrowserURLHandler::null_handler());
2193 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2194 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2195
[email protected]b3adbd02011-11-30 22:23:272196 // about: handler. Must come before chrome: handler, since it will
2197 // rewrite about: urls to chrome: URLs and then expect chrome: to
2198 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252199 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2200 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032201
2202 // Handler to rewrite chrome://newtab for InstantExtended.
2203 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2204 &chrome::HandleNewTabURLReverseRewrite);
2205
[email protected]b8148ac2011-07-13 22:03:252206 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242207 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252208}
2209
2210void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372211 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582212 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472213 BrowsingDataRemover* remover =
2214 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552215 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2216 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252217 // BrowsingDataRemover takes care of deleting itself when done.
2218}
2219
2220void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372221 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582222 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472223 BrowsingDataRemover* remover =
2224 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232225 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552226 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252227 // BrowsingDataRemover takes care of deleting itself when done.
2228}
2229
[email protected]650b2d52013-02-10 03:41:452230base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322231 return download_util::GetDefaultDownloadDirectory();
2232}
2233
[email protected]c9b6eb62011-10-18 20:49:392234std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2235 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2236}
2237
[email protected]b7631cc2012-09-15 05:08:382238void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2239 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542240#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382241 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2242 scoped_ptr<ppapi::host::HostFactory>(
2243 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542244#endif
[email protected]b7631cc2012-09-15 05:08:382245}
2246
[email protected]0c7193742012-11-07 19:05:032247content::BrowserPpapiHost*
2248 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2249 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132250 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032251 while (!iter.Done()) {
2252 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2253 if (host->process() &&
2254 host->process()->GetData().id == plugin_process_id) {
2255 // Found the plugin.
2256 return host->browser_ppapi_host();
2257 }
2258 ++iter;
2259 }
2260 return NULL;
2261}
2262
[email protected]7b38b192013-03-23 18:39:312263bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2264 content::BrowserContext* browser_context, const GURL& site_url) {
2265 if (CommandLine::ForCurrentProcess()->HasSwitch(
2266 switches::kEnableBrowserPluginForAllViewTypes))
2267 return true;
2268
2269 Profile* profile = Profile::FromBrowserContext(browser_context);
2270 ExtensionService* service =
2271 extensions::ExtensionSystem::Get(profile)->extension_service();
2272 if (!service)
2273 return false;
2274
[email protected]be9915fb2013-07-18 09:28:552275 const Extension* extension =
2276 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312277 if (!extension)
2278 return false;
2279
[email protected]c2d2f102013-04-29 16:42:582280 return extension->HasAPIPermission(APIPermission::kWebView) ||
2281 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312282}
2283
[email protected]38cd8f7f2012-06-15 22:06:072284bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582285 content::BrowserContext* browser_context,
2286 const GURL& url,
[email protected]dda54822013-06-15 01:26:392287 bool private_api,
[email protected]157cc902012-11-02 06:31:582288 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402289#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372290 Profile* profile = Profile::FromBrowserContext(browser_context);
2291 const ExtensionSet* extension_set = NULL;
2292 if (profile) {
2293 extension_set = extensions::ExtensionSystem::Get(profile)->
2294 extension_service()->extensions();
2295 }
[email protected]dda54822013-06-15 01:26:392296
2297 if (private_api) {
2298 // Access to private socket APIs is controlled by the whitelist.
2299 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2300 allowed_socket_origins_)) {
2301 return true;
2302 }
2303 } else {
2304 // Access to public socket APIs is controlled by extension permissions.
2305 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2306 extension_set) {
2307 const Extension* extension = extension_set->GetByID(url.host());
2308 if (extension) {
2309 extensions::SocketPermission::CheckParam check_params(
2310 params.type, params.host, params.port);
2311 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2312 extension, extensions::APIPermission::kSocket, &check_params)) {
2313 return true;
2314 }
2315 }
2316 }
2317 }
2318
2319 // Allow both public and private APIs if the command line says so.
2320 return IsHostAllowedByCommandLine(url, extension_set,
2321 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402322#else
[email protected]a658d452012-03-02 12:45:292323 return false;
[email protected]93f72062013-05-29 20:29:402324#endif
[email protected]e461da2f2012-02-16 19:06:402325}
2326
[email protected]650b2d52013-02-10 03:41:452327base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2328 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142329 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2330 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2331}
2332
[email protected]a28e3302013-02-03 03:50:432333ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2334 WebContents* web_contents) {
2335 return new ChromeSelectFilePolicy(web_contents);
2336}
2337
[email protected]7d9424702013-04-14 13:14:162338void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2339 std::vector<std::string>* additional_allowed_schemes) {
2340 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2341 additional_allowed_schemes);
2342 additional_allowed_schemes->push_back(kChromeUIScheme);
2343 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2344}
2345
[email protected]f19bbf62013-07-09 01:22:322346void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312347 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532348 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322349 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532350#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032351 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322352 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032353 storage_partition_path,
2354 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322355 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532356#endif
[email protected]b40015c2013-06-26 08:13:312357#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312358 fileapi::ExternalMountPoints* external_mount_points =
2359 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312360 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322361 chromeos::FileSystemBackend* backend =
2362 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312363 new drive::FileSystemBackendDelegate(browser_context),
2364 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312365 external_mount_points,
2366 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322367 backend->AddSystemMountPoints();
2368 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2369 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312370#endif
[email protected]02250952013-04-24 23:52:532371}
2372
[email protected]e60c0232011-11-11 19:56:352373#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182374void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2375 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382376 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082377 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392378#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452379 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392380 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2381 DCHECK(!data_path.empty());
2382
2383 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452384 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392385 base::PlatformFile f =
2386 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2387 DCHECK(f != base::kInvalidPlatformFileValue);
2388 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2389 FileDescriptor(f, true)));
2390
[email protected]650b2d52013-02-10 03:41:452391 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392392 data_path.AppendASCII("chrome_100_percent.pak");
2393 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2394 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372395 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392396 FileDescriptor(f, true)));
2397
2398 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452399 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392400 GetLocaleFilePath(locale, false);
2401 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2402 DCHECK(f != base::kInvalidPlatformFileValue);
2403 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2404 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382405
[email protected]650b2d52013-02-10 03:41:452406 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372407 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2408 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2409 DCHECK(f != base::kInvalidPlatformFileValue);
2410 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2411 FileDescriptor(f, true)));
2412
[email protected]82174aa2013-01-22 21:53:432413 if (IsCrashReporterEnabled()) {
2414 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2415 if (f == base::kInvalidPlatformFileValue) {
2416 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2417 "be disabled for this process.";
2418 } else {
2419 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2420 FileDescriptor(f, true)));
2421 }
[email protected]40da3e0c2012-10-24 22:03:382422 }
[email protected]40da3e0c2012-10-24 22:03:382423
2424#else
2425 int crash_signal_fd = GetCrashSignalFD(command_line);
2426 if (crash_signal_fd >= 0) {
2427 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2428 FileDescriptor(crash_signal_fd,
2429 false)));
2430 }
[email protected]29699c22012-10-03 23:57:392431#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302432}
[email protected]e60c0232011-11-11 19:56:352433#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302434
[email protected]4a65826d2011-08-25 16:04:012435#if defined(OS_WIN)
2436const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2437 return chrome::kBrowserResourcesDll;
2438}
[email protected]34f48682013-03-20 00:30:182439
2440void ChromeContentBrowserClient::PreSpawnRenderer(
2441 sandbox::TargetPolicy* policy,
2442 bool* success) {
2443 // This code is duplicated in nacl_exe_win_64.cc.
2444 // Allow the server side of a pipe restricted to the "chrome.nacl."
2445 // namespace so that it cannot impersonate other system or other chrome
2446 // service pipes.
2447 sandbox::ResultCode result = policy->AddRule(
2448 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2449 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2450 L"\\\\.\\pipe\\chrome.nacl.*");
2451 if (result != sandbox::SBOX_ALL_OK) {
2452 *success = false;
2453 return;
2454 }
2455
2456 // Renderers need to send named pipe handles and shared memory
2457 // segment handles to NaCl loader processes.
2458 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2459 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2460 L"File");
2461 if (result != sandbox::SBOX_ALL_OK) {
2462 *success = false;
2463 return;
2464 }
2465}
[email protected]4a65826d2011-08-25 16:04:012466#endif
2467
[email protected]37a72af2011-06-13 05:42:012468#if defined(USE_NSS)
2469crypto::CryptoModuleBlockingPasswordDelegate*
2470 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2471 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292472 return chrome::NewCryptoModuleBlockingDialogDelegate(
2473 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012474}
2475#endif
2476
[email protected]d977f9c2011-03-14 16:10:262477} // namespace chrome