blob: b93efb2ea3c0029255a04e2549e33a46fb831148 [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]b1d97272013-08-17 13:38:4934#include "chrome/browser/download/download_prefs.h"
[email protected]2b33dcd02012-03-18 01:34:1635#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]1deace22013-05-22 06:14:4636#include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
[email protected]76411f412012-02-22 18:56:0637#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0438#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3339#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2640#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0841#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2542#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0643#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]6940eef82013-09-11 11:58:4144#include "chrome/browser/extensions/process_map.h"
[email protected]eb4832a2012-12-08 01:57:5245#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2346#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1247#include "chrome/browser/google/google_util.h"
[email protected]0533cc6d2013-06-27 22:44:0548#include "chrome/browser/guestview/adview/adview_guest.h"
49#include "chrome/browser/guestview/guestview_constants.h"
50#include "chrome/browser/guestview/webview/webview_guest.h"
[email protected]11158e2d2013-02-01 02:31:5651#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0452#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]01e59752013-06-18 00:17:3553#include "chrome/browser/nacl_host/nacl_host_message_filter.h"
[email protected]0c7193742012-11-07 19:05:0354#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2855#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0456#include "chrome/browser/notifications/desktop_notification_service.h"
57#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4258#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5659#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0660#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]190e5e22013-07-27 05:59:2361#include "chrome/browser/prerender/prerender_final_status.h"
[email protected]f9034cf2011-07-21 12:43:4162#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5063#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0764#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4165#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1466#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0367#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1468#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3269#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0670#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1471#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3872#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4373#include "chrome/browser/search/instant_service.h"
74#include "chrome/browser/search/instant_service_factory.h"
75#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1476#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0277#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3378#include "chrome/browser/speech/tts_message_filter.h"
[email protected]3b455502012-12-11 18:22:5879#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0380#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5281#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]180c66a62013-08-05 12:01:3682#include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
[email protected]8ec26472011-06-06 16:52:4583#include "chrome/browser/tab_contents/tab_util.h"
[email protected]40aa8bb2013-08-23 20:28:2384#include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h"
[email protected]a28e3302013-02-03 03:50:4385#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2586#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4487#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5088#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0689#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1590#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2791#include "chrome/browser/validation_message_message_filter.h"
[email protected]b80f68432011-05-02 17:22:3092#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0193#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1494#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3095#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2996#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0497#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3898#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4499#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:43100#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:29101#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]dda54822013-06-15 01:26:39102#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]157cc902012-11-02 06:31:58103#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]9a60d1602013-09-11 04:09:12104#include "chrome/common/extensions/web_accessible_resources_handler.h"
[email protected]f1933792011-06-14 00:49:34105#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37106#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12107#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38108#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09109#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53110#include "chromeos/chromeos_constants.h"
[email protected]d5d383252013-07-04 14:44:32111#include "components/nacl/common/nacl_process_type.h"
[email protected]75fee372013-03-06 00:42:44112#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43113#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30114#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38115#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03116#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31117#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03118#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59119#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:30120#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33121#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05122#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33123#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19124#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10125#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43126#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18127#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23128#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42129#include "extensions/common/constants.h"
[email protected]49d9b142013-07-19 08:50:27130#include "extensions/common/switches.h"
[email protected]c9b6eb62011-10-18 20:49:39131#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23132#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53133#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58134#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34135#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06136#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57137#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38138#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39139#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08140#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24141#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31142#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18143#include "webkit/common/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:26144
[email protected]b48c9182011-10-26 18:03:30145#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38146#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18147#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38148#elif defined(OS_MACOSX)
149#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56150#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30151#elif defined(OS_CHROMEOS)
152#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]f19bbf62013-07-09 01:22:32153#include "chrome/browser/chromeos/drive/file_system_backend_delegate.h"
154#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
[email protected]5c915252013-05-07 13:15:39155#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49156#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]c94ac692013-07-27 00:50:10157#include "chrome/browser/chromeos/system/input_device_settings.h"
[email protected]931d1042013-04-05 17:50:44158#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26159#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30160#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09161#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38162#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09163#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39164#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30165#elif defined(OS_POSIX)
166#include "chrome/browser/chrome_browser_main_posix.h"
167#endif
168
[email protected]6653c192012-04-10 22:52:44169#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30170#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12171#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43172#endif
[email protected]b80f68432011-05-02 17:22:30173
[email protected]1e87df32012-09-12 04:53:19174#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
175#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
176#endif
177
[email protected]29699c22012-10-03 23:57:39178#if defined(OS_ANDROID)
179#include "ui/base/ui_base_paths.h"
180#endif
181
[email protected]37a72af2011-06-13 05:42:01182#if defined(USE_NSS)
183#include "chrome/browser/ui/crypto_module_password_dialog.h"
184#endif
185
[email protected]d5bcd06f2013-04-21 08:07:24186#if !defined(OS_CHROMEOS)
187#include "chrome/browser/signin/signin_manager.h"
188#include "chrome/browser/signin/signin_manager_factory.h"
189#endif
190
[email protected]02250952013-04-24 23:52:53191#if !defined(OS_ANDROID)
[email protected]f19bbf62013-07-09 01:22:32192#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
[email protected]02250952013-04-24 23:52:53193#endif
194
[email protected]6ef98b5a2013-05-31 23:58:31195#if defined(ENABLE_WEBRTC)
196#include "chrome/browser/media/webrtc_logging_handler_host.h"
197#endif
198
[email protected]855e18b2013-07-08 21:02:00199#if defined(ENABLE_INPUT_SPEECH)
200#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate_bubble_ui.h"
201#endif
202
[email protected]02a3dc122013-06-13 15:07:53203#if defined(FILE_MANAGER_EXTENSION)
[email protected]473c9a4f2013-09-05 03:09:46204#include "chrome/browser/chromeos/file_manager/app_id.h"
[email protected]02a3dc122013-06-13 15:07:53205#endif
206
[email protected]e8b6ca02013-07-10 18:00:51207#if defined(TOOLKIT_GTK)
208#include "chrome/browser/ui/gtk/chrome_browser_main_extra_parts_gtk.h"
209#endif
210
211#if defined(TOOLKIT_VIEWS)
212#include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h"
213#endif
214
215#if defined(USE_ASH)
216#include "chrome/browser/ui/views/ash/chrome_browser_main_extra_parts_ash.h"
217#endif
218
219#if defined(USE_AURA)
220#include "chrome/browser/ui/aura/chrome_browser_main_extra_parts_aura.h"
221#endif
222
223#if defined(USE_X11)
224#include "chrome/browser/chrome_browser_main_extra_parts_x11.h"
225#endif
226
[email protected]c6ce08072013-07-31 07:48:53227#if defined(ENABLE_SPELLCHECK)
228#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
229#endif
230
[email protected]190e5e22013-07-27 05:59:23231using WebKit::WebWindowFeatures;
[email protected]c7abd422012-09-25 00:20:08232using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47233using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03234using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39235using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31236using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59237using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08238using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00239using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11240using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33241using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13242using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06243using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34244using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40245using extensions::Manifest;
[email protected]593d2a72013-07-26 08:48:38246using message_center::NotifierId;
[email protected]631bb742011-11-02 11:29:39247
[email protected]c5dbef02011-05-13 05:06:09248namespace {
249
[email protected]eabbfb12013-04-05 23:28:35250// Cached version of the locale so we can return the locale on the I/O
251// thread.
252base::LazyInstance<std::string> g_io_thread_application_locale;
253
[email protected]93f72062013-05-29 20:29:40254#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40255const char* kPredefinedAllowedSocketOrigins[] = {
256 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18257 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45258 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
259 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
260 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
261 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35262 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54263 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
264 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
265 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
266 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
267 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
268 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38269 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58270 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29271 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]3f6fca22013-08-12 23:13:42272 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
273 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
274 "4EB74897CB187C7633357C2FE832E0AD6A44883A", // see crbug.com/234789
275 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
276 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
277 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40278};
[email protected]93f72062013-05-29 20:29:40279#endif
[email protected]e461da2f2012-02-16 19:06:40280
[email protected]f8f93eb2012-09-25 03:06:24281// Returns a copy of the given url with its host set to given host and path set
282// to given path. Other parts of the url will be the same.
283GURL ReplaceURLHostAndPath(const GURL& url,
284 const std::string& host,
285 const std::string& path) {
286 url_canon::Replacements<char> replacements;
287 replacements.SetHost(host.c_str(),
288 url_parse::Component(0, host.length()));
289 replacements.SetPath(path.c_str(),
290 url_parse::Component(0, path.length()));
291 return url.ReplaceComponents(replacements);
292}
293
294// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
295GURL AddUberHost(const GURL& url) {
296 const std::string uber_host = chrome::kChromeUIUberHost;
297 const std::string new_path = url.host() + url.path();
298
299 return ReplaceURLHostAndPath(url, uber_host, new_path);
300}
301
[email protected]045bf7c2012-09-28 20:27:36302// If url->host() is "chrome" and url->path() has characters other than the
303// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
304// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24305bool RemoveUberHost(GURL* url) {
306 if (url->host() != chrome::kChromeUIUberHost)
307 return false;
308
[email protected]045bf7c2012-09-28 20:27:36309 if (url->path().empty() || url->path() == "/")
310 return false;
311
[email protected]f8f93eb2012-09-25 03:06:24312 const std::string old_path = url->path();
313
314 const std::string::size_type separator = old_path.find('/', 1);
315 std::string new_host;
316 std::string new_path;
317 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36318 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24319 } else {
320 new_host = old_path.substr(1, separator - 1);
321 new_path = old_path.substr(separator);
322 }
323
[email protected]44e8add2013-06-13 17:29:15324 // Do not allow URLs with paths empty before the first slash since we can't
325 // have an empty host. (e.g "foo://chrome//")
326 if (new_host.empty())
327 return false;
328
[email protected]f8f93eb2012-09-25 03:06:24329 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
330
[email protected]44e8add2013-06-13 17:29:15331 DCHECK(url->is_valid());
332
[email protected]f8f93eb2012-09-25 03:06:24333 return true;
334}
335
[email protected]b8148ac2011-07-13 22:03:25336// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42337bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24338 // Do not handle special URLs such as "about:foo"
339 if (!url->host().empty()) {
340 const GURL chrome_url = AddUberHost(*url);
341
342 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
343 // be called.
344 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
345 browser_context, chrome_url))
346 return true;
347 }
348
[email protected]863f70a2012-01-27 02:05:50349 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
350 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25351 return false;
352
[email protected]fe69558d2012-03-12 11:34:49353#if defined(OS_CHROMEOS)
354 // Special case : in ChromeOS in Guest mode bookmarks and history are
355 // disabled for security reasons. New tab page explains the reasons, so
356 // we redirect user to new tab page.
357 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
358 if (url->SchemeIs(chrome::kChromeUIScheme) &&
359 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
360 url->DomainIs(chrome::kChromeUIHistoryHost))) {
361 // Rewrite with new tab URL
362 *url = GURL(chrome::kChromeUINewTabURL);
363 }
364 }
365#endif
366
[email protected]b8148ac2011-07-13 22:03:25367 // Special case the new tab page. In older versions of Chrome, the new tab
368 // page was hosted at chrome-internal:<blah>. This might be in people's saved
369 // sessions or bookmarks, so we say any URL with that scheme triggers the new
370 // tab page.
371 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
372 // Rewrite it with the proper new tab URL.
373 *url = GURL(chrome::kChromeUINewTabURL);
374 }
375
376 return true;
377}
378
[email protected]f8f93eb2012-09-25 03:06:24379// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
380// "chrome://foo/".
381bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
382 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
383 return false;
384
385 return RemoveUberHost(url);
386}
387
[email protected]8d3132f62011-10-12 07:13:42388// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
389// below. Extension, and isolated apps require different privileges to be
390// granted to their RenderProcessHosts. This classification allows us to make
391// sure URLs are served by hosts with the right set of privileges.
392enum RenderProcessHostPrivilege {
393 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45394 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42395 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45396 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42397};
398
399RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
400 const GURL& url,
401 ExtensionService* service) {
402 // Default to a normal renderer cause it is lower privileged. This should only
403 // occur if the URL on a site instance is either malformed, or uninitialized.
404 // If it is malformed, then there is no need for better privileges anyways.
405 // If it is uninitialized, but eventually settles on being an a scheme other
406 // than normal webrenderer, the navigation logic will correct us out of band
407 // anyways.
408 if (!url.is_valid())
409 return PRIV_NORMAL;
410
[email protected]885c0e92012-11-13 20:27:42411 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44412 const Extension* extension =
413 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43414 if (extension &&
415 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42416 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45417 if (extension && extension->is_hosted_app())
418 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42419
420 return PRIV_EXTENSION;
421 }
422
423 return PRIV_NORMAL;
424}
425
426RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30427 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46428 extensions::ProcessMap* process_map,
429 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46430 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30431 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46432 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21433 return PRIV_NORMAL;
434
[email protected]6f371442011-11-09 06:45:46435 for (std::set<std::string>::iterator iter = extension_ids.begin();
436 iter != extension_ids.end(); ++iter) {
437 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43438 if (extension &&
439 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42440 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45441 if (extension && extension->is_hosted_app())
442 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42443 }
444
[email protected]676f6ab2011-10-19 20:23:21445 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42446}
447
[email protected]6786bf402011-12-03 15:19:45448bool CertMatchesFilter(const net::X509Certificate& cert,
449 const base::DictionaryValue& filter) {
450 // TODO(markusheintz): This is the minimal required filter implementation.
451 // Implement a better matcher.
452
453 // An empty filter matches any client certificate since no requirements are
454 // specified at all.
455 if (filter.empty())
456 return true;
457
458 std::string common_name;
459 if (filter.GetString("ISSUER.CN", &common_name) &&
460 (cert.issuer().common_name == common_name)) {
461 return true;
462 }
463 return false;
464}
465
[email protected]f3986f82012-01-03 20:00:06466// Fills |map| with the per-script font prefs under path |map_name|.
467void FillFontFamilyMap(const PrefService* prefs,
468 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53469 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06470 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
471 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
472 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
473 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23474 if (!font_family.empty())
475 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06476 }
477}
478
[email protected]a1733df2012-06-22 11:24:18479#if defined(OS_POSIX) && !defined(OS_MACOSX)
480int GetCrashSignalFD(const CommandLine& command_line) {
481 if (command_line.HasSwitch(switches::kExtensionProcess)) {
482 ExtensionCrashHandlerHostLinux* crash_handler =
483 ExtensionCrashHandlerHostLinux::GetInstance();
484 return crash_handler->GetDeathSignalSocket();
485 }
486
487 std::string process_type =
488 command_line.GetSwitchValueASCII(switches::kProcessType);
489
490 if (process_type == switches::kRendererProcess)
491 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
492
493 if (process_type == switches::kPluginProcess)
494 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
495
496 if (process_type == switches::kPpapiPluginProcess)
497 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
498
499 if (process_type == switches::kGpuProcess)
500 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
501
502 return -1;
503}
504#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
505
[email protected]d5bcd06f2013-04-21 08:07:24506#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30507GURL GetEffectiveURLForSignin(const GURL& url) {
508 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
509
510 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03511 // Copy the path because the argument to SetPathStr must outlive
512 // the Replacements object.
513 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30514 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03515 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30516 effective_url = effective_url.ReplaceComponents(replacements);
517 return effective_url;
518}
[email protected]d5bcd06f2013-04-21 08:07:24519#endif
[email protected]970c63e2013-03-07 00:25:30520
[email protected]eabbfb12013-04-05 23:28:35521void SetApplicationLocaleOnIOThread(const std::string& locale) {
522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
523 g_io_thread_application_locale.Get() = locale;
524}
525
[email protected]190e5e22013-07-27 05:59:23526struct BlockedPopupParams {
527 BlockedPopupParams(const GURL& target_url,
528 const content::Referrer& referrer,
529 WindowOpenDisposition disposition,
530 const WebWindowFeatures& features,
531 bool user_gesture,
532 bool opener_suppressed,
533 int render_process_id,
534 int opener_id)
535 : target_url(target_url),
536 referrer(referrer),
537 disposition(disposition),
538 features(features),
539 user_gesture(user_gesture),
540 opener_suppressed(opener_suppressed),
541 render_process_id(render_process_id),
542 opener_id(opener_id)
543 {}
544
545 GURL target_url;
546 content::Referrer referrer;
547 WindowOpenDisposition disposition;
548 WebWindowFeatures features;
549 bool user_gesture;
550 bool opener_suppressed;
551 int render_process_id;
552 int opener_id;
553};
554
555void HandleBlockedPopupOnUIThread(const BlockedPopupParams& params) {
556 WebContents* tab =
557 tab_util::GetWebContentsByID(params.render_process_id, params.opener_id);
558 if (!tab)
559 return;
560
[email protected]190e5e22013-07-27 05:59:23561 PopupBlockerTabHelper* popup_helper =
562 PopupBlockerTabHelper::FromWebContents(tab);
563 if (!popup_helper)
564 return;
565 popup_helper->AddBlockedPopup(params.target_url,
566 params.referrer,
567 params.disposition,
568 params.features,
569 params.user_gesture,
570 params.opener_suppressed);
571}
[email protected]190e5e22013-07-27 05:59:23572
[email protected]9dbfff12011-07-01 19:37:07573} // namespace
[email protected]c5dbef02011-05-13 05:06:09574
[email protected]d977f9c2011-03-14 16:10:26575namespace chrome {
576
[email protected]e461da2f2012-02-16 19:06:40577ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40578#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40579 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
580 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40581#endif
[email protected]1deace22013-05-22 06:14:46582
583 permissions_policy_delegate_.reset(
584 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40585}
586
587ChromeContentBrowserClient::~ChromeContentBrowserClient() {
588}
589
[email protected]bca18382012-06-25 19:15:23590// static
[email protected]37ca3fe02013-07-05 15:32:44591void ChromeContentBrowserClient::RegisterProfilePrefs(
[email protected]443e9312013-05-06 06:17:34592 user_prefs::PrefRegistrySyncable* registry) {
593 registry->RegisterBooleanPref(
594 prefs::kDisable3DAPIs,
595 false,
596 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
597 registry->RegisterBooleanPref(
598 prefs::kEnableHyperlinkAuditing,
599 true,
600 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
601 registry->RegisterBooleanPref(
602 prefs::kEnableMemoryInfo,
603 false,
604 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23605}
606
[email protected]eabbfb12013-04-05 23:28:35607// static
608void ChromeContentBrowserClient::SetApplicationLocale(
609 const std::string& locale) {
610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
611
612 // This object is guaranteed to outlive all threads so we don't have to
613 // worry about the lack of refcounting and can just post as Unretained.
614 //
615 // The common case is that this function is called early in Chrome startup
616 // before any threads are created (it will also be called later if the user
617 // changes the pref). In this case, there will be no threads created and
618 // posting will fail. When there are no threads, we can just set the string
619 // without worrying about threadsafety.
620 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
621 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
622 g_io_thread_application_locale.Get() = locale;
623 }
624}
625
[email protected]50462bf02011-11-21 19:13:31626content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
627 const content::MainFunctionParams& parameters) {
628 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30629 // Construct the Main browser parts based on the OS type.
630#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31631 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04632#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31633 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30634#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22635 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26636#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31637 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14638#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09639 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30640#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31641 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04642#else
[email protected]b48c9182011-10-26 18:03:30643 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31644 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30645#endif
646
[email protected]7e75e4a2013-05-17 17:20:03647 chrome::AddProfilesExtraParts(main_parts);
648
[email protected]c7480942011-11-08 19:18:27649 // Construct additional browser parts. Stages are called in the order in
650 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22651#if defined(TOOLKIT_GTK)
[email protected]e8b6ca02013-07-10 18:00:51652 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04653#endif
[email protected]c7480942011-11-08 19:18:27654
655#if defined(TOOLKIT_VIEWS)
[email protected]e8b6ca02013-07-10 18:00:51656 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27657#endif
658
[email protected]dc04be7c2012-03-15 23:57:49659#if defined(USE_ASH)
[email protected]e8b6ca02013-07-10 18:00:51660 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
[email protected]dc04be7c2012-03-15 23:57:49661#endif
662
[email protected]e050ef142012-03-21 01:04:24663#if defined(USE_AURA)
[email protected]e8b6ca02013-07-10 18:00:51664 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
665#endif
666
667#if defined(USE_X11)
668 main_parts->AddParts(new ChromeBrowserMainExtraPartsX11());
[email protected]e050ef142012-03-21 01:04:24669#endif
670
[email protected]95132f52013-04-12 02:19:04671 chrome::AddMetricsExtraParts(main_parts);
672
[email protected]50462bf02011-11-21 19:13:31673 return main_parts;
[email protected]f967b722011-09-07 00:58:04674}
675
[email protected]e94bbcb2012-09-07 05:33:57676std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19677 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57678 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53679 std::string partition_id;
680
681 // The partition ID for webview guest processes is the string value of its
682 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
683 if (site.SchemeIs(chrome::kGuestScheme))
684 partition_id = site.spec();
685
[email protected]056efdc2013-04-06 00:14:53686 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53687 return partition_id;
688}
689
690bool ChromeContentBrowserClient::IsValidStoragePartitionId(
691 content::BrowserContext* browser_context,
692 const std::string& partition_id) {
693 // The default ID is empty and is always valid.
694 if (partition_id.empty())
695 return true;
696
697 return GURL(partition_id).is_valid();
698}
699
700void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
701 content::BrowserContext* browser_context,
702 const GURL& site,
[email protected]14acc642012-11-17 12:20:10703 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53704 std::string* partition_domain,
705 std::string* partition_name,
706 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10707 // Default to the browser-wide storage partition and override based on |site|
708 // below.
709 partition_domain->clear();
710 partition_name->clear();
711 *in_memory = false;
712
[email protected]1bc28312012-11-08 08:31:53713 // For the webview tag, we create special guest processes, which host the
714 // tag content separately from the main application that embeds the tag.
715 // A webview tag can specify both the partition name and whether the storage
716 // for that partition should be persisted. Each tag gets a SiteInstance with
717 // a specially formatted URL, based on the application it is hosted by and
718 // the partition requested by it. The format for that URL is:
719 // chrome-guest://partition_domain/persist?partition_name
720 if (site.SchemeIs(chrome::kGuestScheme)) {
721 // Since guest URLs are only used for packaged apps, there must be an app
722 // id in the URL.
723 CHECK(site.has_host());
724 *partition_domain = site.host();
725 // Since persistence is optional, the path must either be empty or the
726 // literal string.
727 *in_memory = (site.path() != "/persist");
728 // The partition name is user supplied value, which we have encoded when the
729 // URL was created, so it needs to be decoded.
730 *partition_name = net::UnescapeURLComponent(site.query(),
731 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10732 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
733 // If |can_be_default| is false, the caller is stating that the |site|
734 // should be parsed as if it had isolated storage. In particular it is
735 // important to NOT check ExtensionService for the is_storage_isolated()
736 // attribute because this code path is run during Extension uninstall
737 // to do cleanup after the Extension has already been unloaded from the
738 // ExtensionService.
739 bool is_isolated = !can_be_default;
740 if (can_be_default) {
741 const Extension* extension = NULL;
742 Profile* profile = Profile::FromBrowserContext(browser_context);
743 ExtensionService* extension_service =
744 extensions::ExtensionSystem::Get(profile)->extension_service();
745 if (extension_service) {
[email protected]be9915fb2013-07-18 09:28:55746 extension =
747 extension_service->extensions()->GetExtensionOrAppByURL(site);
[email protected]561e33d52013-04-03 06:58:43748 if (extension &&
749 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10750 is_isolated = true;
751 }
752 }
753 }
[email protected]1bc28312012-11-08 08:31:53754
[email protected]14acc642012-11-17 12:20:10755 if (is_isolated) {
756 CHECK(site.has_host());
757 // For extensions with isolated storage, the the host of the |site| is
758 // the |partition_domain|. The |in_memory| and |partition_name| are only
759 // used in guest schemes so they are cleared here.
760 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53761 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10762 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53763 }
[email protected]d1198fd2012-08-13 22:50:19764 }
765
[email protected]14acc642012-11-17 12:20:10766 // Assert that if |can_be_default| is false, the code above must have found a
767 // non-default partition. If this fails, the caller has a serious logic
768 // error about which StoragePartition they expect to be in and it is not
769 // safe to continue.
770 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44771}
772
[email protected]38b098f2012-03-14 21:11:57773content::WebContentsViewDelegate*
774 ChromeContentBrowserClient::GetWebContentsViewDelegate(
775 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27776 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32777}
778
[email protected]738f57a2013-06-29 21:06:54779void ChromeContentBrowserClient::GuestWebContentsCreated(
780 WebContents* guest_web_contents,
781 WebContents* opener_web_contents,
[email protected]4c0e8272013-07-03 23:39:22782 content::BrowserPluginGuestDelegate** guest_delegate,
[email protected]738f57a2013-06-29 21:06:54783 scoped_ptr<base::DictionaryValue> extra_params) {
784 if (opener_web_contents) {
785 GuestView* guest = GuestView::FromWebContents(opener_web_contents);
786 if (!guest) {
787 NOTREACHED();
788 return;
789 }
790
791 switch (guest->GetViewType()) {
792 case GuestView::WEBVIEW: {
[email protected]4c0e8272013-07-03 23:39:22793 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54794 break;
795 }
796 case GuestView::ADVIEW: {
[email protected]4c0e8272013-07-03 23:39:22797 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54798 break;
799 }
800 default:
801 NOTREACHED();
802 break;
803 }
804 return;
805 }
806
807 if (!extra_params) {
808 NOTREACHED();
809 return;
810 }
811 std::string api_type;
[email protected]90547d72013-08-06 05:57:27812 extra_params->GetString(guestview::kParameterApi, &api_type);
[email protected]738f57a2013-06-29 21:06:54813
814 if (api_type == "adview") {
[email protected]4c0e8272013-07-03 23:39:22815 *guest_delegate = new AdViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54816 } else if (api_type == "webview") {
[email protected]4c0e8272013-07-03 23:39:22817 *guest_delegate = new WebViewGuest(guest_web_contents);
[email protected]738f57a2013-06-29 21:06:54818 } else {
819 NOTREACHED();
820 }
821}
822
[email protected]44295a12013-06-05 08:45:46823void ChromeContentBrowserClient::GuestWebContentsAttached(
824 WebContents* guest_web_contents,
825 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53826 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06827 Profile* profile = Profile::FromBrowserContext(
828 embedder_web_contents->GetBrowserContext());
829 ExtensionService* service =
830 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]738f57a2013-06-29 21:06:54831 if (!service) {
832 NOTREACHED();
[email protected]44703cc72013-01-24 04:56:06833 return;
[email protected]738f57a2013-06-29 21:06:54834 }
[email protected]44703cc72013-01-24 04:56:06835 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
[email protected]be9915fb2013-07-18 09:28:55836 const Extension* extension =
837 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]738f57a2013-06-29 21:06:54838 if (!extension) {
[email protected]efd6fb02013-08-05 04:44:06839 // It's ok to return here, since we could be running a browser plugin
840 // outside an extension, and don't need to attach a
841 // BrowserPluginGuestDelegate in that case;
842 // e.g. running with flag --enable-browser-plugin-for-all-view-types.
[email protected]738f57a2013-06-29 21:06:54843 return;
[email protected]18699372013-06-25 20:42:55844 }
[email protected]738f57a2013-06-29 21:06:54845
846 GuestView* guest = GuestView::FromWebContents(guest_web_contents);
847 if (!guest) {
848 NOTREACHED();
849 return;
850 }
[email protected]9934a5e2013-08-22 00:07:56851 guest->Attach(embedder_web_contents, extension->id(), extra_params);
[email protected]44703cc72013-01-24 04:56:06852}
853
[email protected]f3b1a082011-11-18 00:34:30854void ChromeContentBrowserClient::RenderProcessHostCreated(
855 content::RenderProcessHost* host) {
856 int id = host->GetID();
857 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41858 net::URLRequestContextGetter* context =
859 profile->GetRequestContextForRenderProcess(id);
860
[email protected]f3b1a082011-11-18 00:34:30861 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41862 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55863#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30864 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55865#endif
[email protected]658677f2012-06-09 06:04:02866#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08867 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03868#endif
[email protected]f3b1a082011-11-18 00:34:30869 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02870 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]c6ce08072013-07-31 07:48:53871#if defined(ENABLE_SPELLCHECK)
[email protected]f3b1a082011-11-18 00:34:30872 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]c6ce08072013-07-31 07:48:53873#endif
[email protected]7ceb99012011-12-21 08:05:56874#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21875 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56876#endif
[email protected]43535512013-02-20 20:41:41877 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
878 id, profile, context));
[email protected]2736c032012-05-11 18:06:07879 host->GetChannel()->AddFilter(
880 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27881 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33882 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31883#if defined(ENABLE_WEBRTC)
884 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
885#endif
[email protected]01e59752013-06-18 00:17:35886#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03887 ExtensionInfoMap* extension_info_map =
888 extensions::ExtensionSystem::Get(profile)->info_map();
889 host->GetChannel()->AddFilter(new NaClHostMessageFilter(
890 id, profile->IsOffTheRecord(),
891 profile->GetPath(), extension_info_map,
892 context));
[email protected]01e59752013-06-18 00:17:35893#endif
[email protected]3e69bc82011-05-26 23:22:38894
[email protected]2ccf45c2011-08-19 23:35:50895 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
896 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07897
898 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56899
900 RendererContentSettingRules rules;
901 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
902 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14903}
904
[email protected]3d7474ff2011-07-27 17:47:37905GURL ChromeContentBrowserClient::GetEffectiveURL(
906 content::BrowserContext* browser_context, const GURL& url) {
907 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52908 if (!profile)
909 return url;
910
[email protected]b3cb3a32013-07-31 01:32:29911 // If the input |url| should be assigned to the Instant renderer, make its
912 // effective URL distinct from other URLs on the search provider's domain.
913 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
914 return chrome::GetEffectiveURLForInstant(url, profile);
915
[email protected]d5bcd06f2013-04-21 08:07:24916#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30917 // If the input |url| should be assigned to the Signin renderer, make its
918 // effective URL distinct from other URLs on the signin service's domain.
919 // Note that the signin renderer will be allowed to sign the user in to
920 // Chrome.
921 if (SigninManager::IsWebBasedSigninFlowURL(url))
922 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24923#endif
[email protected]970c63e2013-03-07 00:25:30924
[email protected]c5dec6292013-01-25 04:54:52925 // If the input |url| is part of an installed app, the effective URL is an
926 // extension URL with the ID of that extension as the host. This has the
927 // effect of grouping apps together in a common SiteInstance.
928 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13929 extensions::ExtensionSystem::Get(profile)->extension_service();
930 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08931 return url;
932
[email protected]06bdd2b2012-11-30 18:47:13933 const Extension* extension = extension_service->extensions()->
[email protected]be9915fb2013-07-18 09:28:55934 GetHostedAppByURL(url);
[email protected]36fb2c7c2011-04-04 15:49:08935 if (!extension)
936 return url;
937
[email protected]15877ca2011-11-18 22:40:52938 // Bookmark apps do not use the hosted app process model, and should be
939 // treated as normal URLs.
940 if (extension->from_bookmark())
941 return url;
942
[email protected]36fb2c7c2011-04-04 15:49:08943 // If the URL is part of an extension's web extent, convert it to an
944 // extension URL.
945 return extension->GetResourceURL(url.path());
946}
947
[email protected]056ad2a2011-07-12 02:13:55948bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37949 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52950 // Non-extension, non-Instant URLs should generally use
951 // process-per-site-instance. Because we expect to use the effective URL,
952 // URLs for hosted apps (apart from bookmark apps) should have an extension
953 // scheme by now.
954
955 Profile* profile = Profile::FromBrowserContext(browser_context);
956 if (!profile)
957 return false;
958
[email protected]df113a12013-07-24 04:56:08959 if (chrome::ShouldUseProcessPerSiteForInstantURL(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52960 return true;
961
[email protected]d5bcd06f2013-04-21 08:07:24962#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30963 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
964 return true;
[email protected]d5bcd06f2013-04-21 08:07:24965#endif
[email protected]970c63e2013-03-07 00:25:30966
[email protected]885c0e92012-11-13 20:27:42967 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55968 return false;
969
[email protected]c5dec6292013-01-25 04:54:52970 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13971 extensions::ExtensionSystem::Get(profile)->extension_service();
972 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55973 return false;
974
[email protected]be9915fb2013-07-18 09:28:55975 const Extension* extension =
976 extension_service->extensions()->GetExtensionOrAppByURL(effective_url);
[email protected]056ad2a2011-07-12 02:13:55977 if (!extension)
978 return false;
979
980 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53981 // permission, or that does not allow JavaScript access to the background
982 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55983 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40984 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06985 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29986 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53987 return false;
988 }
989 }
[email protected]056ad2a2011-07-12 02:13:55990
[email protected]7b54ca02012-03-02 18:06:53991 // Hosted apps that have script access to their background page must use
992 // process per site, since all instances can make synchronous calls to the
993 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55994 return true;
995}
996
[email protected]672c8c12013-03-07 12:30:06997// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41998void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
999 std::vector<std::string>* additional_schemes) {
1000 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:061001}
1002
[email protected]6bd30072013-02-08 18:17:111003net::URLRequestContextGetter*
1004ChromeContentBrowserClient::CreateRequestContext(
1005 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:061006 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111007 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:061008 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111009}
1010
1011net::URLRequestContextGetter*
1012ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
1013 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:401014 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:111015 bool in_memory,
[email protected]672c8c12013-03-07 12:30:061016 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:111017 Profile* profile = Profile::FromBrowserContext(browser_context);
1018 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:061019 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:111020}
1021
[email protected]46fb9442011-12-09 17:57:471022bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
1023 return ProfileIOData::IsHandledURL(url);
1024}
1025
[email protected]c4365fa42013-05-14 01:08:241026bool ChromeContentBrowserClient::CanCommitURL(
1027 content::RenderProcessHost* process_host,
1028 const GURL& url) {
1029 // We need to let most extension URLs commit in any process, since this can
1030 // be allowed due to web_accessible_resources. Most hosted app URLs may also
1031 // load in any process (e.g., in an iframe). However, the Chrome Web Store
1032 // cannot be loaded in iframes and should never be requested outside its
1033 // process.
1034 Profile* profile =
1035 Profile::FromBrowserContext(process_host->GetBrowserContext());
1036 ExtensionService* service =
1037 extensions::ExtensionSystem::Get(profile)->extension_service();
1038 if (!service)
1039 return true;
1040 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551041 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]c4365fa42013-05-14 01:08:241042 if (new_extension &&
1043 new_extension->is_hosted_app() &&
1044 new_extension->id() == extension_misc::kWebStoreAppId &&
1045 !service->process_map()->Contains(new_extension->id(),
1046 process_host->GetID())) {
1047 return false;
1048 }
1049
1050 return true;
1051}
1052
[email protected]9a60d1602013-09-11 04:09:121053bool ChromeContentBrowserClient::ShouldAllowOpenURL(
1054 content::SiteInstance* site_instance, const GURL& url) {
1055 GURL from_url = site_instance->GetSiteURL();
1056 // Do not allow pages from the web or other extensions navigate to
1057 // non-web-accessible extension resources.
1058 if (url.SchemeIs(extensions::kExtensionScheme) &&
1059 (from_url.SchemeIsHTTPOrHTTPS() ||
1060 from_url.SchemeIs(extensions::kExtensionScheme))) {
1061 Profile* profile = Profile::FromBrowserContext(
1062 site_instance->GetProcess()->GetBrowserContext());
1063 ExtensionService* service =
1064 extensions::ExtensionSystem::Get(profile)->extension_service();
1065 if (!service)
1066 return true;
1067 const Extension* extension =
1068 service->extensions()->GetExtensionOrAppByURL(url);
1069 if (!extension)
1070 return true;
1071 const Extension* from_extension =
1072 service->extensions()->GetExtensionOrAppByURL(
1073 site_instance->GetSiteURL());
1074 if (from_extension && from_extension->id() == extension->id())
1075 return true;
1076
1077 if (!extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible(
1078 extension, url.path()))
1079 return false;
1080 }
1081 return true;
1082}
1083
[email protected]2a5221b2011-09-27 23:07:311084bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:301085 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:311086 const GURL& site_url) {
1087 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:301088 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521089 // This may be NULL during tests. In that case, just assume any site can
1090 // share any host.
1091 if (!profile)
1092 return true;
1093
[email protected]d43f99fe2013-04-03 00:20:141094 // Instant URLs should only be in the instant process and instant process
1095 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:521096 InstantService* instant_service =
1097 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:141098 if (instant_service) {
1099 bool is_instant_process = instant_service->IsInstantProcess(
1100 process_host->GetID());
1101 bool should_be_in_instant_process =
1102 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
1103 if (is_instant_process || should_be_in_instant_process)
1104 return is_instant_process && should_be_in_instant_process;
1105 }
[email protected]c5dec6292013-01-25 04:54:521106
[email protected]d5bcd06f2013-04-21 08:07:241107#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301108 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
1109 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
1110 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:241111#endif
[email protected]970c63e2013-03-07 00:25:301112
[email protected]06bdd2b2012-11-30 18:47:131113 ExtensionService* service =
1114 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461115 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:311116
[email protected]ffa97602011-11-17 17:55:521117 // Don't allow the Task Manager to share a process with anything else.
1118 // Otherwise it can affect the renderers it is observing.
1119 // Note: we could create another RenderProcessHostPrivilege bucket for
1120 // this to allow multiple chrome://tasks instances to share, but that's
1121 // a very unlikely case without serious consequences.
1122 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1123 return false;
1124
[email protected]8d3132f62011-10-12 07:13:421125 // These may be NULL during tests. In that case, just assume any site can
1126 // share any host.
[email protected]6f371442011-11-09 06:45:461127 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311128 return true;
1129
[email protected]eec0b33c2011-12-05 22:09:451130 // Otherwise, just make sure the process privilege matches the privilege
1131 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571132 RenderProcessHostPrivilege privilege_required =
1133 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451134 return GetProcessPrivilege(process_host, process_map, service) ==
1135 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311136}
1137
[email protected]76411f412012-02-22 18:56:061138// This function is trying to limit the amount of processes used by extensions
1139// with background pages. It uses a globally set percentage of processes to
1140// run such extensions and if the limit is exceeded, it returns true, to
1141// indicate to the content module to group extensions together.
1142bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1143 content::BrowserContext* browser_context, const GURL& url) {
1144 // It has to be a valid URL for us to check for an extension.
1145 if (!url.is_valid())
1146 return false;
1147
1148 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191149 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131150 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061151 if (!service)
1152 return false;
1153
1154 // We have to have a valid extension with background page to proceed.
1155 const Extension* extension =
[email protected]be9915fb2013-07-18 09:28:551156 service->extensions()->GetExtensionOrAppByURL(url);
[email protected]76411f412012-02-22 18:56:061157 if (!extension)
1158 return false;
[email protected]9367eabc2013-03-01 01:29:291159 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061160 return false;
1161
1162 std::set<int> process_ids;
1163 size_t max_process_count =
1164 content::RenderProcessHost::GetMaxRendererProcessCount();
1165
1166 // Go through all profiles to ensure we have total count of extension
1167 // processes containing background pages, otherwise one profile can
1168 // starve the other.
1169 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1170 GetLoadedProfiles();
1171 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031172 ExtensionProcessManager* epm =
1173 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321174 for (ExtensionProcessManager::const_iterator iter =
1175 epm->background_hosts().begin();
1176 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131177 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321178 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061179 }
1180 }
1181
1182 if (process_ids.size() >
1183 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1184 return true;
1185 }
1186
1187 return false;
1188}
1189
[email protected]6f371442011-11-09 06:45:461190void ChromeContentBrowserClient::SiteInstanceGotProcess(
1191 SiteInstance* site_instance) {
1192 CHECK(site_instance->HasProcess());
1193
1194 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021195 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521196 if (!profile)
1197 return;
1198
1199 // Remember the ID of the Instant process to signal the renderer process
1200 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031201 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321202 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521203 InstantService* instant_service =
1204 InstantServiceFactory::GetForProfile(profile);
1205 if (instant_service)
1206 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1207 }
1208
[email protected]d5bcd06f2013-04-21 08:07:241209#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301210 // We only expect there to be one signin process as we use process-per-site
1211 // for signin URLs. The signin process will be cleared from SigninManager
1212 // when the renderer is destroyed.
1213 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1214 SigninManager* signin_manager =
1215 SigninManagerFactory::GetForProfile(profile);
1216 if (signin_manager)
1217 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461218 BrowserThread::PostTask(
1219 BrowserThread::IO, FROM_HERE,
1220 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1221 extensions::ExtensionSystem::Get(profile)->info_map(),
1222 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301223 }
[email protected]d5bcd06f2013-04-21 08:07:241224#endif
[email protected]970c63e2013-03-07 00:25:301225
[email protected]06bdd2b2012-11-30 18:47:131226 ExtensionService* service =
1227 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461228 if (!service)
1229 return;
1230
[email protected]be9915fb2013-07-18 09:28:551231 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1232 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461233 if (!extension)
1234 return;
1235
[email protected]6bc04fd82011-12-04 02:29:351236 service->process_map()->Insert(extension->id(),
1237 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331238 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461239 BrowserThread::PostTask(
1240 BrowserThread::IO, FROM_HERE,
1241 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591242 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461243 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351244 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331245 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461246}
1247
1248void ChromeContentBrowserClient::SiteInstanceDeleting(
1249 SiteInstance* site_instance) {
1250 if (!site_instance->HasProcess())
1251 return;
1252
1253 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021254 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131255 ExtensionService* service =
1256 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461257 if (!service)
1258 return;
1259
[email protected]be9915fb2013-07-18 09:28:551260 const Extension* extension = service->extensions()->GetExtensionOrAppByURL(
1261 site_instance->GetSiteURL());
[email protected]6f371442011-11-09 06:45:461262 if (!extension)
1263 return;
1264
[email protected]6bc04fd82011-12-04 02:29:351265 service->process_map()->Remove(extension->id(),
1266 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331267 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461268 BrowserThread::PostTask(
1269 BrowserThread::IO, FROM_HERE,
1270 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591271 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461272 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351273 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331274 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461275}
1276
[email protected]f05763972012-06-06 18:17:261277bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141278 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081279 const GURL& current_url,
1280 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261281 if (current_url.is_empty()) {
1282 // Always choose a new process when navigating to extension URLs. The
1283 // process grouping logic will combine all of a given extension's pages
1284 // into the same process.
[email protected]885c0e92012-11-13 20:27:421285 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261286 return true;
[email protected]e3daf3c2011-10-05 21:17:081287
[email protected]f05763972012-06-06 18:17:261288 return false;
1289 }
1290
1291 // Also, we must switch if one is an extension and the other is not the exact
1292 // same extension.
[email protected]885c0e92012-11-13 20:27:421293 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1294 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261295 if (current_url.GetOrigin() != new_url.GetOrigin())
1296 return true;
1297 }
1298
[email protected]e9841fbd2013-02-22 23:12:141299 // The checks below only matter if we can retrieve which extensions are
1300 // installed.
1301 Profile* profile =
1302 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1303 ExtensionService* service =
1304 extensions::ExtensionSystem::Get(profile)->extension_service();
1305 if (!service)
1306 return false;
1307
1308 // We must swap if the URL is for an extension and we are not using an
1309 // extension process.
1310 const Extension* new_extension =
[email protected]be9915fb2013-07-18 09:28:551311 service->extensions()->GetExtensionOrAppByURL(new_url);
[email protected]e9841fbd2013-02-22 23:12:141312 // Ignore all hosted apps except the Chrome Web Store, since they do not
1313 // require their own BrowsingInstance (e.g., postMessage is ok).
1314 if (new_extension &&
1315 new_extension->is_hosted_app() &&
1316 new_extension->id() != extension_misc::kWebStoreAppId)
1317 new_extension = NULL;
1318 if (new_extension &&
1319 site_instance->HasProcess() &&
1320 !service->process_map()->Contains(new_extension->id(),
1321 site_instance->GetProcess()->GetID()))
1322 return true;
1323
[email protected]f05763972012-06-06 18:17:261324 return false;
[email protected]e3daf3c2011-10-05 21:17:081325}
1326
[email protected]395045c2012-05-22 15:04:381327bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1328 content::ResourceContext* resource_context, const GURL& current_url,
1329 const GURL& new_url) {
1330 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1331 return extensions::CrossesExtensionProcessBoundary(
1332 io_data->GetExtensionInfoMap()->extensions(),
[email protected]be9915fb2013-07-18 09:28:551333 current_url, new_url, false);
[email protected]395045c2012-05-22 15:04:381334}
1335
[email protected]3d831992013-07-04 01:13:291336bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) {
1337 return !url.SchemeIs(chrome::kChromeNativeScheme);
1338}
1339
[email protected]763ec4ca2011-04-29 15:48:121340std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1341 const std::string& alias_name) {
1342 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1343}
1344
[email protected]b80f68432011-05-02 17:22:301345void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1346 CommandLine* command_line, int child_process_id) {
[email protected]97425082013-07-16 03:10:071347#if defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301348 if (IsCrashReporterEnabled()) {
1349 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1350 child_process_logging::GetClientId());
1351 }
[email protected]97425082013-07-16 03:10:071352#elif defined(OS_POSIX)
1353 if (IsCrashReporterEnabled()) {
1354 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1355 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1356 }
1357
[email protected]b80f68432011-05-02 17:22:301358#endif // OS_MACOSX
1359
[email protected]f1933792011-06-14 00:49:341360 if (logging::DialogsAreSuppressed())
1361 command_line->AppendSwitch(switches::kNoErrorDialogs);
1362
[email protected]b80f68432011-05-02 17:22:301363 std::string process_type =
1364 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171365 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321366
[email protected]7c9b6f92013-09-10 18:11:351367 static const char* const kCommonSwitchNames[] = {
1368 switches::kChromeFrame,
1369 switches::kUserDataDir, // Make logs go to the right file.
1370 };
1371 command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames,
1372 arraysize(kCommonSwitchNames));
[email protected]9206f2a02013-03-20 01:10:321373
[email protected]718eab62011-10-05 21:16:521374 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:301375#if defined(OS_CHROMEOS)
1376 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441377 browser_command_line.GetSwitchValueASCII(
1378 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301379 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441380 command_line->AppendSwitchASCII(
1381 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301382#endif
1383
[email protected]f3b1a082011-11-18 00:34:301384 content::RenderProcessHost* process =
1385 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371386 if (process) {
1387 Profile* profile = Profile::FromBrowserContext(
1388 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131389 ExtensionService* extension_service =
1390 extensions::ExtensionSystem::Get(profile)->extension_service();
1391 if (extension_service) {
1392 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001393 if (process_map && process_map->Contains(process->GetID()))
1394 command_line->AppendSwitch(switches::kExtensionProcess);
1395 }
[email protected]b80f68432011-05-02 17:22:301396
[email protected]a8d851f82011-12-21 00:32:371397 PrefService* prefs = profile->GetPrefs();
1398 // Currently this pref is only registered if applied via a policy.
1399 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1400 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1401 // Turn this policy into a command line switch.
1402 command_line->AppendSwitch(switches::kDisable3DAPIs);
1403 }
[email protected]718eab62011-10-05 21:16:521404
[email protected]a8d851f82011-12-21 00:32:371405 // Disable client-side phishing detection in the renderer if it is
1406 // disabled in the Profile preferences or the browser process.
1407 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1408 !g_browser_process->safe_browsing_detection_service()) {
1409 command_line->AppendSwitch(
1410 switches::kDisableClientSidePhishingDetection);
1411 }
[email protected]0045b0f42012-07-26 11:52:081412
1413 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211414 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521415
1416 InstantService* instant_service =
1417 InstantServiceFactory::GetForProfile(profile);
1418 if (instant_service &&
1419 instant_service->IsInstantProcess(process->GetID()))
1420 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301421
[email protected]d5bcd06f2013-04-21 08:07:241422#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301423 SigninManager* signin_manager =
1424 SigninManagerFactory::GetForProfile(profile);
1425 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1426 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241427#endif
[email protected]47c7ec82012-01-18 03:29:211428 }
[email protected]4287a3d2011-06-13 23:56:511429
[email protected]16dc42452013-04-09 04:37:191430 if (message_center::IsRichNotificationEnabled())
1431 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191432
[email protected]47c7ec82012-01-18 03:29:211433 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511434 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171435 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481436 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171437 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]49d9b142013-07-19 08:50:271438 extensions::switches::kAllowLegacyExtensionManifests,
1439 extensions::switches::kAllowScriptingGallery,
[email protected]c8d02992013-07-31 22:16:511440 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271441 extensions::switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511442 switches::kAllowHTTPBackgroundPage,
[email protected]9d450492013-06-13 23:08:371443 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1444 // to browser.
1445 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511446 switches::kAppsCheckoutURL,
1447 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311448 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511449 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501450 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531451 switches::kDisableExtensionsResourceWhitelist,
[email protected]83c85262013-08-22 21:13:461452 switches::kDisablePnacl,
[email protected]b0553c7e2012-09-19 21:36:111453 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531454 switches::kEnableAdview,
1455 switches::kEnableAdviewSrcAttribute,
[email protected]1f4da9e2013-06-27 05:23:441456 switches::kEnableAppWindowControls,
[email protected]47c7ec82012-01-18 03:29:211457 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511458 switches::kEnableIPCFuzzing,
1459 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451460 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481461 switches::kEnablePasswordGeneration,
[email protected]4287a3d2011-06-13 23:56:511462 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511463 switches::kMemoryProfiling,
1464 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371465 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371466 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511467 switches::kPpapiFlashArgs,
1468 switches::kPpapiFlashInProcess,
1469 switches::kPpapiFlashPath,
1470 switches::kPpapiFlashVersion,
1471 switches::kProfilingAtStart,
1472 switches::kProfilingFile,
1473 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371474 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511475 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291476 switches::kSpdyProxyAuthOrigin,
[email protected]cbcf3b5b2013-08-06 17:14:191477 switches::kTranslateSecurityOrigin,
[email protected]a446534d2012-02-09 00:07:381478 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511479 };
1480
1481 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1482 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171483 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381484 static const char* const kSwitchNames[] = {
[email protected]c8d02992013-07-31 22:16:511485 extensions::switches::kEnableExperimentalExtensionApis,
[email protected]49d9b142013-07-19 08:50:271486 extensions::switches::kExtensionsOnChromeURLs,
[email protected]eb653f82012-05-24 02:31:351487 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381488 switches::kWhitelistedExtensionID,
1489 };
1490
1491 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1492 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511493 } else if (process_type == switches::kPluginProcess) {
1494 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441495#if defined(OS_CHROMEOS)
1496 chromeos::switches::kLoginProfile,
1497#endif
[email protected]4287a3d2011-06-13 23:56:511498 switches::kMemoryProfiling,
1499 switches::kSilentDumpOnDCHECK,
[email protected]4287a3d2011-06-13 23:56:511500 };
1501
1502 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1503 arraysize(kSwitchNames));
1504 } else if (process_type == switches::kZygoteProcess) {
1505 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511506 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501507 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511508 switches::kPpapiFlashInProcess,
1509 switches::kPpapiFlashPath,
1510 switches::kPpapiFlashVersion,
1511 };
1512
1513 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1514 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111515 } else if (process_type == switches::kGpuProcess) {
1516 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1517 // because GPU is expected to be unreliable.
1518 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1519 !command_line->HasSwitch(switches::kDisableBreakpad))
1520 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301521 }
[email protected]6f08af82011-09-15 01:19:031522
1523 // The command line switch kEnableBenchmarking needs to be specified along
1524 // with the kEnableStatsTable switch to ensure that the stats table global
1525 // is initialized correctly.
1526 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1527 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301528}
1529
1530std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431531 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351532 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301533 return g_browser_process->GetApplicationLocale();
1534}
1535
[email protected]597a867b2011-11-18 18:31:201536std::string ChromeContentBrowserClient::GetAcceptLangs(
1537 content::BrowserContext* context) {
1538 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371539 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081540}
1541
[email protected]9ec0f452012-05-31 15:58:531542gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221543 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531544 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081545}
1546
[email protected]a2176792011-05-08 19:30:491547bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091548 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191549 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201550 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201552 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051553 return io_data->GetCookieSettings()->
1554 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491555}
1556
[email protected]ed24fad2011-05-10 22:44:011557bool ChromeContentBrowserClient::AllowGetCookie(
1558 const GURL& url,
1559 const GURL& first_party,
1560 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201561 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011562 int render_process_id,
1563 int render_view_id) {
1564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201565 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051566 bool allow = io_data->GetCookieSettings()->
1567 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011568
[email protected]8093a542011-05-13 07:29:321569 BrowserThread::PostTask(
1570 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031571 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431572 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011573 return allow;
1574}
1575
1576bool ChromeContentBrowserClient::AllowSetCookie(
1577 const GURL& url,
1578 const GURL& first_party,
1579 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201580 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011581 int render_process_id,
1582 int render_view_id,
1583 net::CookieOptions* options) {
1584 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201585 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051586 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1587 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1588
[email protected]8093a542011-05-13 07:29:321589 BrowserThread::PostTask(
1590 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031591 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431592 render_view_id, url, first_party, cookie_line, *options,
1593 !allow));
[email protected]ed24fad2011-05-10 22:44:011594 return allow;
1595}
1596
[email protected]d5a19162011-06-30 18:51:541597bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201598 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201600 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431601 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1602 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261603
[email protected]bf510ed2012-06-05 08:31:431604 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1605 // Could we even support per-origin settings?
1606 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541607}
1608
[email protected]5c5a88e2011-11-12 00:45:351609bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351610 const GURL& url,
1611 const string16& name,
1612 const string16& display_name,
1613 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201614 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481615 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351616 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201617 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351618 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1619 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1620
[email protected]62151052012-02-01 18:40:481621 // Record access to database 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::WebDatabaseAccessed,
1627 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351628 }
1629
1630 return allow;
1631}
1632
1633bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351634 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201635 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481636 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201638 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351639 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1640 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1641
[email protected]62151052012-02-01 18:40:481642 // Record access to file system for potential display in UI.
1643 std::vector<std::pair<int, int> >::const_iterator i;
1644 for (i = render_views.begin(); i != render_views.end(); ++i) {
1645 BrowserThread::PostTask(
1646 BrowserThread::UI, FROM_HERE,
1647 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1648 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351649 }
1650
1651 return allow;
1652}
1653
[email protected]7c5ff9a2012-03-02 07:42:491654bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1655 const GURL& url,
1656 const string16& name,
1657 content::ResourceContext* context,
1658 const std::vector<std::pair<int, int> >& render_views) {
1659 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1660 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1661 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1662 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1663
1664 // Record access to IndexedDB for potential display in UI.
1665 std::vector<std::pair<int, int> >::const_iterator i;
1666 for (i = render_views.begin(); i != render_views.end(); ++i) {
1667 BrowserThread::PostTask(
1668 BrowserThread::UI, FROM_HERE,
1669 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1670 i->first, i->second, url, name, !allow));
1671 }
1672
1673 return allow;
1674}
1675
[email protected]33ad6ce92013-08-27 14:39:081676net::URLRequestContext*
1677ChromeContentBrowserClient::OverrideRequestContextForURL(
1678 const GURL& url, content::ResourceContext* context) {
1679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1680 if (url.SchemeIs(extensions::kExtensionScheme)) {
1681 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1682 return io_data->extensions_request_context();
1683 }
1684
1685 return NULL;
1686}
1687
[email protected]317f96c92011-05-31 06:53:411688QuotaPermissionContext*
1689ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1690 return new ChromeQuotaPermissionContext();
1691}
1692
[email protected]848dd042011-06-04 18:24:031693void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171694 int render_process_id,
1695 int render_view_id,
1696 int cert_error,
1697 const net::SSLInfo& ssl_info,
1698 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021699 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031700 bool overridable,
[email protected]d9be47702012-05-16 03:41:221701 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171702 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001703 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021704 if (resource_type != ResourceType::MAIN_FRAME) {
1705 // A sub-resource has a certificate error. The user doesn't really
1706 // have a context for making the right decision, so block the
1707 // request hard, without an info bar to allow showing the insecure
1708 // content.
[email protected]8c965c22013-05-23 19:28:001709 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021710 return;
1711 }
1712
[email protected]f9034cf2011-07-21 12:43:411713 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131714 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171715 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411716 if (!tab) {
1717 NOTREACHED();
1718 return;
1719 }
1720 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501721 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301722 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011723 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1724 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411725 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171726 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411727 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001728 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411729 return;
1730 }
1731 }
1732
[email protected]1e87df32012-09-12 04:53:191733#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231734 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1735 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1736 if (captive_portal_tab_helper)
1737 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191738#endif
1739
[email protected]f9034cf2011-07-21 12:43:411740 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221741 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1742 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031743}
1744
[email protected]c99c442e2011-08-24 11:37:301745void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451746 int render_process_id,
1747 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401748 const net::HttpNetworkSession* network_session,
1749 net::SSLCertRequestInfo* cert_request_info,
1750 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131751 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451752 render_process_id, render_view_id);
1753 if (!tab) {
1754 NOTREACHED();
1755 return;
1756 }
1757
[email protected]6786bf402011-12-03 15:19:451758 GURL requesting_url("https://" + cert_request_info->host_and_port);
1759 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1760 << cert_request_info->host_and_port;
1761
[email protected]627e0512011-12-21 22:55:301762 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451763 scoped_ptr<Value> filter(
1764 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1765 requesting_url,
1766 requesting_url,
1767 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1768 std::string(), NULL));
1769
1770 if (filter.get()) {
1771 // Try to automatically select a client certificate.
1772 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1773 DictionaryValue* filter_dict =
1774 static_cast<DictionaryValue*>(filter.get());
1775
1776 const std::vector<scoped_refptr<net::X509Certificate> >&
1777 all_client_certs = cert_request_info->client_certs;
1778 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091779 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451780 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091781 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451782 return;
1783 }
1784 }
1785 } else {
1786 NOTREACHED();
1787 }
1788 }
1789
[email protected]11feec322012-09-18 03:58:521790 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1791 if (!ssl_tab_helper) {
1792 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451793 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141794 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401795 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451796 return;
1797 }
[email protected]11feec322012-09-18 03:58:521798 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401799 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451800}
1801
[email protected]3b455502012-12-11 18:22:581802void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451803 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581804 net::CertificateMimeType cert_type,
1805 const void* cert_data,
1806 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451807 int render_process_id,
1808 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581809 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1810 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451811}
1812
[email protected]dc73a7b2012-03-25 15:27:181813content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561814 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181815}
1816
[email protected]941623e2011-06-07 23:06:041817void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1818 const GURL& source_origin,
1819 int callback_context,
1820 int render_process_id,
1821 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111822#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021823 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1824 WebContents* contents =
1825 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1826 if (!contents) {
[email protected]941623e2011-06-07 23:06:041827 NOTREACHED();
1828 return;
1829 }
1830
[email protected]d0d9c3ee2012-06-19 03:07:021831 // Skip showing the infobar if the request comes from an extension, and that
1832 // extension has the 'notify' permission. (If the extension does not have the
1833 // permission, the user will still be prompted.)
1834 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011835 ExtensionInfoMap* extension_info_map =
1836 extensions::ExtensionSystem::Get(profile)->info_map();
1837 DesktopNotificationService* notification_service =
1838 DesktopNotificationServiceFactory::GetForProfile(profile);
1839 const Extension* extension = NULL;
1840 if (extension_info_map) {
1841 ExtensionSet extensions;
1842 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1843 source_origin, render_process_id,
1844 extensions::APIPermission::kNotification, &extensions);
1845 for (ExtensionSet::const_iterator iter = extensions.begin();
1846 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381847 if (notification_service->IsNotifierEnabled(NotifierId(
1848 NotifierId::APPLICATION, (*iter)->id()))) {
[email protected]cadac622013-06-11 16:46:361849 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011850 break;
1851 }
1852 }
1853 }
[email protected]eb4832a2012-12-08 01:57:521854 RenderViewHost* rvh =
1855 RenderViewHost::FromID(render_process_id, render_view_id);
1856 if (IsExtensionWithPermissionOrSuggestInConsole(
1857 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021858 if (rvh)
1859 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1860 return;
1861 }
1862
[email protected]c7cd5942013-04-30 03:31:011863 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021864 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111865#else
1866 NOTIMPLEMENTED();
1867#endif
[email protected]941623e2011-06-07 23:06:041868}
1869
1870WebKit::WebNotificationPresenter::Permission
1871 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021872 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201873 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021874 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111875#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041876 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]5c129792013-07-10 02:08:481877 // Sometimes a notification may be invoked during the shutdown.
1878 // See http://crbug.com/256638
1879 if (browser_shutdown::IsTryingToQuit())
1880 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
1881
[email protected]df02aca2012-02-09 21:03:201882 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041883
[email protected]c7cd5942013-04-30 03:31:011884 DesktopNotificationService* notification_service =
1885 io_data->GetNotificationService();
1886 if (notification_service) {
1887 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1888 ExtensionSet extensions;
1889 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1890 source_origin, render_process_id,
1891 extensions::APIPermission::kNotification, &extensions);
1892 for (ExtensionSet::const_iterator iter = extensions.begin();
1893 iter != extensions.end(); ++iter) {
[email protected]593d2a72013-07-26 08:48:381894 NotifierId notifier_id(NotifierId::APPLICATION, (*iter)->id());
1895 if (notification_service->IsNotifierEnabled(notifier_id))
[email protected]c7cd5942013-04-30 03:31:011896 return WebKit::WebNotificationPresenter::PermissionAllowed;
1897 }
1898
1899 return notification_service->HasPermission(source_origin);
1900 }
1901
1902 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111903#else
1904 return WebKit::WebNotificationPresenter::PermissionAllowed;
1905#endif
[email protected]941623e2011-06-07 23:06:041906}
1907
1908void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171909 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041910 int render_process_id,
1911 int render_view_id,
1912 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111913#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041914 RenderViewHost* rvh = RenderViewHost::FromID(
1915 render_process_id, render_view_id);
1916 if (!rvh) {
1917 NOTREACHED();
1918 return;
1919 }
1920
[email protected]9f76c1e2012-03-05 15:15:581921 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301922 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041923 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371924 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041925 service->ShowDesktopNotification(
1926 params, render_process_id, render_view_id,
1927 worker ? DesktopNotificationService::WorkerNotification :
1928 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111929#else
1930 NOTIMPLEMENTED();
1931#endif
[email protected]941623e2011-06-07 23:06:041932}
1933
1934void ChromeContentBrowserClient::CancelDesktopNotification(
1935 int render_process_id,
1936 int render_view_id,
1937 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111938#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041939 RenderViewHost* rvh = RenderViewHost::FromID(
1940 render_process_id, render_view_id);
1941 if (!rvh) {
1942 NOTREACHED();
1943 return;
1944 }
1945
[email protected]9f76c1e2012-03-05 15:15:581946 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301947 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041948 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371949 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041950 service->CancelDesktopNotification(
1951 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111952#else
1953 NOTIMPLEMENTED();
1954#endif
[email protected]941623e2011-06-07 23:06:041955}
1956
[email protected]9f3fba52011-06-08 20:37:191957bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351958 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021959 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191960 WindowContainerType container_type,
[email protected]190e5e22013-07-27 05:59:231961 const GURL& target_url,
1962 const content::Referrer& referrer,
1963 WindowOpenDisposition disposition,
1964 const WebWindowFeatures& features,
1965 bool user_gesture,
1966 bool opener_suppressed,
[email protected]df02aca2012-02-09 21:03:201967 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011968 int render_process_id,
[email protected]190e5e22013-07-27 05:59:231969 bool is_guest,
1970 int opener_id,
[email protected]03b6d552012-03-29 04:03:011971 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191972 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011973
1974 *no_javascript_access = false;
1975
[email protected]9f3fba52011-06-08 20:37:191976 // If the opener is trying to create a background window but doesn't have
1977 // the appropriate permission, fail the attempt.
[email protected]6940eef82013-09-11 11:58:411978 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1979 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
[email protected]7b54ca02012-03-02 18:06:531980
[email protected]6940eef82013-09-11 11:58:411981 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]03b6d552012-03-29 04:03:011982 if (!map->SecurityOriginHasAPIPermission(
1983 source_origin,
1984 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061985 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011986 return false;
1987 }
1988
[email protected]7b54ca02012-03-02 18:06:531989 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1990 // return a recently installed Extension even if this CanCreateWindow call
1991 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011992 // because the permission check above would have caused an early return
1993 // already. We must use the full URL to find hosted apps, though, and not
1994 // just the origin.
[email protected]be9915fb2013-07-18 09:28:551995 const Extension* extension =
1996 map->extensions().GetExtensionOrAppByURL(opener_url);
[email protected]9367eabc2013-03-01 01:29:291997 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011998 *no_javascript_access = true;
[email protected]190e5e22013-07-27 05:59:231999
2000 return true;
[email protected]9f3fba52011-06-08 20:37:192001 }
[email protected]056efdc2013-04-06 00:14:532002
2003 // No new browser window (popup or tab) in app mode.
2004 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
2005 chrome::IsRunningInForcedAppMode()) {
2006 return false;
2007 }
2008
[email protected]d2bac6b2013-08-13 03:42:362009 if (g_browser_process->prerender_tracker() &&
2010 g_browser_process->prerender_tracker()->TryCancelOnIOThread(
2011 render_process_id,
2012 opener_id,
2013 prerender::FINAL_STATUS_CREATE_NEW_WINDOW)) {
2014 return false;
2015 }
2016
[email protected]190e5e22013-07-27 05:59:232017 if (is_guest)
2018 return true;
2019
[email protected]6940eef82013-09-11 11:58:412020 // Extensions are whitelisted for popup blocking.
2021 const Extension* extension =
2022 map->extensions().GetExtensionOrAppByURL(opener_url);
2023 if (extension &&
2024 map->process_map().Contains(extension->id(), render_process_id)) {
2025 return true;
2026 }
2027
[email protected]190e5e22013-07-27 05:59:232028 HostContentSettingsMap* content_settings =
2029 ProfileIOData::FromResourceContext(context)->GetHostContentSettingsMap();
2030
[email protected]7f53dff2013-08-05 10:45:502031 if (!user_gesture && !CommandLine::ForCurrentProcess()->HasSwitch(
2032 switches::kDisablePopupBlocking)) {
[email protected]190e5e22013-07-27 05:59:232033 if (content_settings->GetContentSetting(opener_url,
2034 opener_url,
2035 CONTENT_SETTINGS_TYPE_POPUPS,
2036 std::string()) ==
2037 CONTENT_SETTING_ALLOW) {
2038 return true;
2039 }
2040
2041 BrowserThread::PostTask(BrowserThread::UI,
2042 FROM_HERE,
2043 base::Bind(&HandleBlockedPopupOnUIThread,
2044 BlockedPopupParams(target_url,
2045 referrer,
2046 disposition,
2047 features,
2048 user_gesture,
2049 opener_suppressed,
2050 render_process_id,
2051 opener_id)));
2052 return false;
2053 }
[email protected]190e5e22013-07-27 05:59:232054
[email protected]9f3fba52011-06-08 20:37:192055 return true;
2056}
2057
2058std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:202059 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:192060 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2061 // Check if it's an extension-created worker, in which case we want to use
2062 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:202063 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:192064 const Extension* extension =
2065 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
2066 return extension ? extension->name() : std::string();
2067}
2068
[email protected]99907362012-01-11 05:41:402069void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
2070 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:172071}
2072
[email protected]7a06d282013-05-03 04:39:332073// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:022074content::SpeechRecognitionManagerDelegate*
2075 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]855e18b2013-07-08 21:02:002076#if defined(ENABLE_INPUT_SPEECH)
2077 return new speech::ChromeSpeechRecognitionManagerDelegateBubbleUI();
[email protected]a03f2d32012-03-14 00:26:322078#else
[email protected]855e18b2013-07-08 21:02:002079 // Platforms who don't implement x-webkit-speech (a.k.a INPUT_SPEECH) just
2080 // need the base delegate without the bubble UI.
2081 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:322082#endif
[email protected]66cfec62012-02-24 17:57:512083}
2084
[email protected]ae6e9912011-07-27 01:18:282085net::NetLog* ChromeContentBrowserClient::GetNetLog() {
2086 return g_browser_process->net_log();
2087}
2088
[email protected]32538d92011-08-25 00:09:232089AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
2090 return new ChromeAccessTokenStore();
2091}
2092
[email protected]dbae6b02011-06-29 23:51:412093bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:012094 return true;
[email protected]dbae6b02011-06-29 23:51:412095}
2096
[email protected]64d69de42012-02-06 00:19:542097void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:322098 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:062099 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582100 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:062101 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:062102
[email protected]f3986f82012-01-03 20:00:062103 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542104 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:062105 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542106 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:062107 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542108 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062109 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542110 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:062111 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542112 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:062113 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:542114 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:032115 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
2116 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:062117
[email protected]64d69de42012-02-06 00:19:542118 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:402119 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:542120 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:402121 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:542122 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:402123 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:542124 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:402125 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:062126
[email protected]ddf72142012-05-22 04:52:402127 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062128
[email protected]64d69de42012-02-06 00:19:542129 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:402130 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:542131 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:062132 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:542133 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:062134 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
2135 const DictionaryValue* inspector_settings =
2136 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
2137 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:182138 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
2139 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:062140 std::string value;
[email protected]c40ef1c2013-02-25 18:42:182141 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:542142 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:182143 std::make_pair(iter.key(), value));
2144 }
[email protected]f3986f82012-01-03 20:00:062145 }
2146 }
[email protected]64d69de42012-02-06 00:19:542147 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:062148
[email protected]ddf72142012-05-22 04:52:402149 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:542150 web_prefs->javascript_enabled = false;
2151 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
2152 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:402153 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:542154 web_prefs->plugins_enabled = false;
2155 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
2156 web_prefs->java_enabled = false;
2157 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:402158 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:062159
[email protected]64d69de42012-02-06 00:19:542160 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
2161 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:062162
[email protected]64d69de42012-02-06 00:19:542163 web_prefs->memory_info_enabled =
2164 prefs->GetBoolean(prefs::kEnableMemoryInfo);
2165 web_prefs->allow_displaying_insecure_content =
2166 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
2167 web_prefs->allow_running_insecure_content =
2168 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:322169#if defined(OS_ANDROID)
2170 web_prefs->font_scale_factor =
2171 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
2172 web_prefs->force_enable_zoom =
2173 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
2174#endif
[email protected]5c915252013-05-07 13:15:392175
[email protected]af4256d52013-06-04 20:39:072176#if defined(OS_ANDROID)
2177 web_prefs->password_echo_enabled =
2178 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2179#else
[email protected]9d06d88d2012-02-23 22:37:082180 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072181#endif
2182
[email protected]5c915252013-05-07 13:15:392183#if defined(OS_CHROMEOS)
2184 // Enable password echo during OOBE when keyboard driven flag is set.
2185 if (chromeos::UserManager::IsInitialized() &&
2186 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
[email protected]c94ac692013-07-27 00:50:102187 !chromeos::StartupUtils::IsOobeCompleted() &&
2188 chromeos::system::keyboard_settings::ForceKeyboardDrivenUINavigation()) {
2189 web_prefs->password_echo_enabled = true;
[email protected]5c915252013-05-07 13:15:392190 }
2191#endif
[email protected]f3986f82012-01-03 20:00:062192
[email protected]46f8e742013-05-03 18:37:142193#if defined(OS_ANDROID)
2194 web_prefs->user_style_sheet_enabled = false;
2195#else
[email protected]64d69de42012-02-06 00:19:542196 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152197 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362198 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152199 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542200 web_prefs->user_style_sheet_enabled = true;
2201 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152202 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542203 } else {
2204 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062205 }
[email protected]46f8e742013-05-03 18:37:142206#endif
[email protected]f3986f82012-01-03 20:00:062207
[email protected]cfadadd2013-04-03 04:43:022208 web_prefs->asynchronous_spell_checking_enabled = true;
2209 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572210
[email protected]64d69de42012-02-06 00:19:542211 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062212 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542213 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062214 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542215 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062216 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2217
2218 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542219 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062220 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542221 web_prefs->default_encoding);
2222 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402223 prefs->ClearPref(prefs::kDefaultCharset);
2224 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062225 }
[email protected]64d69de42012-02-06 00:19:542226 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062227
[email protected]299d7f12012-05-23 05:31:152228 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232229 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132230 ExtensionService* service =
2231 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062232 if (service) {
[email protected]1bc28312012-11-08 08:31:532233 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2234 const Extension* extension = service->extensions()->GetByID(url.host());
2235 // Ensure that we are only granting extension preferences to URLs with
2236 // the correct scheme. Without this check, chrome-guest:// schemes used by
2237 // webview tags as well as hosts that happen to match the id of an
2238 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422239 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532240 extension_webkit_preferences::SetPreferences(
2241 extension, view_type, web_prefs);
2242 }
[email protected]f3986f82012-01-03 20:00:062243 }
2244
[email protected]cb2edf22013-04-01 20:25:232245 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542246 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232247 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062248 // Disable all kinds of acceleration for background pages.
2249 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542250 web_prefs->force_compositing_mode = false;
2251 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062252 }
[email protected]2e21fe292012-03-02 22:52:322253
2254#if defined(FILE_MANAGER_EXTENSION)
2255 // Override the default of suppressing HW compositing for WebUI pages for the
2256 // file manager, which is implemented using WebUI but wants HW acceleration
2257 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532258 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]2de96a52013-08-14 01:18:092259 url.host() == file_manager::kFileManagerAppId) {
[email protected]2e21fe292012-03-02 22:52:322260 web_prefs->accelerated_compositing_enabled = true;
2261 web_prefs->accelerated_2d_canvas_enabled = true;
2262 }
2263#endif
[email protected]181a95ee2011-07-12 19:26:362264}
2265
2266void ChromeContentBrowserClient::UpdateInspectorSetting(
2267 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062268 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582269 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062270 DictionaryPrefUpdate update(
2271 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2272 prefs::kWebKitInspectorSettings);
2273 DictionaryValue* inspector_settings = update.Get();
2274 inspector_settings->SetWithoutPathExpansion(key,
2275 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362276}
2277
[email protected]b8148ac2011-07-13 22:03:252278void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2279 BrowserURLHandler* handler) {
2280 // Add the default URL handlers.
2281 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2282 BrowserURLHandler::null_handler());
2283 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2284 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2285
[email protected]b3adbd02011-11-30 22:23:272286 // about: handler. Must come before chrome: handler, since it will
2287 // rewrite about: urls to chrome: URLs and then expect chrome: to
2288 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252289 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2290 BrowserURLHandler::null_handler());
[email protected]231dba22013-07-25 23:53:032291
2292 // Handler to rewrite chrome://newtab for InstantExtended.
2293 handler->AddHandlerPair(&chrome::HandleNewTabURLRewrite,
2294 &chrome::HandleNewTabURLReverseRewrite);
2295
[email protected]b8148ac2011-07-13 22:03:252296 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242297 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252298}
2299
2300void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372301 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582302 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472303 BrowsingDataRemover* remover =
2304 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552305 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2306 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252307 // BrowsingDataRemover takes care of deleting itself when done.
2308}
2309
2310void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372311 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582312 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472313 BrowsingDataRemover* remover =
2314 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232315 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552316 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252317 // BrowsingDataRemover takes care of deleting itself when done.
2318}
2319
[email protected]650b2d52013-02-10 03:41:452320base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]b1d97272013-08-17 13:38:492321 return DownloadPrefs::GetDefaultDownloadDirectory();
[email protected]e1d16eb92011-08-18 23:19:322322}
2323
[email protected]c9b6eb62011-10-18 20:49:392324std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2325 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2326}
2327
[email protected]b7631cc2012-09-15 05:08:382328void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2329 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542330#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382331 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2332 scoped_ptr<ppapi::host::HostFactory>(
2333 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542334#endif
[email protected]b7631cc2012-09-15 05:08:382335}
2336
[email protected]0c7193742012-11-07 19:05:032337content::BrowserPpapiHost*
2338 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2339 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132340 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032341 while (!iter.Done()) {
2342 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2343 if (host->process() &&
2344 host->process()->GetData().id == plugin_process_id) {
2345 // Found the plugin.
2346 return host->browser_ppapi_host();
2347 }
2348 ++iter;
2349 }
2350 return NULL;
2351}
2352
[email protected]7b38b192013-03-23 18:39:312353bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2354 content::BrowserContext* browser_context, const GURL& site_url) {
2355 if (CommandLine::ForCurrentProcess()->HasSwitch(
2356 switches::kEnableBrowserPluginForAllViewTypes))
2357 return true;
2358
2359 Profile* profile = Profile::FromBrowserContext(browser_context);
2360 ExtensionService* service =
2361 extensions::ExtensionSystem::Get(profile)->extension_service();
2362 if (!service)
2363 return false;
2364
[email protected]be9915fb2013-07-18 09:28:552365 const Extension* extension =
2366 service->extensions()->GetExtensionOrAppByURL(site_url);
[email protected]7b38b192013-03-23 18:39:312367 if (!extension)
2368 return false;
2369
[email protected]c2d2f102013-04-29 16:42:582370 return extension->HasAPIPermission(APIPermission::kWebView) ||
2371 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312372}
2373
[email protected]38cd8f7f2012-06-15 22:06:072374bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582375 content::BrowserContext* browser_context,
2376 const GURL& url,
[email protected]dda54822013-06-15 01:26:392377 bool private_api,
[email protected]157cc902012-11-02 06:31:582378 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402379#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372380 Profile* profile = Profile::FromBrowserContext(browser_context);
2381 const ExtensionSet* extension_set = NULL;
2382 if (profile) {
2383 extension_set = extensions::ExtensionSystem::Get(profile)->
2384 extension_service()->extensions();
2385 }
[email protected]dda54822013-06-15 01:26:392386
2387 if (private_api) {
2388 // Access to private socket APIs is controlled by the whitelist.
2389 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2390 allowed_socket_origins_)) {
2391 return true;
2392 }
2393 } else {
2394 // Access to public socket APIs is controlled by extension permissions.
2395 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2396 extension_set) {
2397 const Extension* extension = extension_set->GetByID(url.host());
2398 if (extension) {
2399 extensions::SocketPermission::CheckParam check_params(
2400 params.type, params.host, params.port);
2401 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2402 extension, extensions::APIPermission::kSocket, &check_params)) {
2403 return true;
2404 }
2405 }
2406 }
2407 }
2408
2409 // Allow both public and private APIs if the command line says so.
2410 return IsHostAllowedByCommandLine(url, extension_set,
2411 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402412#else
[email protected]a658d452012-03-02 12:45:292413 return false;
[email protected]93f72062013-05-29 20:29:402414#endif
[email protected]e461da2f2012-02-16 19:06:402415}
2416
[email protected]a28e3302013-02-03 03:50:432417ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2418 WebContents* web_contents) {
2419 return new ChromeSelectFilePolicy(web_contents);
2420}
2421
[email protected]7d9424702013-04-14 13:14:162422void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2423 std::vector<std::string>* additional_allowed_schemes) {
2424 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2425 additional_allowed_schemes);
2426 additional_allowed_schemes->push_back(kChromeUIScheme);
2427 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2428}
2429
[email protected]f19bbf62013-07-09 01:22:322430void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
[email protected]0ff5eb52013-07-10 20:35:312431 content::BrowserContext* browser_context,
[email protected]02250952013-04-24 23:52:532432 const base::FilePath& storage_partition_path,
[email protected]f19bbf62013-07-09 01:22:322433 ScopedVector<fileapi::FileSystemBackend>* additional_backends) {
[email protected]02250952013-04-24 23:52:532434#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032435 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]f19bbf62013-07-09 01:22:322436 additional_backends->push_back(new MediaFileSystemBackend(
[email protected]30a306f42013-06-10 03:09:032437 storage_partition_path,
2438 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]f19bbf62013-07-09 01:22:322439 MediaFileSystemBackend::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532440#endif
[email protected]b40015c2013-06-26 08:13:312441#if defined(OS_CHROMEOS)
[email protected]0ff5eb52013-07-10 20:35:312442 fileapi::ExternalMountPoints* external_mount_points =
2443 content::BrowserContext::GetMountPoints(browser_context);
[email protected]b40015c2013-06-26 08:13:312444 DCHECK(external_mount_points);
[email protected]f19bbf62013-07-09 01:22:322445 chromeos::FileSystemBackend* backend =
2446 new chromeos::FileSystemBackend(
[email protected]0ff5eb52013-07-10 20:35:312447 new drive::FileSystemBackendDelegate(browser_context),
2448 browser_context->GetSpecialStoragePolicy(),
[email protected]b40015c2013-06-26 08:13:312449 external_mount_points,
2450 fileapi::ExternalMountPoints::GetSystemInstance());
[email protected]f19bbf62013-07-09 01:22:322451 backend->AddSystemMountPoints();
2452 DCHECK(backend->CanHandleType(fileapi::kFileSystemTypeExternal));
2453 additional_backends->push_back(backend);
[email protected]b40015c2013-06-26 08:13:312454#endif
[email protected]445b7db2013-08-02 04:58:272455
[email protected]e86e2be2013-08-30 11:20:392456 additional_backends->push_back(
2457 new sync_file_system::SyncFileSystemBackend(
2458 Profile::FromBrowserContext(browser_context)));
[email protected]02250952013-04-24 23:52:532459}
2460
[email protected]e60c0232011-11-11 19:56:352461#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182462void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2463 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382464 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082465 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392466#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452467 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392468 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2469 DCHECK(!data_path.empty());
2470
2471 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452472 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392473 data_path.AppendASCII("chrome_100_percent.pak");
[email protected]5db2b7492013-08-23 05:33:092474 base::PlatformFile f =
2475 base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
[email protected]29699c22012-10-03 23:57:392476 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372477 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392478 FileDescriptor(f, true)));
2479
2480 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452481 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392482 GetLocaleFilePath(locale, false);
2483 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2484 DCHECK(f != base::kInvalidPlatformFileValue);
2485 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2486 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382487
[email protected]650b2d52013-02-10 03:41:452488 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372489 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2490 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2491 DCHECK(f != base::kInvalidPlatformFileValue);
2492 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2493 FileDescriptor(f, true)));
2494
[email protected]82174aa2013-01-22 21:53:432495 if (IsCrashReporterEnabled()) {
2496 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2497 if (f == base::kInvalidPlatformFileValue) {
2498 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2499 "be disabled for this process.";
2500 } else {
2501 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2502 FileDescriptor(f, true)));
2503 }
[email protected]40da3e0c2012-10-24 22:03:382504 }
[email protected]40da3e0c2012-10-24 22:03:382505
2506#else
2507 int crash_signal_fd = GetCrashSignalFD(command_line);
2508 if (crash_signal_fd >= 0) {
2509 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2510 FileDescriptor(crash_signal_fd,
2511 false)));
2512 }
[email protected]29699c22012-10-03 23:57:392513#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302514}
[email protected]e60c0232011-11-11 19:56:352515#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302516
[email protected]4a65826d2011-08-25 16:04:012517#if defined(OS_WIN)
2518const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2519 return chrome::kBrowserResourcesDll;
2520}
[email protected]34f48682013-03-20 00:30:182521
2522void ChromeContentBrowserClient::PreSpawnRenderer(
2523 sandbox::TargetPolicy* policy,
2524 bool* success) {
2525 // This code is duplicated in nacl_exe_win_64.cc.
2526 // Allow the server side of a pipe restricted to the "chrome.nacl."
2527 // namespace so that it cannot impersonate other system or other chrome
2528 // service pipes.
2529 sandbox::ResultCode result = policy->AddRule(
2530 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2531 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2532 L"\\\\.\\pipe\\chrome.nacl.*");
2533 if (result != sandbox::SBOX_ALL_OK) {
2534 *success = false;
2535 return;
2536 }
2537
2538 // Renderers need to send named pipe handles and shared memory
2539 // segment handles to NaCl loader processes.
2540 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2541 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2542 L"File");
2543 if (result != sandbox::SBOX_ALL_OK) {
2544 *success = false;
2545 return;
2546 }
2547}
[email protected]4a65826d2011-08-25 16:04:012548#endif
2549
[email protected]37a72af2011-06-13 05:42:012550#if defined(USE_NSS)
2551crypto::CryptoModuleBlockingPasswordDelegate*
2552 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2553 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292554 return chrome::NewCryptoModuleBlockingDialogDelegate(
2555 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012556}
2557#endif
2558
[email protected]d977f9c2011-03-14 16:10:262559} // namespace chrome