blob: 3070791abbf69a9f20f1cfd4ada7ebfa35e13f39 [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]18699372013-06-25 20:42:5520#include "chrome/browser/adview/adview_guest.h"
[email protected]056efdc2013-04-06 00:14:5321#include "chrome/browser/app_mode/app_mode_utils.h"
[email protected]b8148ac2011-07-13 22:03:2522#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3023#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4724#include "chrome/browser/browsing_data/browsing_data_helper.h"
25#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1226#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4127#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4128#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5629#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0530#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4531#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3232#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0833#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3234#include "chrome/browser/download/download_util.h"
[email protected]17263b22013-05-16 03:29:2235#include "chrome/browser/extensions/activity_log/activity_log.h"
[email protected]2b33dcd02012-03-18 01:34:1636#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]1deace22013-05-22 06:14:4637#include "chrome/browser/extensions/browser_permissions_policy_delegate.h"
[email protected]76411f412012-02-22 18:56:0638#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0439#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3340#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2641#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0842#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2543#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0644#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5245#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2346#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1247#include "chrome/browser/google/google_util.h"
[email protected]11158e2d2013-02-01 02:31:5648#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0449#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]01e59752013-06-18 00:17:3550#include "chrome/browser/nacl_host/nacl_host_message_filter.h"
[email protected]0c7193742012-11-07 19:05:0351#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2852#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0453#include "chrome/browser/notifications/desktop_notification_service.h"
54#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4255#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5656#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0657#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4158#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5059#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0760#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4161#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1462#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0363#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1464#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3265#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0666#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1467#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3868#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4369#include "chrome/browser/search/instant_service.h"
70#include "chrome/browser/search/instant_service_factory.h"
71#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1472#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0273#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3374#include "chrome/browser/speech/tts_message_filter.h"
[email protected]8ec71262011-07-28 08:12:4675#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5876#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0377#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5278#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4579#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5480#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4381#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]329ac972013-06-21 15:24:2582#include "chrome/browser/ui/sync/sync_promo_ui.h"
[email protected]b5d73422012-06-02 23:46:4483#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5084#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0685#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1586#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2787#include "chrome/browser/validation_message_message_filter.h"
[email protected]18699372013-06-25 20:42:5588#include "chrome/browser/webview/webview_constants.h"
[email protected]db9f2142013-05-27 22:56:1689#include "chrome/browser/webview/webview_guest.h"
[email protected]b80f68432011-05-02 17:22:3090#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0191#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1492#include "chrome/common/chrome_paths.h"
[email protected]f3b357692013-03-22 05:16:1393#include "chrome/common/chrome_process_type.h"
[email protected]b80f68432011-05-02 17:22:3094#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2995#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0496#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3897#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4498#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4399#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:29100#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]dda54822013-06-15 01:26:39101#include "chrome/common/extensions/permissions/permissions_data.h"
[email protected]157cc902012-11-02 06:31:58102#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:34103#include "chrome/common/logging_chrome.h"
[email protected]9d450492013-06-13 23:08:37104#include "chrome/common/pepper_permission_util.h"
[email protected]763ec4ca2011-04-29 15:48:12105#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38106#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09107#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53108#include "chromeos/chromeos_constants.h"
[email protected]75fee372013-03-06 00:42:44109#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43110#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30111#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38112#include "content/public/browser/browser_ppapi_host.h"
[email protected]30a306f42013-06-10 03:09:03113#include "content/public/browser/browser_thread.h"
[email protected]825b1662012-03-12 19:07:31114#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03115#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59116#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36117#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30118#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33119#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05120#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33121#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19122#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10123#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43124#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18125#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23126#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42127#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39128#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23129#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53130#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58131#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34132#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06133#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57134#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38135#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39136#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08137#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24138#include "ui/message_center/message_center_util.h"
[email protected]b40015c2013-06-26 08:13:31139#include "webkit/browser/fileapi/external_mount_points.h"
[email protected]fab55e72013-05-31 07:06:18140#include "webkit/common/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04141#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26142
[email protected]b48c9182011-10-26 18:03:30143#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38144#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18145#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38146#elif defined(OS_MACOSX)
147#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56148#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30149#elif defined(OS_CHROMEOS)
150#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]b40015c2013-06-26 08:13:31151#include "chrome/browser/chromeos/fileapi/cros_mount_point_provider.h"
[email protected]5c915252013-05-07 13:15:39152#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49153#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]5c915252013-05-07 13:15:39154#include "chrome/browser/chromeos/system/statistics_provider.h"
[email protected]931d1042013-04-05 17:50:44155#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26156#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30157#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09158#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38159#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09160#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39161#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30162#elif defined(OS_POSIX)
163#include "chrome/browser/chrome_browser_main_posix.h"
164#endif
165
[email protected]6653c192012-04-10 22:52:44166#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30167#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12168#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43169#endif
[email protected]b80f68432011-05-02 17:22:30170
[email protected]1e87df32012-09-12 04:53:19171#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
172#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
173#endif
174
[email protected]29699c22012-10-03 23:57:39175#if defined(OS_ANDROID)
176#include "ui/base/ui_base_paths.h"
177#endif
178
[email protected]37a72af2011-06-13 05:42:01179#if defined(USE_NSS)
180#include "chrome/browser/ui/crypto_module_password_dialog.h"
181#endif
182
[email protected]d5bcd06f2013-04-21 08:07:24183#if !defined(OS_CHROMEOS)
184#include "chrome/browser/signin/signin_manager.h"
185#include "chrome/browser/signin/signin_manager_factory.h"
186#endif
187
[email protected]02250952013-04-24 23:52:53188#if !defined(OS_ANDROID)
189#include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h"
190#endif
191
[email protected]6ef98b5a2013-05-31 23:58:31192#if defined(ENABLE_WEBRTC)
193#include "chrome/browser/media/webrtc_logging_handler_host.h"
194#endif
195
[email protected]02a3dc122013-06-13 15:07:53196#if defined(FILE_MANAGER_EXTENSION)
197#include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
198#endif
199
[email protected]c7abd422012-09-25 00:20:08200using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47201using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03202using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39203using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31204using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59205using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08206using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00207using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11208using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33209using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13210using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06211using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34212using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40213using extensions::Manifest;
[email protected]631bb742011-11-02 11:29:39214
[email protected]c5dbef02011-05-13 05:06:09215namespace {
216
[email protected]eabbfb12013-04-05 23:28:35217// Cached version of the locale so we can return the locale on the I/O
218// thread.
219base::LazyInstance<std::string> g_io_thread_application_locale;
220
[email protected]93f72062013-05-29 20:29:40221#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40222const char* kPredefinedAllowedSocketOrigins[] = {
223 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18224 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45225 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
226 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
227 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
228 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35229 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54230 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
231 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
232 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
233 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
234 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
235 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38236 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58237 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29238 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
[email protected]f6599915a2013-06-20 20:03:50239 "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080
[email protected]b71313232013-05-06 06:16:29240 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
241 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
242 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
243 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40244};
[email protected]93f72062013-05-29 20:29:40245#endif
[email protected]e461da2f2012-02-16 19:06:40246
[email protected]f8f93eb2012-09-25 03:06:24247// Returns a copy of the given url with its host set to given host and path set
248// to given path. Other parts of the url will be the same.
249GURL ReplaceURLHostAndPath(const GURL& url,
250 const std::string& host,
251 const std::string& path) {
252 url_canon::Replacements<char> replacements;
253 replacements.SetHost(host.c_str(),
254 url_parse::Component(0, host.length()));
255 replacements.SetPath(path.c_str(),
256 url_parse::Component(0, path.length()));
257 return url.ReplaceComponents(replacements);
258}
259
260// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
261GURL AddUberHost(const GURL& url) {
262 const std::string uber_host = chrome::kChromeUIUberHost;
263 const std::string new_path = url.host() + url.path();
264
265 return ReplaceURLHostAndPath(url, uber_host, new_path);
266}
267
[email protected]045bf7c2012-09-28 20:27:36268// If url->host() is "chrome" and url->path() has characters other than the
269// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
270// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24271bool RemoveUberHost(GURL* url) {
272 if (url->host() != chrome::kChromeUIUberHost)
273 return false;
274
[email protected]045bf7c2012-09-28 20:27:36275 if (url->path().empty() || url->path() == "/")
276 return false;
277
[email protected]f8f93eb2012-09-25 03:06:24278 const std::string old_path = url->path();
279
280 const std::string::size_type separator = old_path.find('/', 1);
281 std::string new_host;
282 std::string new_path;
283 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36284 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24285 } else {
286 new_host = old_path.substr(1, separator - 1);
287 new_path = old_path.substr(separator);
288 }
289
[email protected]44e8add2013-06-13 17:29:15290 // Do not allow URLs with paths empty before the first slash since we can't
291 // have an empty host. (e.g "foo://chrome//")
292 if (new_host.empty())
293 return false;
294
[email protected]f8f93eb2012-09-25 03:06:24295 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
296
[email protected]44e8add2013-06-13 17:29:15297 DCHECK(url->is_valid());
298
[email protected]f8f93eb2012-09-25 03:06:24299 return true;
300}
301
[email protected]b8148ac2011-07-13 22:03:25302// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42303bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24304 // Do not handle special URLs such as "about:foo"
305 if (!url->host().empty()) {
306 const GURL chrome_url = AddUberHost(*url);
307
308 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
309 // be called.
310 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
311 browser_context, chrome_url))
312 return true;
313 }
314
[email protected]863f70a2012-01-27 02:05:50315 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
316 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25317 return false;
318
[email protected]fe69558d2012-03-12 11:34:49319#if defined(OS_CHROMEOS)
320 // Special case : in ChromeOS in Guest mode bookmarks and history are
321 // disabled for security reasons. New tab page explains the reasons, so
322 // we redirect user to new tab page.
323 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
324 if (url->SchemeIs(chrome::kChromeUIScheme) &&
325 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
326 url->DomainIs(chrome::kChromeUIHistoryHost))) {
327 // Rewrite with new tab URL
328 *url = GURL(chrome::kChromeUINewTabURL);
329 }
330 }
331#endif
332
[email protected]b8148ac2011-07-13 22:03:25333 // Special case the new tab page. In older versions of Chrome, the new tab
334 // page was hosted at chrome-internal:<blah>. This might be in people's saved
335 // sessions or bookmarks, so we say any URL with that scheme triggers the new
336 // tab page.
337 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
338 // Rewrite it with the proper new tab URL.
339 *url = GURL(chrome::kChromeUINewTabURL);
340 }
341
342 return true;
343}
344
[email protected]f8f93eb2012-09-25 03:06:24345// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
346// "chrome://foo/".
347bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
348 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
349 return false;
350
351 return RemoveUberHost(url);
352}
353
[email protected]8d3132f62011-10-12 07:13:42354// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
355// below. Extension, and isolated apps require different privileges to be
356// granted to their RenderProcessHosts. This classification allows us to make
357// sure URLs are served by hosts with the right set of privileges.
358enum RenderProcessHostPrivilege {
359 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45360 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42361 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45362 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42363};
364
365RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
366 const GURL& url,
367 ExtensionService* service) {
368 // Default to a normal renderer cause it is lower privileged. This should only
369 // occur if the URL on a site instance is either malformed, or uninitialized.
370 // If it is malformed, then there is no need for better privileges anyways.
371 // If it is uninitialized, but eventually settles on being an a scheme other
372 // than normal webrenderer, the navigation logic will correct us out of band
373 // anyways.
374 if (!url.is_valid())
375 return PRIV_NORMAL;
376
[email protected]885c0e92012-11-13 20:27:42377 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44378 const Extension* extension =
379 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43380 if (extension &&
381 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42382 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45383 if (extension && extension->is_hosted_app())
384 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42385
386 return PRIV_EXTENSION;
387 }
388
389 return PRIV_NORMAL;
390}
391
392RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30393 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46394 extensions::ProcessMap* process_map,
395 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46396 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30397 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46398 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21399 return PRIV_NORMAL;
400
[email protected]6f371442011-11-09 06:45:46401 for (std::set<std::string>::iterator iter = extension_ids.begin();
402 iter != extension_ids.end(); ++iter) {
403 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43404 if (extension &&
405 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42406 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45407 if (extension && extension->is_hosted_app())
408 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42409 }
410
[email protected]676f6ab2011-10-19 20:23:21411 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42412}
413
[email protected]6786bf402011-12-03 15:19:45414bool CertMatchesFilter(const net::X509Certificate& cert,
415 const base::DictionaryValue& filter) {
416 // TODO(markusheintz): This is the minimal required filter implementation.
417 // Implement a better matcher.
418
419 // An empty filter matches any client certificate since no requirements are
420 // specified at all.
421 if (filter.empty())
422 return true;
423
424 std::string common_name;
425 if (filter.GetString("ISSUER.CN", &common_name) &&
426 (cert.issuer().common_name == common_name)) {
427 return true;
428 }
429 return false;
430}
431
[email protected]f3986f82012-01-03 20:00:06432// Fills |map| with the per-script font prefs under path |map_name|.
433void FillFontFamilyMap(const PrefService* prefs,
434 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53435 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06436 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
437 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
438 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
439 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23440 if (!font_family.empty())
441 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06442 }
443}
444
[email protected]a1733df2012-06-22 11:24:18445#if defined(OS_POSIX) && !defined(OS_MACOSX)
446int GetCrashSignalFD(const CommandLine& command_line) {
447 if (command_line.HasSwitch(switches::kExtensionProcess)) {
448 ExtensionCrashHandlerHostLinux* crash_handler =
449 ExtensionCrashHandlerHostLinux::GetInstance();
450 return crash_handler->GetDeathSignalSocket();
451 }
452
453 std::string process_type =
454 command_line.GetSwitchValueASCII(switches::kProcessType);
455
456 if (process_type == switches::kRendererProcess)
457 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
458
459 if (process_type == switches::kPluginProcess)
460 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
461
462 if (process_type == switches::kPpapiPluginProcess)
463 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
464
465 if (process_type == switches::kGpuProcess)
466 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
467
468 return -1;
469}
470#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
471
[email protected]d5bcd06f2013-04-21 08:07:24472#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30473GURL GetEffectiveURLForSignin(const GURL& url) {
474 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
475
476 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03477 // Copy the path because the argument to SetPathStr must outlive
478 // the Replacements object.
479 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30480 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03481 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30482 effective_url = effective_url.ReplaceComponents(replacements);
483 return effective_url;
484}
[email protected]d5bcd06f2013-04-21 08:07:24485#endif
[email protected]970c63e2013-03-07 00:25:30486
[email protected]eabbfb12013-04-05 23:28:35487void SetApplicationLocaleOnIOThread(const std::string& locale) {
488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
489 g_io_thread_application_locale.Get() = locale;
490}
491
[email protected]9dbfff12011-07-01 19:37:07492} // namespace
[email protected]c5dbef02011-05-13 05:06:09493
[email protected]d977f9c2011-03-14 16:10:26494namespace chrome {
495
[email protected]e461da2f2012-02-16 19:06:40496ChromeContentBrowserClient::ChromeContentBrowserClient() {
[email protected]93f72062013-05-29 20:29:40497#if defined(ENABLE_PLUGINS)
[email protected]e461da2f2012-02-16 19:06:40498 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
499 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]93f72062013-05-29 20:29:40500#endif
[email protected]1deace22013-05-22 06:14:46501
502 permissions_policy_delegate_.reset(
503 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40504}
505
506ChromeContentBrowserClient::~ChromeContentBrowserClient() {
507}
508
[email protected]bca18382012-06-25 19:15:23509// static
[email protected]c753f142013-02-10 13:14:04510void ChromeContentBrowserClient::RegisterUserPrefs(
[email protected]443e9312013-05-06 06:17:34511 user_prefs::PrefRegistrySyncable* registry) {
512 registry->RegisterBooleanPref(
513 prefs::kDisable3DAPIs,
514 false,
515 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
516 registry->RegisterBooleanPref(
517 prefs::kEnableHyperlinkAuditing,
518 true,
519 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
520 registry->RegisterBooleanPref(
521 prefs::kEnableMemoryInfo,
522 false,
523 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23524}
525
[email protected]eabbfb12013-04-05 23:28:35526// static
527void ChromeContentBrowserClient::SetApplicationLocale(
528 const std::string& locale) {
529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
530
531 // This object is guaranteed to outlive all threads so we don't have to
532 // worry about the lack of refcounting and can just post as Unretained.
533 //
534 // The common case is that this function is called early in Chrome startup
535 // before any threads are created (it will also be called later if the user
536 // changes the pref). In this case, there will be no threads created and
537 // posting will fail. When there are no threads, we can just set the string
538 // without worrying about threadsafety.
539 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
540 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
541 g_io_thread_application_locale.Get() = locale;
542 }
543}
544
[email protected]50462bf02011-11-21 19:13:31545content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
546 const content::MainFunctionParams& parameters) {
547 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30548 // Construct the Main browser parts based on the OS type.
549#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31550 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04551#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31552 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30553#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22554 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26555#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31556 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14557#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09558 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30559#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31560 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04561#else
[email protected]b48c9182011-10-26 18:03:30562 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31563 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30564#endif
565
[email protected]7e75e4a2013-05-17 17:20:03566 chrome::AddProfilesExtraParts(main_parts);
567
[email protected]c7480942011-11-08 19:18:27568 // Construct additional browser parts. Stages are called in the order in
569 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22570#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41571 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04572#endif
[email protected]c7480942011-11-08 19:18:27573
574#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41575 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27576#endif
577
[email protected]dc04be7c2012-03-15 23:57:49578#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41579 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49580#endif
581
[email protected]e050ef142012-03-21 01:04:24582#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41583 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24584#endif
585
[email protected]95132f52013-04-12 02:19:04586 chrome::AddMetricsExtraParts(main_parts);
587
[email protected]50462bf02011-11-21 19:13:31588 return main_parts;
[email protected]f967b722011-09-07 00:58:04589}
590
[email protected]e94bbcb2012-09-07 05:33:57591std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19592 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57593 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53594 std::string partition_id;
595
596 // The partition ID for webview guest processes is the string value of its
597 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
598 if (site.SchemeIs(chrome::kGuestScheme))
599 partition_id = site.spec();
600
[email protected]056efdc2013-04-06 00:14:53601 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53602 return partition_id;
603}
604
605bool ChromeContentBrowserClient::IsValidStoragePartitionId(
606 content::BrowserContext* browser_context,
607 const std::string& partition_id) {
608 // The default ID is empty and is always valid.
609 if (partition_id.empty())
610 return true;
611
612 return GURL(partition_id).is_valid();
613}
614
615void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
616 content::BrowserContext* browser_context,
617 const GURL& site,
[email protected]14acc642012-11-17 12:20:10618 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53619 std::string* partition_domain,
620 std::string* partition_name,
621 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10622 // Default to the browser-wide storage partition and override based on |site|
623 // below.
624 partition_domain->clear();
625 partition_name->clear();
626 *in_memory = false;
627
[email protected]1bc28312012-11-08 08:31:53628 // For the webview tag, we create special guest processes, which host the
629 // tag content separately from the main application that embeds the tag.
630 // A webview tag can specify both the partition name and whether the storage
631 // for that partition should be persisted. Each tag gets a SiteInstance with
632 // a specially formatted URL, based on the application it is hosted by and
633 // the partition requested by it. The format for that URL is:
634 // chrome-guest://partition_domain/persist?partition_name
635 if (site.SchemeIs(chrome::kGuestScheme)) {
636 // Since guest URLs are only used for packaged apps, there must be an app
637 // id in the URL.
638 CHECK(site.has_host());
639 *partition_domain = site.host();
640 // Since persistence is optional, the path must either be empty or the
641 // literal string.
642 *in_memory = (site.path() != "/persist");
643 // The partition name is user supplied value, which we have encoded when the
644 // URL was created, so it needs to be decoded.
645 *partition_name = net::UnescapeURLComponent(site.query(),
646 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10647 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
648 // If |can_be_default| is false, the caller is stating that the |site|
649 // should be parsed as if it had isolated storage. In particular it is
650 // important to NOT check ExtensionService for the is_storage_isolated()
651 // attribute because this code path is run during Extension uninstall
652 // to do cleanup after the Extension has already been unloaded from the
653 // ExtensionService.
654 bool is_isolated = !can_be_default;
655 if (can_be_default) {
656 const Extension* extension = NULL;
657 Profile* profile = Profile::FromBrowserContext(browser_context);
658 ExtensionService* extension_service =
659 extensions::ExtensionSystem::Get(profile)->extension_service();
660 if (extension_service) {
661 extension = extension_service->extensions()->
662 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43663 if (extension &&
664 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10665 is_isolated = true;
666 }
667 }
668 }
[email protected]1bc28312012-11-08 08:31:53669
[email protected]14acc642012-11-17 12:20:10670 if (is_isolated) {
671 CHECK(site.has_host());
672 // For extensions with isolated storage, the the host of the |site| is
673 // the |partition_domain|. The |in_memory| and |partition_name| are only
674 // used in guest schemes so they are cleared here.
675 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53676 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10677 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53678 }
[email protected]d1198fd2012-08-13 22:50:19679 }
680
[email protected]14acc642012-11-17 12:20:10681 // Assert that if |can_be_default| is false, the code above must have found a
682 // non-default partition. If this fails, the caller has a serious logic
683 // error about which StoragePartition they expect to be in and it is not
684 // safe to continue.
685 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44686}
687
[email protected]38b098f2012-03-14 21:11:57688content::WebContentsViewDelegate*
689 ChromeContentBrowserClient::GetWebContentsViewDelegate(
690 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27691 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32692}
693
[email protected]24665682013-02-25 20:59:38694// Check if the extension activity log is enabled for the profile.
695static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
[email protected]770d6a82013-06-09 13:08:33696 // crbug.com/247908 - This should be IsLogEnabled except for an issue
697 // in chrome_frame_net_tests
698 return extensions::ActivityLog::IsLogEnabledOnAnyProfile();
[email protected]24665682013-02-25 20:59:38699}
700
[email protected]44295a12013-06-05 08:45:46701void ChromeContentBrowserClient::GuestWebContentsAttached(
702 WebContents* guest_web_contents,
703 WebContents* embedder_web_contents,
[email protected]5715566a2013-06-25 00:04:53704 int browser_plugin_instance_id,
705 const base::DictionaryValue& extra_params) {
[email protected]44703cc72013-01-24 04:56:06706 Profile* profile = Profile::FromBrowserContext(
707 embedder_web_contents->GetBrowserContext());
708 ExtensionService* service =
709 extensions::ExtensionSystem::Get(profile)->extension_service();
710 if (!service)
711 return;
712 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
713 const Extension* extension = service->extensions()->
714 GetExtensionOrAppByURL(ExtensionURLInfo(url));
715 if (!extension)
716 return;
[email protected]18699372013-06-25 20:42:55717
718 std::string api_type;
719 extra_params.GetString(webview::kAttributeApi, &api_type);
720
721 // WebViewGuest and AdViewGuest's lifetimes iare tied to their associated
722 // guest WebContents' lifetime. When the guest WebContents is destroyed, so is
723 // the attached WebViewGuest or AdViewGuest.
724 if (api_type == "adview") {
725 new AdViewGuest(guest_web_contents,
726 embedder_web_contents,
727 extension->id(),
728 browser_plugin_instance_id,
729 extra_params);
730 } else if (api_type == "webview") {
731 new WebViewGuest(guest_web_contents,
732 embedder_web_contents,
733 extension->id(),
734 browser_plugin_instance_id,
735 extra_params);
736 } else {
737 NOTREACHED();
738 }
[email protected]44703cc72013-01-24 04:56:06739}
740
[email protected]f3b1a082011-11-18 00:34:30741void ChromeContentBrowserClient::RenderProcessHostCreated(
742 content::RenderProcessHost* host) {
743 int id = host->GetID();
744 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41745 net::URLRequestContextGetter* context =
746 profile->GetRequestContextForRenderProcess(id);
747
[email protected]f3b1a082011-11-18 00:34:30748 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41749 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55750#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30751 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55752#endif
[email protected]658677f2012-06-09 06:04:02753#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08754 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03755#endif
[email protected]f3b1a082011-11-18 00:34:30756 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02757 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30758 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56759#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21760 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56761#endif
[email protected]43535512013-02-20 20:41:41762 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
763 id, profile, context));
[email protected]2736c032012-05-11 18:06:07764 host->GetChannel()->AddFilter(
765 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27766 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33767 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]6ef98b5a2013-05-31 23:58:31768#if defined(ENABLE_WEBRTC)
769 host->GetChannel()->AddFilter(new WebRtcLoggingHandlerHost());
770#endif
[email protected]01e59752013-06-18 00:17:35771#if !defined(DISABLE_NACL)
[email protected]14230ca2013-06-26 23:33:03772 ExtensionInfoMap* extension_info_map =
773 extensions::ExtensionSystem::Get(profile)->info_map();
774 host->GetChannel()->AddFilter(new NaClHostMessageFilter(
775 id, profile->IsOffTheRecord(),
776 profile->GetPath(), extension_info_map,
777 context));
[email protected]01e59752013-06-18 00:17:35778#endif
[email protected]3e69bc82011-05-26 23:22:38779
[email protected]2ccf45c2011-08-19 23:35:50780 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
781 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07782
[email protected]24665682013-02-25 20:59:38783 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
784 IsExtensionActivityLogEnabledForProfile(profile)));
785
[email protected]39a5b532011-10-22 01:47:07786 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56787
788 RendererContentSettingRules rules;
789 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
790 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14791}
792
[email protected]95c95552013-05-03 04:21:22793GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
794 content::BrowserContext* browser_context,
795 const GURL& url,
796 bool is_renderer_initiated,
797 content::SiteInstance* current_instance) {
798 Profile* profile = Profile::FromBrowserContext(browser_context);
799 if (!profile)
800 return url;
801
802 // Only return the privileged instant URL if we are entering from a browser-
803 // initiated navigation or if we are already in the instant process.
804 bool is_instant_process = false;
805 int process_id = current_instance->GetProcess()->GetID();
806 InstantService* instant_service =
807 InstantServiceFactory::GetForProfile(profile);
808 if (instant_service)
809 is_instant_process = instant_service->IsInstantProcess(process_id);
810
811 DCHECK_EQ(is_instant_process,
812 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
813 if (!is_renderer_initiated || is_instant_process) {
814 // If the input |url| should be assigned to the Instant renderer, make its
815 // privileged URL distinct from other URLs on the search provider's domain.
816 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
817 return chrome::GetPrivilegedURLForInstant(url, profile);
818 }
819
820 return url;
821}
822
[email protected]3d7474ff2011-07-27 17:47:37823GURL ChromeContentBrowserClient::GetEffectiveURL(
824 content::BrowserContext* browser_context, const GURL& url) {
825 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52826 if (!profile)
827 return url;
828
[email protected]d5bcd06f2013-04-21 08:07:24829#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30830 // If the input |url| should be assigned to the Signin renderer, make its
831 // effective URL distinct from other URLs on the signin service's domain.
832 // Note that the signin renderer will be allowed to sign the user in to
833 // Chrome.
834 if (SigninManager::IsWebBasedSigninFlowURL(url))
835 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24836#endif
[email protected]970c63e2013-03-07 00:25:30837
[email protected]c5dec6292013-01-25 04:54:52838 // If the input |url| is part of an installed app, the effective URL is an
839 // extension URL with the ID of that extension as the host. This has the
840 // effect of grouping apps together in a common SiteInstance.
841 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13842 extensions::ExtensionSystem::Get(profile)->extension_service();
843 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08844 return url;
845
[email protected]06bdd2b2012-11-30 18:47:13846 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44847 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08848 if (!extension)
849 return url;
850
[email protected]15877ca2011-11-18 22:40:52851 // Bookmark apps do not use the hosted app process model, and should be
852 // treated as normal URLs.
853 if (extension->from_bookmark())
854 return url;
855
[email protected]36fb2c7c2011-04-04 15:49:08856 // If the URL is part of an extension's web extent, convert it to an
857 // extension URL.
858 return extension->GetResourceURL(url.path());
859}
860
[email protected]056ad2a2011-07-12 02:13:55861bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37862 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52863 // Non-extension, non-Instant URLs should generally use
864 // process-per-site-instance. Because we expect to use the effective URL,
865 // URLs for hosted apps (apart from bookmark apps) should have an extension
866 // scheme by now.
867
868 Profile* profile = Profile::FromBrowserContext(browser_context);
869 if (!profile)
870 return false;
871
[email protected]165fe422013-03-27 06:34:03872 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52873 return true;
874
[email protected]d5bcd06f2013-04-21 08:07:24875#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30876 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
877 return true;
[email protected]d5bcd06f2013-04-21 08:07:24878#endif
[email protected]970c63e2013-03-07 00:25:30879
[email protected]885c0e92012-11-13 20:27:42880 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55881 return false;
882
[email protected]c5dec6292013-01-25 04:54:52883 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13884 extensions::ExtensionSystem::Get(profile)->extension_service();
885 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55886 return false;
887
[email protected]06bdd2b2012-11-30 18:47:13888 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44889 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55890 if (!extension)
891 return false;
892
893 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53894 // permission, or that does not allow JavaScript access to the background
895 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55896 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40897 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06898 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29899 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53900 return false;
901 }
902 }
[email protected]056ad2a2011-07-12 02:13:55903
[email protected]7b54ca02012-03-02 18:06:53904 // Hosted apps that have script access to their background page must use
905 // process per site, since all instances can make synchronous calls to the
906 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55907 return true;
908}
909
[email protected]672c8c12013-03-07 12:30:06910// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41911void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
912 std::vector<std::string>* additional_schemes) {
913 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06914}
915
[email protected]6bd30072013-02-08 18:17:11916net::URLRequestContextGetter*
917ChromeContentBrowserClient::CreateRequestContext(
918 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06919 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11920 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06921 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11922}
923
924net::URLRequestContextGetter*
925ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
926 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40927 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11928 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06929 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11930 Profile* profile = Profile::FromBrowserContext(browser_context);
931 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06932 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11933}
934
[email protected]46fb9442011-12-09 17:57:47935bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
936 return ProfileIOData::IsHandledURL(url);
937}
938
[email protected]c4365fa42013-05-14 01:08:24939bool ChromeContentBrowserClient::CanCommitURL(
940 content::RenderProcessHost* process_host,
941 const GURL& url) {
942 // We need to let most extension URLs commit in any process, since this can
943 // be allowed due to web_accessible_resources. Most hosted app URLs may also
944 // load in any process (e.g., in an iframe). However, the Chrome Web Store
945 // cannot be loaded in iframes and should never be requested outside its
946 // process.
947 Profile* profile =
948 Profile::FromBrowserContext(process_host->GetBrowserContext());
949 ExtensionService* service =
950 extensions::ExtensionSystem::Get(profile)->extension_service();
951 if (!service)
952 return true;
953 const Extension* new_extension =
954 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
955 if (new_extension &&
956 new_extension->is_hosted_app() &&
957 new_extension->id() == extension_misc::kWebStoreAppId &&
958 !service->process_map()->Contains(new_extension->id(),
959 process_host->GetID())) {
960 return false;
961 }
962
963 return true;
964}
965
[email protected]2a5221b2011-09-27 23:07:31966bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30967 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31968 const GURL& site_url) {
969 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30970 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52971 // This may be NULL during tests. In that case, just assume any site can
972 // share any host.
973 if (!profile)
974 return true;
975
[email protected]d43f99fe2013-04-03 00:20:14976 // Instant URLs should only be in the instant process and instant process
977 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52978 InstantService* instant_service =
979 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14980 if (instant_service) {
981 bool is_instant_process = instant_service->IsInstantProcess(
982 process_host->GetID());
983 bool should_be_in_instant_process =
984 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
985 if (is_instant_process || should_be_in_instant_process)
986 return is_instant_process && should_be_in_instant_process;
987 }
[email protected]c5dec6292013-01-25 04:54:52988
[email protected]d5bcd06f2013-04-21 08:07:24989#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30990 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
991 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
992 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:24993#endif
[email protected]970c63e2013-03-07 00:25:30994
[email protected]06bdd2b2012-11-30 18:47:13995 ExtensionService* service =
996 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46997 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31998
[email protected]ffa97602011-11-17 17:55:52999 // Don't allow the Task Manager to share a process with anything else.
1000 // Otherwise it can affect the renderers it is observing.
1001 // Note: we could create another RenderProcessHostPrivilege bucket for
1002 // this to allow multiple chrome://tasks instances to share, but that's
1003 // a very unlikely case without serious consequences.
1004 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
1005 return false;
1006
[email protected]8d3132f62011-10-12 07:13:421007 // These may be NULL during tests. In that case, just assume any site can
1008 // share any host.
[email protected]6f371442011-11-09 06:45:461009 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:311010 return true;
1011
[email protected]eec0b33c2011-12-05 22:09:451012 // Otherwise, just make sure the process privilege matches the privilege
1013 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:571014 RenderProcessHostPrivilege privilege_required =
1015 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:451016 return GetProcessPrivilege(process_host, process_map, service) ==
1017 privilege_required;
[email protected]2a5221b2011-09-27 23:07:311018}
1019
[email protected]76411f412012-02-22 18:56:061020// This function is trying to limit the amount of processes used by extensions
1021// with background pages. It uses a globally set percentage of processes to
1022// run such extensions and if the limit is exceeded, it returns true, to
1023// indicate to the content module to group extensions together.
1024bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
1025 content::BrowserContext* browser_context, const GURL& url) {
1026 // It has to be a valid URL for us to check for an extension.
1027 if (!url.is_valid())
1028 return false;
1029
1030 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:191031 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131032 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:061033 if (!service)
1034 return false;
1035
1036 // We have to have a valid extension with background page to proceed.
1037 const Extension* extension =
1038 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
1039 if (!extension)
1040 return false;
[email protected]9367eabc2013-03-01 01:29:291041 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:061042 return false;
1043
1044 std::set<int> process_ids;
1045 size_t max_process_count =
1046 content::RenderProcessHost::GetMaxRendererProcessCount();
1047
1048 // Go through all profiles to ensure we have total count of extension
1049 // processes containing background pages, otherwise one profile can
1050 // starve the other.
1051 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1052 GetLoadedProfiles();
1053 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031054 ExtensionProcessManager* epm =
1055 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321056 for (ExtensionProcessManager::const_iterator iter =
1057 epm->background_hosts().begin();
1058 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131059 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321060 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061061 }
1062 }
1063
1064 if (process_ids.size() >
1065 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1066 return true;
1067 }
1068
1069 return false;
1070}
1071
[email protected]6f371442011-11-09 06:45:461072void ChromeContentBrowserClient::SiteInstanceGotProcess(
1073 SiteInstance* site_instance) {
1074 CHECK(site_instance->HasProcess());
1075
1076 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021077 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521078 if (!profile)
1079 return;
1080
1081 // Remember the ID of the Instant process to signal the renderer process
1082 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031083 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321084 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521085 InstantService* instant_service =
1086 InstantServiceFactory::GetForProfile(profile);
1087 if (instant_service)
1088 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1089 }
1090
[email protected]d5bcd06f2013-04-21 08:07:241091#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301092 // We only expect there to be one signin process as we use process-per-site
1093 // for signin URLs. The signin process will be cleared from SigninManager
1094 // when the renderer is destroyed.
1095 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1096 SigninManager* signin_manager =
1097 SigninManagerFactory::GetForProfile(profile);
1098 if (signin_manager)
1099 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461100 BrowserThread::PostTask(
1101 BrowserThread::IO, FROM_HERE,
1102 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1103 extensions::ExtensionSystem::Get(profile)->info_map(),
1104 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301105 }
[email protected]d5bcd06f2013-04-21 08:07:241106#endif
[email protected]970c63e2013-03-07 00:25:301107
[email protected]06bdd2b2012-11-30 18:47:131108 ExtensionService* service =
1109 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461110 if (!service)
1111 return;
1112
1113 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441114 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591115 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461116 if (!extension)
1117 return;
1118
[email protected]6bc04fd82011-12-04 02:29:351119 service->process_map()->Insert(extension->id(),
1120 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331121 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461122 BrowserThread::PostTask(
1123 BrowserThread::IO, FROM_HERE,
1124 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591125 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461126 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351127 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331128 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461129}
1130
1131void ChromeContentBrowserClient::SiteInstanceDeleting(
1132 SiteInstance* site_instance) {
1133 if (!site_instance->HasProcess())
1134 return;
1135
1136 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021137 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131138 ExtensionService* service =
1139 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461140 if (!service)
1141 return;
1142
1143 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441144 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591145 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461146 if (!extension)
1147 return;
1148
[email protected]6bc04fd82011-12-04 02:29:351149 service->process_map()->Remove(extension->id(),
1150 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331151 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461152 BrowserThread::PostTask(
1153 BrowserThread::IO, FROM_HERE,
1154 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591155 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461156 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351157 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331158 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461159}
1160
[email protected]f05763972012-06-06 18:17:261161bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141162 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081163 const GURL& current_url,
1164 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261165 if (current_url.is_empty()) {
1166 // Always choose a new process when navigating to extension URLs. The
1167 // process grouping logic will combine all of a given extension's pages
1168 // into the same process.
[email protected]885c0e92012-11-13 20:27:421169 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261170 return true;
[email protected]e3daf3c2011-10-05 21:17:081171
[email protected]f05763972012-06-06 18:17:261172 return false;
1173 }
1174
1175 // Also, we must switch if one is an extension and the other is not the exact
1176 // same extension.
[email protected]885c0e92012-11-13 20:27:421177 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1178 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261179 if (current_url.GetOrigin() != new_url.GetOrigin())
1180 return true;
1181 }
1182
[email protected]e9841fbd2013-02-22 23:12:141183 // The checks below only matter if we can retrieve which extensions are
1184 // installed.
1185 Profile* profile =
1186 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1187 ExtensionService* service =
1188 extensions::ExtensionSystem::Get(profile)->extension_service();
1189 if (!service)
1190 return false;
1191
1192 // We must swap if the URL is for an extension and we are not using an
1193 // extension process.
1194 const Extension* new_extension =
1195 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1196 // Ignore all hosted apps except the Chrome Web Store, since they do not
1197 // require their own BrowsingInstance (e.g., postMessage is ok).
1198 if (new_extension &&
1199 new_extension->is_hosted_app() &&
1200 new_extension->id() != extension_misc::kWebStoreAppId)
1201 new_extension = NULL;
1202 if (new_extension &&
1203 site_instance->HasProcess() &&
1204 !service->process_map()->Contains(new_extension->id(),
1205 site_instance->GetProcess()->GetID()))
1206 return true;
1207
[email protected]f05763972012-06-06 18:17:261208 return false;
[email protected]e3daf3c2011-10-05 21:17:081209}
1210
[email protected]395045c2012-05-22 15:04:381211bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1212 content::ResourceContext* resource_context, const GURL& current_url,
1213 const GURL& new_url) {
1214 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1215 return extensions::CrossesExtensionProcessBoundary(
1216 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171217 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381218}
1219
[email protected]763ec4ca2011-04-29 15:48:121220std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1221 const std::string& alias_name) {
1222 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1223}
1224
[email protected]b80f68432011-05-02 17:22:301225void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1226 CommandLine* command_line, int child_process_id) {
1227#if defined(USE_LINUX_BREAKPAD)
1228 if (IsCrashReporterEnabled()) {
1229 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1230 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1231 }
1232#elif defined(OS_MACOSX)
1233 if (IsCrashReporterEnabled()) {
1234 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1235 child_process_logging::GetClientId());
1236 }
1237#endif // OS_MACOSX
1238
[email protected]f1933792011-06-14 00:49:341239 if (logging::DialogsAreSuppressed())
1240 command_line->AppendSwitch(switches::kNoErrorDialogs);
1241
[email protected]b80f68432011-05-02 17:22:301242 std::string process_type =
1243 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171244 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321245
1246 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1247 command_line->AppendSwitch(switches::kChromeFrame);
1248
[email protected]718eab62011-10-05 21:16:521249 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451250 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301251 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1252 if (!user_data_dir.empty())
1253 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1254#if defined(OS_CHROMEOS)
1255 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441256 browser_command_line.GetSwitchValueASCII(
1257 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301258 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441259 command_line->AppendSwitchASCII(
1260 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301261#endif
1262
[email protected]f3b1a082011-11-18 00:34:301263 content::RenderProcessHost* process =
1264 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371265 if (process) {
1266 Profile* profile = Profile::FromBrowserContext(
1267 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131268 ExtensionService* extension_service =
1269 extensions::ExtensionSystem::Get(profile)->extension_service();
1270 if (extension_service) {
1271 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001272 if (process_map && process_map->Contains(process->GetID()))
1273 command_line->AppendSwitch(switches::kExtensionProcess);
1274 }
[email protected]b80f68432011-05-02 17:22:301275
[email protected]a8d851f82011-12-21 00:32:371276 PrefService* prefs = profile->GetPrefs();
1277 // Currently this pref is only registered if applied via a policy.
1278 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1279 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1280 // Turn this policy into a command line switch.
1281 command_line->AppendSwitch(switches::kDisable3DAPIs);
1282 }
[email protected]718eab62011-10-05 21:16:521283
[email protected]a8d851f82011-12-21 00:32:371284 // Disable client-side phishing detection in the renderer if it is
1285 // disabled in the Profile preferences or the browser process.
1286 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1287 !g_browser_process->safe_browsing_detection_service()) {
1288 command_line->AppendSwitch(
1289 switches::kDisableClientSidePhishingDetection);
1290 }
[email protected]0045b0f42012-07-26 11:52:081291
1292 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211293 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521294
1295 InstantService* instant_service =
1296 InstantServiceFactory::GetForProfile(profile);
1297 if (instant_service &&
1298 instant_service->IsInstantProcess(process->GetID()))
1299 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301300
[email protected]d5bcd06f2013-04-21 08:07:241301#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301302 SigninManager* signin_manager =
1303 SigninManagerFactory::GetForProfile(profile);
1304 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1305 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241306#endif
[email protected]47c7ec82012-01-18 03:29:211307 }
[email protected]4287a3d2011-06-13 23:56:511308
[email protected]87552982012-11-02 17:21:401309 if (content::IsThreadedCompositingEnabled())
1310 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1311
[email protected]16dc42452013-04-09 04:37:191312 if (message_center::IsRichNotificationEnabled())
1313 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191314
[email protected]47c7ec82012-01-18 03:29:211315 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511316 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171317 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481318 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171319 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511320 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481321 switches::kAllowLegacyExtensionManifests,
[email protected]9d450492013-06-13 23:08:371322 // TODO(victorhsieh): remove the following flag once we move PPAPI FileIO
1323 // to browser.
1324 switches::kAllowNaClFileHandleAPI,
[email protected]4287a3d2011-06-13 23:56:511325 switches::kAllowScriptingGallery,
1326 switches::kAppsCheckoutURL,
1327 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311328 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511329 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501330 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531331 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111332 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531333 switches::kEnableAdview,
1334 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211335 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511336 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511337 switches::kEnableIPCFuzzing,
1338 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451339 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481340 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051341 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511342 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291343 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511344 switches::kMemoryProfiling,
1345 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371346 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371347 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511348 switches::kPpapiFlashArgs,
1349 switches::kPpapiFlashInProcess,
1350 switches::kPpapiFlashPath,
1351 switches::kPpapiFlashVersion,
1352 switches::kProfilingAtStart,
1353 switches::kProfilingFile,
1354 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371355 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511356 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291357 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381358 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511359 };
1360
1361 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1362 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171363 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381364 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351365 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381366 switches::kEnableExperimentalExtensionApis,
1367 switches::kWhitelistedExtensionID,
1368 };
1369
1370 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1371 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511372 } else if (process_type == switches::kPluginProcess) {
1373 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441374#if defined(OS_CHROMEOS)
1375 chromeos::switches::kLoginProfile,
1376#endif
[email protected]4287a3d2011-06-13 23:56:511377 switches::kMemoryProfiling,
1378 switches::kSilentDumpOnDCHECK,
1379 switches::kUserDataDir,
1380 };
1381
1382 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1383 arraysize(kSwitchNames));
1384 } else if (process_type == switches::kZygoteProcess) {
1385 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511386 switches::kUserDataDir, // Make logs go to the right file.
1387 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501388 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511389 switches::kPpapiFlashInProcess,
1390 switches::kPpapiFlashPath,
1391 switches::kPpapiFlashVersion,
1392 };
1393
1394 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1395 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111396 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001397 base::FilePath user_data_dir =
1398 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1399 if (!user_data_dir.empty())
1400 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111401 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1402 // because GPU is expected to be unreliable.
1403 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1404 !command_line->HasSwitch(switches::kDisableBreakpad))
1405 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301406 }
[email protected]6f08af82011-09-15 01:19:031407
1408 // The command line switch kEnableBenchmarking needs to be specified along
1409 // with the kEnableStatsTable switch to ensure that the stats table global
1410 // is initialized correctly.
1411 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1412 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301413}
1414
1415std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431416 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351417 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301418 return g_browser_process->GetApplicationLocale();
1419}
1420
[email protected]597a867b2011-11-18 18:31:201421std::string ChromeContentBrowserClient::GetAcceptLangs(
1422 content::BrowserContext* context) {
1423 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371424 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081425}
1426
[email protected]9ec0f452012-05-31 15:58:531427gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221428 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531429 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081430}
1431
[email protected]a2176792011-05-08 19:30:491432bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091433 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191434 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201435 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201437 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051438 return io_data->GetCookieSettings()->
1439 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491440}
1441
[email protected]ed24fad2011-05-10 22:44:011442bool ChromeContentBrowserClient::AllowGetCookie(
1443 const GURL& url,
1444 const GURL& first_party,
1445 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201446 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011447 int render_process_id,
1448 int render_view_id) {
1449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201450 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051451 bool allow = io_data->GetCookieSettings()->
1452 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011453
[email protected]8093a542011-05-13 07:29:321454 BrowserThread::PostTask(
1455 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031456 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431457 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011458 return allow;
1459}
1460
1461bool ChromeContentBrowserClient::AllowSetCookie(
1462 const GURL& url,
1463 const GURL& first_party,
1464 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201465 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011466 int render_process_id,
1467 int render_view_id,
1468 net::CookieOptions* options) {
1469 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201470 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051471 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1472 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1473
[email protected]8093a542011-05-13 07:29:321474 BrowserThread::PostTask(
1475 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031476 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431477 render_view_id, url, first_party, cookie_line, *options,
1478 !allow));
[email protected]ed24fad2011-05-10 22:44:011479 return allow;
1480}
1481
[email protected]d5a19162011-06-30 18:51:541482bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201483 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201485 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431486 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1487 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261488
[email protected]bf510ed2012-06-05 08:31:431489 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1490 // Could we even support per-origin settings?
1491 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541492}
1493
[email protected]5c5a88e2011-11-12 00:45:351494bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351495 const GURL& url,
1496 const string16& name,
1497 const string16& display_name,
1498 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201499 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481500 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201502 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351503 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1504 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1505
[email protected]62151052012-02-01 18:40:481506 // Record access to database for potential display in UI.
1507 std::vector<std::pair<int, int> >::const_iterator i;
1508 for (i = render_views.begin(); i != render_views.end(); ++i) {
1509 BrowserThread::PostTask(
1510 BrowserThread::UI, FROM_HERE,
1511 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1512 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351513 }
1514
1515 return allow;
1516}
1517
1518bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351519 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201520 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481521 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201523 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351524 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1525 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1526
[email protected]62151052012-02-01 18:40:481527 // Record access to file system for potential display in UI.
1528 std::vector<std::pair<int, int> >::const_iterator i;
1529 for (i = render_views.begin(); i != render_views.end(); ++i) {
1530 BrowserThread::PostTask(
1531 BrowserThread::UI, FROM_HERE,
1532 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1533 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351534 }
1535
1536 return allow;
1537}
1538
[email protected]7c5ff9a2012-03-02 07:42:491539bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1540 const GURL& url,
1541 const string16& name,
1542 content::ResourceContext* context,
1543 const std::vector<std::pair<int, int> >& render_views) {
1544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1545 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1546 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1547 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1548
1549 // Record access to IndexedDB for potential display in UI.
1550 std::vector<std::pair<int, int> >::const_iterator i;
1551 for (i = render_views.begin(); i != render_views.end(); ++i) {
1552 BrowserThread::PostTask(
1553 BrowserThread::UI, FROM_HERE,
1554 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1555 i->first, i->second, url, name, !allow));
1556 }
1557
1558 return allow;
1559}
1560
[email protected]6133f922011-07-01 21:34:341561net::URLRequestContext*
1562ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201563 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421565 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201566 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341567 return io_data->extensions_request_context();
1568 }
1569
1570 return NULL;
1571}
1572
[email protected]317f96c92011-05-31 06:53:411573QuotaPermissionContext*
1574ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1575 return new ChromeQuotaPermissionContext();
1576}
1577
[email protected]848dd042011-06-04 18:24:031578void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171579 int render_process_id,
1580 int render_view_id,
1581 int cert_error,
1582 const net::SSLInfo& ssl_info,
1583 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021584 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031585 bool overridable,
[email protected]d9be47702012-05-16 03:41:221586 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171587 const base::Callback<void(bool)>& callback,
[email protected]8c965c22013-05-23 19:28:001588 content::CertificateRequestResultType* result) {
[email protected]a2f76882013-02-25 21:36:021589 if (resource_type != ResourceType::MAIN_FRAME) {
1590 // A sub-resource has a certificate error. The user doesn't really
1591 // have a context for making the right decision, so block the
1592 // request hard, without an info bar to allow showing the insecure
1593 // content.
[email protected]8c965c22013-05-23 19:28:001594 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
[email protected]a2f76882013-02-25 21:36:021595 return;
1596 }
1597
[email protected]f9034cf2011-07-21 12:43:411598 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131599 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171600 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411601 if (!tab) {
1602 NOTREACHED();
1603 return;
1604 }
1605 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501606 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301607 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011608 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1609 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411610 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171611 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411612 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]8c965c22013-05-23 19:28:001613 *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
[email protected]f9034cf2011-07-21 12:43:411614 return;
1615 }
1616 }
1617
[email protected]1e87df32012-09-12 04:53:191618#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231619 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1620 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1621 if (captive_portal_tab_helper)
1622 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191623#endif
1624
[email protected]f9034cf2011-07-21 12:43:411625 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221626 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1627 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031628}
1629
[email protected]c99c442e2011-08-24 11:37:301630void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451631 int render_process_id,
1632 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401633 const net::HttpNetworkSession* network_session,
1634 net::SSLCertRequestInfo* cert_request_info,
1635 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131636 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451637 render_process_id, render_view_id);
1638 if (!tab) {
1639 NOTREACHED();
1640 return;
1641 }
1642
[email protected]6786bf402011-12-03 15:19:451643 GURL requesting_url("https://" + cert_request_info->host_and_port);
1644 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1645 << cert_request_info->host_and_port;
1646
[email protected]627e0512011-12-21 22:55:301647 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451648 scoped_ptr<Value> filter(
1649 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1650 requesting_url,
1651 requesting_url,
1652 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1653 std::string(), NULL));
1654
1655 if (filter.get()) {
1656 // Try to automatically select a client certificate.
1657 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1658 DictionaryValue* filter_dict =
1659 static_cast<DictionaryValue*>(filter.get());
1660
1661 const std::vector<scoped_refptr<net::X509Certificate> >&
1662 all_client_certs = cert_request_info->client_certs;
1663 for (size_t i = 0; i < all_client_certs.size(); ++i) {
[email protected]dc24976f2013-06-02 21:15:091664 if (CertMatchesFilter(*all_client_certs[i].get(), *filter_dict)) {
[email protected]6786bf402011-12-03 15:19:451665 // Use the first certificate that is matched by the filter.
[email protected]dc24976f2013-06-02 21:15:091666 callback.Run(all_client_certs[i].get());
[email protected]6786bf402011-12-03 15:19:451667 return;
1668 }
1669 }
1670 } else {
1671 NOTREACHED();
1672 }
1673 }
1674
[email protected]11feec322012-09-18 03:58:521675 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1676 if (!ssl_tab_helper) {
1677 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451678 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141679 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401680 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451681 return;
1682 }
[email protected]11feec322012-09-18 03:58:521683 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401684 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451685}
1686
[email protected]3b455502012-12-11 18:22:581687void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451688 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581689 net::CertificateMimeType cert_type,
1690 const void* cert_data,
1691 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451692 int render_process_id,
1693 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581694 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1695 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451696}
1697
[email protected]dc73a7b2012-03-25 15:27:181698content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561699 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181700}
1701
[email protected]941623e2011-06-07 23:06:041702void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1703 const GURL& source_origin,
1704 int callback_context,
1705 int render_process_id,
1706 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111707#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021708 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1709 WebContents* contents =
1710 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1711 if (!contents) {
[email protected]941623e2011-06-07 23:06:041712 NOTREACHED();
1713 return;
1714 }
1715
[email protected]d0d9c3ee2012-06-19 03:07:021716 // Skip showing the infobar if the request comes from an extension, and that
1717 // extension has the 'notify' permission. (If the extension does not have the
1718 // permission, the user will still be prompted.)
1719 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011720 ExtensionInfoMap* extension_info_map =
1721 extensions::ExtensionSystem::Get(profile)->info_map();
1722 DesktopNotificationService* notification_service =
1723 DesktopNotificationServiceFactory::GetForProfile(profile);
1724 const Extension* extension = NULL;
1725 if (extension_info_map) {
1726 ExtensionSet extensions;
1727 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1728 source_origin, render_process_id,
1729 extensions::APIPermission::kNotification, &extensions);
1730 for (ExtensionSet::const_iterator iter = extensions.begin();
1731 iter != extensions.end(); ++iter) {
1732 if (notification_service->IsExtensionEnabled((*iter)->id())) {
[email protected]cadac622013-06-11 16:46:361733 extension = iter->get();
[email protected]c7cd5942013-04-30 03:31:011734 break;
1735 }
1736 }
1737 }
[email protected]eb4832a2012-12-08 01:57:521738 RenderViewHost* rvh =
1739 RenderViewHost::FromID(render_process_id, render_view_id);
1740 if (IsExtensionWithPermissionOrSuggestInConsole(
1741 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021742 if (rvh)
1743 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1744 return;
1745 }
1746
[email protected]c7cd5942013-04-30 03:31:011747 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021748 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111749#else
1750 NOTIMPLEMENTED();
1751#endif
[email protected]941623e2011-06-07 23:06:041752}
1753
1754WebKit::WebNotificationPresenter::Permission
1755 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021756 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201757 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021758 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111759#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041760 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201761 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041762
[email protected]c7cd5942013-04-30 03:31:011763 DesktopNotificationService* notification_service =
1764 io_data->GetNotificationService();
1765 if (notification_service) {
1766 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1767 ExtensionSet extensions;
1768 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1769 source_origin, render_process_id,
1770 extensions::APIPermission::kNotification, &extensions);
1771 for (ExtensionSet::const_iterator iter = extensions.begin();
1772 iter != extensions.end(); ++iter) {
1773 if (notification_service->IsExtensionEnabled((*iter)->id()))
1774 return WebKit::WebNotificationPresenter::PermissionAllowed;
1775 }
1776
1777 return notification_service->HasPermission(source_origin);
1778 }
1779
1780 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111781#else
1782 return WebKit::WebNotificationPresenter::PermissionAllowed;
1783#endif
[email protected]941623e2011-06-07 23:06:041784}
1785
1786void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171787 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041788 int render_process_id,
1789 int render_view_id,
1790 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111791#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041792 RenderViewHost* rvh = RenderViewHost::FromID(
1793 render_process_id, render_view_id);
1794 if (!rvh) {
1795 NOTREACHED();
1796 return;
1797 }
1798
[email protected]9f76c1e2012-03-05 15:15:581799 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301800 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041801 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371802 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041803 service->ShowDesktopNotification(
1804 params, render_process_id, render_view_id,
1805 worker ? DesktopNotificationService::WorkerNotification :
1806 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111807#else
1808 NOTIMPLEMENTED();
1809#endif
[email protected]941623e2011-06-07 23:06:041810}
1811
1812void ChromeContentBrowserClient::CancelDesktopNotification(
1813 int render_process_id,
1814 int render_view_id,
1815 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111816#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041817 RenderViewHost* rvh = RenderViewHost::FromID(
1818 render_process_id, render_view_id);
1819 if (!rvh) {
1820 NOTREACHED();
1821 return;
1822 }
1823
[email protected]9f76c1e2012-03-05 15:15:581824 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301825 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041826 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371827 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041828 service->CancelDesktopNotification(
1829 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111830#else
1831 NOTIMPLEMENTED();
1832#endif
[email protected]941623e2011-06-07 23:06:041833}
1834
[email protected]9f3fba52011-06-08 20:37:191835bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351836 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021837 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191838 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201839 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011840 int render_process_id,
1841 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191842 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011843
1844 *no_javascript_access = false;
1845
[email protected]9f3fba52011-06-08 20:37:191846 // If the opener is trying to create a background window but doesn't have
1847 // the appropriate permission, fail the attempt.
1848 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201849 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531850 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1851
[email protected]03b6d552012-03-29 04:03:011852 if (!map->SecurityOriginHasAPIPermission(
1853 source_origin,
1854 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061855 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011856 return false;
1857 }
1858
[email protected]7b54ca02012-03-02 18:06:531859 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1860 // return a recently installed Extension even if this CanCreateWindow call
1861 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011862 // because the permission check above would have caused an early return
1863 // already. We must use the full URL to find hosted apps, though, and not
1864 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531865 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351866 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291867 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011868 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191869 }
[email protected]056efdc2013-04-06 00:14:531870
1871 // No new browser window (popup or tab) in app mode.
1872 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1873 chrome::IsRunningInForcedAppMode()) {
1874 return false;
1875 }
1876
[email protected]9f3fba52011-06-08 20:37:191877 return true;
1878}
1879
1880std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201881 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191882 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1883 // Check if it's an extension-created worker, in which case we want to use
1884 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201885 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191886 const Extension* extension =
1887 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1888 return extension ? extension->name() : std::string();
1889}
1890
[email protected]99907362012-01-11 05:41:401891void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1892 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171893}
1894
[email protected]7a06d282013-05-03 04:39:331895// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021896content::SpeechRecognitionManagerDelegate*
1897 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]3bd0aab2013-05-30 20:07:491898#if !defined(OS_ANDROID)
[email protected]c52b2892012-03-07 11:01:021899 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321900#else
[email protected]3bd0aab2013-05-30 20:07:491901 // TODO(janx): Implement speech::AndroidSpeechRecognitionManagerDelegate
1902 // (see crbug.com/222352).
[email protected]a03f2d32012-03-14 00:26:321903 return NULL;
1904#endif
[email protected]66cfec62012-02-24 17:57:511905}
1906
[email protected]ae6e9912011-07-27 01:18:281907net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1908 return g_browser_process->net_log();
1909}
1910
[email protected]32538d92011-08-25 00:09:231911AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1912 return new ChromeAccessTokenStore();
1913}
1914
[email protected]dbae6b02011-06-29 23:51:411915bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011916 return true;
[email protected]dbae6b02011-06-29 23:51:411917}
1918
[email protected]64d69de42012-02-06 00:19:541919void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321920 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061921 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581922 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061923 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061924
[email protected]f3986f82012-01-03 20:00:061925 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541926 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061927 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541928 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061929 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541930 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061931 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541932 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061933 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541934 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061935 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541936 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031937 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1938 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061939
[email protected]64d69de42012-02-06 00:19:541940 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401941 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541942 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401943 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541944 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401945 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541946 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401947 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061948
[email protected]ddf72142012-05-22 04:52:401949 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061950
[email protected]64d69de42012-02-06 00:19:541951 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401952 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541953 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061954 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541955 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061956 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1957 const DictionaryValue* inspector_settings =
1958 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1959 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181960 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1961 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061962 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181963 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541964 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181965 std::make_pair(iter.key(), value));
1966 }
[email protected]f3986f82012-01-03 20:00:061967 }
1968 }
[email protected]64d69de42012-02-06 00:19:541969 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061970
[email protected]ddf72142012-05-22 04:52:401971 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541972 web_prefs->javascript_enabled = false;
1973 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1974 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401975 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541976 web_prefs->plugins_enabled = false;
1977 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1978 web_prefs->java_enabled = false;
1979 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401980 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061981
[email protected]64d69de42012-02-06 00:19:541982 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1983 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061984
[email protected]64d69de42012-02-06 00:19:541985 web_prefs->memory_info_enabled =
1986 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1987 web_prefs->allow_displaying_insecure_content =
1988 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1989 web_prefs->allow_running_insecure_content =
1990 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321991#if defined(OS_ANDROID)
1992 web_prefs->font_scale_factor =
1993 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1994 web_prefs->force_enable_zoom =
1995 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451996#if defined(GOOGLE_TV)
1997 web_prefs->user_gesture_required_for_media_playback = false;
1998#endif
[email protected]d3b935f2012-10-19 23:14:321999#endif
[email protected]5c915252013-05-07 13:15:392000
[email protected]af4256d52013-06-04 20:39:072001#if defined(OS_ANDROID)
2002 web_prefs->password_echo_enabled =
2003 prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled);
2004#else
[email protected]9d06d88d2012-02-23 22:37:082005 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]af4256d52013-06-04 20:39:072006#endif
2007
[email protected]5c915252013-05-07 13:15:392008#if defined(OS_CHROMEOS)
2009 // Enable password echo during OOBE when keyboard driven flag is set.
2010 if (chromeos::UserManager::IsInitialized() &&
2011 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
2012 !chromeos::StartupUtils::IsOobeCompleted()) {
2013 bool keyboard_driven_oobe = false;
2014 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]0071aed32013-06-19 13:39:552015 chromeos::system::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:392016 if (keyboard_driven_oobe)
2017 web_prefs->password_echo_enabled = true;
2018 }
2019#endif
[email protected]f3986f82012-01-03 20:00:062020
[email protected]46f8e742013-05-03 18:37:142021#if defined(OS_ANDROID)
2022 web_prefs->user_style_sheet_enabled = false;
2023#else
[email protected]64d69de42012-02-06 00:19:542024 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:152025 UserStyleSheetWatcher* user_style_sheet_watcher =
[email protected]cadac622013-06-11 16:46:362026 UserStyleSheetWatcherFactory::GetForProfile(profile).get();
[email protected]13169ab2012-04-06 07:48:152027 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:542028 web_prefs->user_style_sheet_enabled = true;
2029 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:152030 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:542031 } else {
2032 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:062033 }
[email protected]46f8e742013-05-03 18:37:142034#endif
[email protected]f3986f82012-01-03 20:00:062035
[email protected]cfadadd2013-04-03 04:43:022036 web_prefs->asynchronous_spell_checking_enabled = true;
2037 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:572038
[email protected]64d69de42012-02-06 00:19:542039 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:062040 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:542041 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:062042 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:542043 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:062044 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
2045
2046 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:542047 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:062048 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:542049 web_prefs->default_encoding);
2050 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:402051 prefs->ClearPref(prefs::kDefaultCharset);
2052 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:062053 }
[email protected]64d69de42012-02-06 00:19:542054 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:062055
[email protected]88ecf66d2012-12-11 22:53:472056 if (content::IsForceCompositingModeEnabled())
2057 web_prefs->force_compositing_mode = true;
2058
[email protected]299d7f12012-05-23 05:31:152059 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232060 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132061 ExtensionService* service =
2062 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062063 if (service) {
[email protected]1bc28312012-11-08 08:31:532064 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2065 const Extension* extension = service->extensions()->GetByID(url.host());
2066 // Ensure that we are only granting extension preferences to URLs with
2067 // the correct scheme. Without this check, chrome-guest:// schemes used by
2068 // webview tags as well as hosts that happen to match the id of an
2069 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422070 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532071 extension_webkit_preferences::SetPreferences(
2072 extension, view_type, web_prefs);
2073 }
[email protected]f3986f82012-01-03 20:00:062074 }
2075
[email protected]cb2edf22013-04-01 20:25:232076 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542077 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232078 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062079 // Disable all kinds of acceleration for background pages.
2080 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542081 web_prefs->force_compositing_mode = false;
2082 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062083 }
[email protected]2e21fe292012-03-02 22:52:322084
2085#if defined(FILE_MANAGER_EXTENSION)
2086 // Override the default of suppressing HW compositing for WebUI pages for the
2087 // file manager, which is implemented using WebUI but wants HW acceleration
2088 // for video decode & render.
[email protected]02a3dc122013-06-13 15:07:532089 if (url.SchemeIs(extensions::kExtensionScheme) &&
2090 url.host() == kFileBrowserDomain) {
[email protected]2e21fe292012-03-02 22:52:322091 web_prefs->accelerated_compositing_enabled = true;
2092 web_prefs->accelerated_2d_canvas_enabled = true;
2093 }
2094#endif
[email protected]181a95ee2011-07-12 19:26:362095}
2096
2097void ChromeContentBrowserClient::UpdateInspectorSetting(
2098 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062099 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582100 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062101 DictionaryPrefUpdate update(
2102 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2103 prefs::kWebKitInspectorSettings);
2104 DictionaryValue* inspector_settings = update.Get();
2105 inspector_settings->SetWithoutPathExpansion(key,
2106 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362107}
2108
[email protected]b8148ac2011-07-13 22:03:252109void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2110 BrowserURLHandler* handler) {
2111 // Add the default URL handlers.
2112 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2113 BrowserURLHandler::null_handler());
2114 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2115 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2116
[email protected]b3adbd02011-11-30 22:23:272117 // about: handler. Must come before chrome: handler, since it will
2118 // rewrite about: urls to chrome: URLs and then expect chrome: to
2119 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252120 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2121 BrowserURLHandler::null_handler());
2122 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242123 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252124}
2125
2126void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372127 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582128 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472129 BrowsingDataRemover* remover =
2130 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552131 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2132 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252133 // BrowsingDataRemover takes care of deleting itself when done.
2134}
2135
2136void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372137 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582138 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472139 BrowsingDataRemover* remover =
2140 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232141 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552142 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252143 // BrowsingDataRemover takes care of deleting itself when done.
2144}
2145
[email protected]650b2d52013-02-10 03:41:452146base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322147 return download_util::GetDefaultDownloadDirectory();
2148}
2149
[email protected]c9b6eb62011-10-18 20:49:392150std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2151 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2152}
2153
[email protected]b7631cc2012-09-15 05:08:382154void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2155 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542156#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382157 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2158 scoped_ptr<ppapi::host::HostFactory>(
2159 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542160#endif
[email protected]b7631cc2012-09-15 05:08:382161}
2162
[email protected]0c7193742012-11-07 19:05:032163content::BrowserPpapiHost*
2164 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2165 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132166 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032167 while (!iter.Done()) {
2168 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2169 if (host->process() &&
2170 host->process()->GetData().id == plugin_process_id) {
2171 // Found the plugin.
2172 return host->browser_ppapi_host();
2173 }
2174 ++iter;
2175 }
2176 return NULL;
2177}
2178
[email protected]7b38b192013-03-23 18:39:312179bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2180 content::BrowserContext* browser_context, const GURL& site_url) {
2181 if (CommandLine::ForCurrentProcess()->HasSwitch(
2182 switches::kEnableBrowserPluginForAllViewTypes))
2183 return true;
2184
2185 Profile* profile = Profile::FromBrowserContext(browser_context);
2186 ExtensionService* service =
2187 extensions::ExtensionSystem::Get(profile)->extension_service();
2188 if (!service)
2189 return false;
2190
2191 const Extension* extension = service->extensions()->
2192 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2193 if (!extension)
2194 return false;
2195
[email protected]c2d2f102013-04-29 16:42:582196 return extension->HasAPIPermission(APIPermission::kWebView) ||
2197 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312198}
2199
[email protected]38cd8f7f2012-06-15 22:06:072200bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582201 content::BrowserContext* browser_context,
2202 const GURL& url,
[email protected]dda54822013-06-15 01:26:392203 bool private_api,
[email protected]157cc902012-11-02 06:31:582204 const content::SocketPermissionRequest& params) {
[email protected]93f72062013-05-29 20:29:402205#if defined(ENABLE_PLUGINS)
[email protected]9d450492013-06-13 23:08:372206 Profile* profile = Profile::FromBrowserContext(browser_context);
2207 const ExtensionSet* extension_set = NULL;
2208 if (profile) {
2209 extension_set = extensions::ExtensionSystem::Get(profile)->
2210 extension_service()->extensions();
2211 }
[email protected]dda54822013-06-15 01:26:392212
2213 if (private_api) {
2214 // Access to private socket APIs is controlled by the whitelist.
2215 if (IsExtensionOrSharedModuleWhitelisted(url, extension_set,
2216 allowed_socket_origins_)) {
2217 return true;
2218 }
2219 } else {
2220 // Access to public socket APIs is controlled by extension permissions.
2221 if (url.is_valid() && url.SchemeIs(extensions::kExtensionScheme) &&
2222 extension_set) {
2223 const Extension* extension = extension_set->GetByID(url.host());
2224 if (extension) {
2225 extensions::SocketPermission::CheckParam check_params(
2226 params.type, params.host, params.port);
2227 if (extensions::PermissionsData::CheckAPIPermissionWithParam(
2228 extension, extensions::APIPermission::kSocket, &check_params)) {
2229 return true;
2230 }
2231 }
2232 }
2233 }
2234
2235 // Allow both public and private APIs if the command line says so.
2236 return IsHostAllowedByCommandLine(url, extension_set,
2237 switches::kAllowNaClSocketAPI);
[email protected]93f72062013-05-29 20:29:402238#else
[email protected]a658d452012-03-02 12:45:292239 return false;
[email protected]93f72062013-05-29 20:29:402240#endif
[email protected]e461da2f2012-02-16 19:06:402241}
2242
[email protected]650b2d52013-02-10 03:41:452243base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2244 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142245 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2246 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2247}
2248
[email protected]a28e3302013-02-03 03:50:432249ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2250 WebContents* web_contents) {
2251 return new ChromeSelectFilePolicy(web_contents);
2252}
2253
[email protected]7d9424702013-04-14 13:14:162254void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2255 std::vector<std::string>* additional_allowed_schemes) {
2256 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2257 additional_allowed_schemes);
2258 additional_allowed_schemes->push_back(kChromeUIScheme);
2259 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2260}
2261
[email protected]02250952013-04-24 23:52:532262void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2263 const base::FilePath& storage_partition_path,
[email protected]b40015c2013-06-26 08:13:312264 quota::SpecialStoragePolicy* special_storage_policy,
2265 fileapi::ExternalMountPoints* external_mount_points,
[email protected]02250952013-04-24 23:52:532266 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2267#if !defined(OS_ANDROID)
[email protected]30a306f42013-06-10 03:09:032268 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
[email protected]02250952013-04-24 23:52:532269 additional_providers->push_back(new MediaFileSystemMountPointProvider(
[email protected]30a306f42013-06-10 03:09:032270 storage_partition_path,
2271 pool->GetSequencedTaskRunner(pool->GetNamedSequenceToken(
[email protected]e66f02632013-06-13 22:51:502272 MediaFileSystemMountPointProvider::kMediaTaskRunnerName)).get()));
[email protected]02250952013-04-24 23:52:532273#endif
[email protected]b40015c2013-06-26 08:13:312274#if defined(OS_CHROMEOS)
2275 DCHECK(external_mount_points);
2276 chromeos::CrosMountPointProvider* cros_mount_provider =
2277 new chromeos::CrosMountPointProvider(
2278 special_storage_policy,
2279 external_mount_points,
2280 fileapi::ExternalMountPoints::GetSystemInstance());
2281 cros_mount_provider->AddSystemMountPoints();
2282 DCHECK(cros_mount_provider->CanHandleType(fileapi::kFileSystemTypeExternal));
2283 additional_providers->push_back(cros_mount_provider);
2284#endif
[email protected]02250952013-04-24 23:52:532285}
2286
[email protected]e60c0232011-11-11 19:56:352287#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182288void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2289 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382290 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082291 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392292#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452293 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392294 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2295 DCHECK(!data_path.empty());
2296
2297 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452298 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392299 base::PlatformFile f =
2300 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2301 DCHECK(f != base::kInvalidPlatformFileValue);
2302 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2303 FileDescriptor(f, true)));
2304
[email protected]650b2d52013-02-10 03:41:452305 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392306 data_path.AppendASCII("chrome_100_percent.pak");
2307 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2308 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372309 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392310 FileDescriptor(f, true)));
2311
2312 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452313 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392314 GetLocaleFilePath(locale, false);
2315 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2316 DCHECK(f != base::kInvalidPlatformFileValue);
2317 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2318 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382319
[email protected]650b2d52013-02-10 03:41:452320 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372321 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2322 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2323 DCHECK(f != base::kInvalidPlatformFileValue);
2324 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2325 FileDescriptor(f, true)));
2326
[email protected]40da3e0c2012-10-24 22:03:382327#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432328 if (IsCrashReporterEnabled()) {
2329 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2330 if (f == base::kInvalidPlatformFileValue) {
2331 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2332 "be disabled for this process.";
2333 } else {
2334 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2335 FileDescriptor(f, true)));
2336 }
[email protected]40da3e0c2012-10-24 22:03:382337 }
2338#endif // defined(USE_LINUX_BREAKPAD)
2339
2340#else
2341 int crash_signal_fd = GetCrashSignalFD(command_line);
2342 if (crash_signal_fd >= 0) {
2343 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2344 FileDescriptor(crash_signal_fd,
2345 false)));
2346 }
[email protected]29699c22012-10-03 23:57:392347#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302348}
[email protected]e60c0232011-11-11 19:56:352349#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302350
[email protected]4a65826d2011-08-25 16:04:012351#if defined(OS_WIN)
2352const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2353 return chrome::kBrowserResourcesDll;
2354}
[email protected]34f48682013-03-20 00:30:182355
2356void ChromeContentBrowserClient::PreSpawnRenderer(
2357 sandbox::TargetPolicy* policy,
2358 bool* success) {
2359 // This code is duplicated in nacl_exe_win_64.cc.
2360 // Allow the server side of a pipe restricted to the "chrome.nacl."
2361 // namespace so that it cannot impersonate other system or other chrome
2362 // service pipes.
2363 sandbox::ResultCode result = policy->AddRule(
2364 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2365 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2366 L"\\\\.\\pipe\\chrome.nacl.*");
2367 if (result != sandbox::SBOX_ALL_OK) {
2368 *success = false;
2369 return;
2370 }
2371
2372 // Renderers need to send named pipe handles and shared memory
2373 // segment handles to NaCl loader processes.
2374 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2375 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2376 L"File");
2377 if (result != sandbox::SBOX_ALL_OK) {
2378 *success = false;
2379 return;
2380 }
2381}
[email protected]4a65826d2011-08-25 16:04:012382#endif
2383
[email protected]37a72af2011-06-13 05:42:012384#if defined(USE_NSS)
2385crypto::CryptoModuleBlockingPasswordDelegate*
2386 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2387 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292388 return chrome::NewCryptoModuleBlockingDialogDelegate(
2389 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012390}
2391#endif
2392
[email protected]d977f9c2011-03-14 16:10:262393} // namespace chrome