blob: 5d1fec5d4b1a3862d89342776983f2ae87de8623 [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]b71313232013-05-06 06:16:2916#include "base/sha1.h"
17#include "base/string_number_conversions.h"
[email protected]f4ebe772013-02-02 00:21:3918#include "base/strings/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0619#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3020#include "chrome/app/breakpad_mac.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]0c7193742012-11-07 19:05:0350#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2851#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0452#include "chrome/browser/notifications/desktop_notification_service.h"
53#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4254#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5655#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0656#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4157#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5058#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0759#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4160#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1461#include "chrome/browser/printing/printing_message_filter.h"
[email protected]7e75e4a2013-05-17 17:20:0362#include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h"
[email protected]05fcf982011-04-19 00:44:1463#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3264#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0665#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1466#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3867#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4368#include "chrome/browser/search/instant_service.h"
69#include "chrome/browser/search/instant_service_factory.h"
70#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1471#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0272#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3373#include "chrome/browser/speech/tts_message_filter.h"
[email protected]8ec71262011-07-28 08:12:4674#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5875#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0376#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5277#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4578#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5479#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4380#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]b5d73422012-06-02 23:46:4481#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5082#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]970c63e2013-03-07 00:25:3083#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
[email protected]f3986f82012-01-03 20:00:0684#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1585#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2786#include "chrome/browser/validation_message_message_filter.h"
[email protected]b80f68432011-05-02 17:22:3087#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0188#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1489#include "chrome/common/chrome_paths.h"
[email protected]f3b357692013-03-22 05:16:1390#include "chrome/common/chrome_process_type.h"
[email protected]b80f68432011-05-02 17:22:3091#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2992#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0493#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3894#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4495#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4396#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:2997#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]157cc902012-11-02 06:31:5898#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3499#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:12100#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:38101#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09102#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53103#include "chromeos/chromeos_constants.h"
[email protected]75fee372013-03-06 00:42:44104#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43105#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30106#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38107#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:31108#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03109#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59110#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36111#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30112#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33113#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05114#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33115#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19116#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10117#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43118#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18119#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23120#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42121#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39122#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23123#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53124#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58125#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34126#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06127#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57128#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38129#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39130#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08131#include "ui/base/resource/resource_bundle.h"
[email protected]fb1aac12013-05-14 05:30:24132#include "ui/message_center/message_center_util.h"
[email protected]4fdf6742012-01-10 20:14:36133#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04134#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26135
[email protected]b48c9182011-10-26 18:03:30136#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38137#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18138#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38139#elif defined(OS_MACOSX)
140#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56141#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30142#elif defined(OS_CHROMEOS)
143#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]5c915252013-05-07 13:15:39144#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49145#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]5c915252013-05-07 13:15:39146#include "chrome/browser/chromeos/system/statistics_provider.h"
[email protected]931d1042013-04-05 17:50:44147#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26148#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30149#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09150#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38151#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09152#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39153#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30154#elif defined(OS_POSIX)
155#include "chrome/browser/chrome_browser_main_posix.h"
156#endif
157
[email protected]6653c192012-04-10 22:52:44158#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30159#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12160#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43161#endif
[email protected]b80f68432011-05-02 17:22:30162
[email protected]1e87df32012-09-12 04:53:19163#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
164#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
165#endif
166
[email protected]29699c22012-10-03 23:57:39167#if defined(OS_ANDROID)
168#include "ui/base/ui_base_paths.h"
169#endif
170
[email protected]37a72af2011-06-13 05:42:01171#if defined(USE_NSS)
172#include "chrome/browser/ui/crypto_module_password_dialog.h"
173#endif
174
[email protected]d5bcd06f2013-04-21 08:07:24175#if !defined(OS_CHROMEOS)
176#include "chrome/browser/signin/signin_manager.h"
177#include "chrome/browser/signin/signin_manager_factory.h"
178#endif
179
[email protected]02250952013-04-24 23:52:53180#if !defined(OS_ANDROID)
181#include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h"
182#endif
183
[email protected]c7abd422012-09-25 00:20:08184using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47185using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03186using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39187using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31188using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59189using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08190using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00191using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11192using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33193using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13194using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06195using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34196using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40197using extensions::Manifest;
[email protected]631bb742011-11-02 11:29:39198
[email protected]c5dbef02011-05-13 05:06:09199namespace {
200
[email protected]eabbfb12013-04-05 23:28:35201// Cached version of the locale so we can return the locale on the I/O
202// thread.
203base::LazyInstance<std::string> g_io_thread_application_locale;
204
[email protected]e461da2f2012-02-16 19:06:40205const char* kPredefinedAllowedSocketOrigins[] = {
206 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18207 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45208 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
209 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
210 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
211 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35212 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54213 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
214 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
215 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
216 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
217 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
218 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38219 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58220 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29221 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
222 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
223 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
224 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
225 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40226};
227
[email protected]f8f93eb2012-09-25 03:06:24228// Returns a copy of the given url with its host set to given host and path set
229// to given path. Other parts of the url will be the same.
230GURL ReplaceURLHostAndPath(const GURL& url,
231 const std::string& host,
232 const std::string& path) {
233 url_canon::Replacements<char> replacements;
234 replacements.SetHost(host.c_str(),
235 url_parse::Component(0, host.length()));
236 replacements.SetPath(path.c_str(),
237 url_parse::Component(0, path.length()));
238 return url.ReplaceComponents(replacements);
239}
240
241// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
242GURL AddUberHost(const GURL& url) {
243 const std::string uber_host = chrome::kChromeUIUberHost;
244 const std::string new_path = url.host() + url.path();
245
246 return ReplaceURLHostAndPath(url, uber_host, new_path);
247}
248
[email protected]045bf7c2012-09-28 20:27:36249// If url->host() is "chrome" and url->path() has characters other than the
250// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
251// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24252bool RemoveUberHost(GURL* url) {
253 if (url->host() != chrome::kChromeUIUberHost)
254 return false;
255
[email protected]045bf7c2012-09-28 20:27:36256 if (url->path().empty() || url->path() == "/")
257 return false;
258
[email protected]f8f93eb2012-09-25 03:06:24259 const std::string old_path = url->path();
260
261 const std::string::size_type separator = old_path.find('/', 1);
262 std::string new_host;
263 std::string new_path;
264 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36265 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24266 } else {
267 new_host = old_path.substr(1, separator - 1);
268 new_path = old_path.substr(separator);
269 }
270
271 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
272
273 return true;
274}
275
[email protected]b8148ac2011-07-13 22:03:25276// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42277bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24278 // Do not handle special URLs such as "about:foo"
279 if (!url->host().empty()) {
280 const GURL chrome_url = AddUberHost(*url);
281
282 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
283 // be called.
284 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
285 browser_context, chrome_url))
286 return true;
287 }
288
[email protected]863f70a2012-01-27 02:05:50289 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
290 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25291 return false;
292
[email protected]fe69558d2012-03-12 11:34:49293#if defined(OS_CHROMEOS)
294 // Special case : in ChromeOS in Guest mode bookmarks and history are
295 // disabled for security reasons. New tab page explains the reasons, so
296 // we redirect user to new tab page.
297 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
298 if (url->SchemeIs(chrome::kChromeUIScheme) &&
299 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
300 url->DomainIs(chrome::kChromeUIHistoryHost))) {
301 // Rewrite with new tab URL
302 *url = GURL(chrome::kChromeUINewTabURL);
303 }
304 }
305#endif
306
[email protected]b8148ac2011-07-13 22:03:25307 // Special case the new tab page. In older versions of Chrome, the new tab
308 // page was hosted at chrome-internal:<blah>. This might be in people's saved
309 // sessions or bookmarks, so we say any URL with that scheme triggers the new
310 // tab page.
311 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
312 // Rewrite it with the proper new tab URL.
313 *url = GURL(chrome::kChromeUINewTabURL);
314 }
315
316 return true;
317}
318
[email protected]f8f93eb2012-09-25 03:06:24319// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
320// "chrome://foo/".
321bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
322 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
323 return false;
324
325 return RemoveUberHost(url);
326}
327
[email protected]8d3132f62011-10-12 07:13:42328// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
329// below. Extension, and isolated apps require different privileges to be
330// granted to their RenderProcessHosts. This classification allows us to make
331// sure URLs are served by hosts with the right set of privileges.
332enum RenderProcessHostPrivilege {
333 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45334 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42335 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45336 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42337};
338
339RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
340 const GURL& url,
341 ExtensionService* service) {
342 // Default to a normal renderer cause it is lower privileged. This should only
343 // occur if the URL on a site instance is either malformed, or uninitialized.
344 // If it is malformed, then there is no need for better privileges anyways.
345 // If it is uninitialized, but eventually settles on being an a scheme other
346 // than normal webrenderer, the navigation logic will correct us out of band
347 // anyways.
348 if (!url.is_valid())
349 return PRIV_NORMAL;
350
[email protected]885c0e92012-11-13 20:27:42351 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44352 const Extension* extension =
353 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43354 if (extension &&
355 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42356 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45357 if (extension && extension->is_hosted_app())
358 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42359
360 return PRIV_EXTENSION;
361 }
362
363 return PRIV_NORMAL;
364}
365
366RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30367 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46368 extensions::ProcessMap* process_map,
369 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46370 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30371 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46372 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21373 return PRIV_NORMAL;
374
[email protected]6f371442011-11-09 06:45:46375 for (std::set<std::string>::iterator iter = extension_ids.begin();
376 iter != extension_ids.end(); ++iter) {
377 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43378 if (extension &&
379 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42380 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45381 if (extension && extension->is_hosted_app())
382 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42383 }
384
[email protected]676f6ab2011-10-19 20:23:21385 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42386}
387
[email protected]6786bf402011-12-03 15:19:45388bool CertMatchesFilter(const net::X509Certificate& cert,
389 const base::DictionaryValue& filter) {
390 // TODO(markusheintz): This is the minimal required filter implementation.
391 // Implement a better matcher.
392
393 // An empty filter matches any client certificate since no requirements are
394 // specified at all.
395 if (filter.empty())
396 return true;
397
398 std::string common_name;
399 if (filter.GetString("ISSUER.CN", &common_name) &&
400 (cert.issuer().common_name == common_name)) {
401 return true;
402 }
403 return false;
404}
405
[email protected]f3986f82012-01-03 20:00:06406// Fills |map| with the per-script font prefs under path |map_name|.
407void FillFontFamilyMap(const PrefService* prefs,
408 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53409 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06410 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
411 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
412 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
413 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23414 if (!font_family.empty())
415 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06416 }
417}
418
[email protected]a1733df2012-06-22 11:24:18419#if defined(OS_POSIX) && !defined(OS_MACOSX)
420int GetCrashSignalFD(const CommandLine& command_line) {
421 if (command_line.HasSwitch(switches::kExtensionProcess)) {
422 ExtensionCrashHandlerHostLinux* crash_handler =
423 ExtensionCrashHandlerHostLinux::GetInstance();
424 return crash_handler->GetDeathSignalSocket();
425 }
426
427 std::string process_type =
428 command_line.GetSwitchValueASCII(switches::kProcessType);
429
430 if (process_type == switches::kRendererProcess)
431 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
432
433 if (process_type == switches::kPluginProcess)
434 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
435
436 if (process_type == switches::kPpapiPluginProcess)
437 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
438
439 if (process_type == switches::kGpuProcess)
440 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
441
442 return -1;
443}
444#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
445
[email protected]d5bcd06f2013-04-21 08:07:24446#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30447GURL GetEffectiveURLForSignin(const GURL& url) {
448 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
449
450 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03451 // Copy the path because the argument to SetPathStr must outlive
452 // the Replacements object.
453 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30454 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03455 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30456 effective_url = effective_url.ReplaceComponents(replacements);
457 return effective_url;
458}
[email protected]d5bcd06f2013-04-21 08:07:24459#endif
[email protected]970c63e2013-03-07 00:25:30460
[email protected]eabbfb12013-04-05 23:28:35461void SetApplicationLocaleOnIOThread(const std::string& locale) {
462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
463 g_io_thread_application_locale.Get() = locale;
464}
465
[email protected]b71313232013-05-06 06:16:29466std::string HashHost(const std::string& host) {
467 const std::string id_hash = base::SHA1HashString(host);
468 DCHECK(id_hash.length() == base::kSHA1Length);
469 return base::HexEncode(id_hash.c_str(), id_hash.length());
470}
471
472bool HostIsInSet(const std::string& host, const std::set<std::string>& set) {
473 return set.count(host) > 0 || set.count(HashHost(host)) > 0;
474}
475
[email protected]9dbfff12011-07-01 19:37:07476} // namespace
[email protected]c5dbef02011-05-13 05:06:09477
[email protected]d977f9c2011-03-14 16:10:26478namespace chrome {
479
[email protected]e461da2f2012-02-16 19:06:40480ChromeContentBrowserClient::ChromeContentBrowserClient() {
481 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
482 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]1deace22013-05-22 06:14:46483
484 permissions_policy_delegate_.reset(
485 new extensions::BrowserPermissionsPolicyDelegate());
[email protected]e461da2f2012-02-16 19:06:40486}
487
488ChromeContentBrowserClient::~ChromeContentBrowserClient() {
489}
490
[email protected]bca18382012-06-25 19:15:23491// static
[email protected]c753f142013-02-10 13:14:04492void ChromeContentBrowserClient::RegisterUserPrefs(
[email protected]443e9312013-05-06 06:17:34493 user_prefs::PrefRegistrySyncable* registry) {
494 registry->RegisterBooleanPref(
495 prefs::kDisable3DAPIs,
496 false,
497 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
498 registry->RegisterBooleanPref(
499 prefs::kEnableHyperlinkAuditing,
500 true,
501 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
502 registry->RegisterBooleanPref(
503 prefs::kEnableMemoryInfo,
504 false,
505 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23506}
507
[email protected]eabbfb12013-04-05 23:28:35508// static
509void ChromeContentBrowserClient::SetApplicationLocale(
510 const std::string& locale) {
511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
512
513 // This object is guaranteed to outlive all threads so we don't have to
514 // worry about the lack of refcounting and can just post as Unretained.
515 //
516 // The common case is that this function is called early in Chrome startup
517 // before any threads are created (it will also be called later if the user
518 // changes the pref). In this case, there will be no threads created and
519 // posting will fail. When there are no threads, we can just set the string
520 // without worrying about threadsafety.
521 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
522 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
523 g_io_thread_application_locale.Get() = locale;
524 }
525}
526
[email protected]50462bf02011-11-21 19:13:31527content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
528 const content::MainFunctionParams& parameters) {
529 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30530 // Construct the Main browser parts based on the OS type.
531#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31532 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04533#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31534 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30535#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22536 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26537#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31538 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14539#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09540 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30541#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31542 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04543#else
[email protected]b48c9182011-10-26 18:03:30544 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31545 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30546#endif
547
[email protected]7e75e4a2013-05-17 17:20:03548 chrome::AddProfilesExtraParts(main_parts);
549
[email protected]c7480942011-11-08 19:18:27550 // Construct additional browser parts. Stages are called in the order in
551 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22552#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41553 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04554#endif
[email protected]c7480942011-11-08 19:18:27555
556#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41557 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27558#endif
559
[email protected]dc04be7c2012-03-15 23:57:49560#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41561 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49562#endif
563
[email protected]e050ef142012-03-21 01:04:24564#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41565 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24566#endif
567
[email protected]95132f52013-04-12 02:19:04568 chrome::AddMetricsExtraParts(main_parts);
569
[email protected]50462bf02011-11-21 19:13:31570 return main_parts;
[email protected]f967b722011-09-07 00:58:04571}
572
[email protected]e94bbcb2012-09-07 05:33:57573std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19574 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57575 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53576 std::string partition_id;
577
578 // The partition ID for webview guest processes is the string value of its
579 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
580 if (site.SchemeIs(chrome::kGuestScheme))
581 partition_id = site.spec();
582
[email protected]056efdc2013-04-06 00:14:53583 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53584 return partition_id;
585}
586
587bool ChromeContentBrowserClient::IsValidStoragePartitionId(
588 content::BrowserContext* browser_context,
589 const std::string& partition_id) {
590 // The default ID is empty and is always valid.
591 if (partition_id.empty())
592 return true;
593
594 return GURL(partition_id).is_valid();
595}
596
597void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
598 content::BrowserContext* browser_context,
599 const GURL& site,
[email protected]14acc642012-11-17 12:20:10600 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53601 std::string* partition_domain,
602 std::string* partition_name,
603 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10604 // Default to the browser-wide storage partition and override based on |site|
605 // below.
606 partition_domain->clear();
607 partition_name->clear();
608 *in_memory = false;
609
[email protected]1bc28312012-11-08 08:31:53610 // For the webview tag, we create special guest processes, which host the
611 // tag content separately from the main application that embeds the tag.
612 // A webview tag can specify both the partition name and whether the storage
613 // for that partition should be persisted. Each tag gets a SiteInstance with
614 // a specially formatted URL, based on the application it is hosted by and
615 // the partition requested by it. The format for that URL is:
616 // chrome-guest://partition_domain/persist?partition_name
617 if (site.SchemeIs(chrome::kGuestScheme)) {
618 // Since guest URLs are only used for packaged apps, there must be an app
619 // id in the URL.
620 CHECK(site.has_host());
621 *partition_domain = site.host();
622 // Since persistence is optional, the path must either be empty or the
623 // literal string.
624 *in_memory = (site.path() != "/persist");
625 // The partition name is user supplied value, which we have encoded when the
626 // URL was created, so it needs to be decoded.
627 *partition_name = net::UnescapeURLComponent(site.query(),
628 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10629 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
630 // If |can_be_default| is false, the caller is stating that the |site|
631 // should be parsed as if it had isolated storage. In particular it is
632 // important to NOT check ExtensionService for the is_storage_isolated()
633 // attribute because this code path is run during Extension uninstall
634 // to do cleanup after the Extension has already been unloaded from the
635 // ExtensionService.
636 bool is_isolated = !can_be_default;
637 if (can_be_default) {
638 const Extension* extension = NULL;
639 Profile* profile = Profile::FromBrowserContext(browser_context);
640 ExtensionService* extension_service =
641 extensions::ExtensionSystem::Get(profile)->extension_service();
642 if (extension_service) {
643 extension = extension_service->extensions()->
644 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43645 if (extension &&
646 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10647 is_isolated = true;
648 }
649 }
650 }
[email protected]1bc28312012-11-08 08:31:53651
[email protected]14acc642012-11-17 12:20:10652 if (is_isolated) {
653 CHECK(site.has_host());
654 // For extensions with isolated storage, the the host of the |site| is
655 // the |partition_domain|. The |in_memory| and |partition_name| are only
656 // used in guest schemes so they are cleared here.
657 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53658 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10659 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53660 }
[email protected]d1198fd2012-08-13 22:50:19661 }
662
[email protected]14acc642012-11-17 12:20:10663 // Assert that if |can_be_default| is false, the code above must have found a
664 // non-default partition. If this fails, the caller has a serious logic
665 // error about which StoragePartition they expect to be in and it is not
666 // safe to continue.
667 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44668}
669
[email protected]38b098f2012-03-14 21:11:57670content::WebContentsViewDelegate*
671 ChromeContentBrowserClient::GetWebContentsViewDelegate(
672 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27673 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32674}
675
[email protected]24665682013-02-25 20:59:38676// Check if the extension activity log is enabled for the profile.
677static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
678 extensions::ActivityLog* activity_log =
679 extensions::ActivityLog::GetInstance(profile);
680 return activity_log->IsLogEnabled();
681}
682
[email protected]44703cc72013-01-24 04:56:06683void ChromeContentBrowserClient::GuestWebContentsCreated(
684 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
685 Profile* profile = Profile::FromBrowserContext(
686 embedder_web_contents->GetBrowserContext());
687 ExtensionService* service =
688 extensions::ExtensionSystem::Get(profile)->extension_service();
689 if (!service)
690 return;
691 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
692 const Extension* extension = service->extensions()->
693 GetExtensionOrAppByURL(ExtensionURLInfo(url));
694 if (!extension)
695 return;
696 std::vector<ExtensionMsg_Loaded_Params> extensions;
697 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
698 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
[email protected]c4c2312c2013-05-13 05:04:11699 // TODO(fsamuel): This should be replaced with WebViewGuest or AdViewGuest
700 // once they are ready.
701 extensions::TabHelper::CreateForWebContents(guest_web_contents);
[email protected]44703cc72013-01-24 04:56:06702}
703
[email protected]f3b1a082011-11-18 00:34:30704void ChromeContentBrowserClient::RenderProcessHostCreated(
705 content::RenderProcessHost* host) {
706 int id = host->GetID();
707 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41708 net::URLRequestContextGetter* context =
709 profile->GetRequestContextForRenderProcess(id);
710
[email protected]f3b1a082011-11-18 00:34:30711 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41712 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55713#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30714 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55715#endif
[email protected]658677f2012-06-09 06:04:02716#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08717 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03718#endif
[email protected]f3b1a082011-11-18 00:34:30719 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02720 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30721 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56722#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21723 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56724#endif
[email protected]43535512013-02-20 20:41:41725 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
726 id, profile, context));
[email protected]2736c032012-05-11 18:06:07727 host->GetChannel()->AddFilter(
728 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27729 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33730 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38731
[email protected]2ccf45c2011-08-19 23:35:50732 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
733 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07734
[email protected]24665682013-02-25 20:59:38735 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
736 IsExtensionActivityLogEnabledForProfile(profile)));
737
[email protected]39a5b532011-10-22 01:47:07738 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56739
740 RendererContentSettingRules rules;
741 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
742 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14743}
744
[email protected]95c95552013-05-03 04:21:22745GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
746 content::BrowserContext* browser_context,
747 const GURL& url,
748 bool is_renderer_initiated,
749 content::SiteInstance* current_instance) {
750 Profile* profile = Profile::FromBrowserContext(browser_context);
751 if (!profile)
752 return url;
753
754 // Only return the privileged instant URL if we are entering from a browser-
755 // initiated navigation or if we are already in the instant process.
756 bool is_instant_process = false;
757 int process_id = current_instance->GetProcess()->GetID();
758 InstantService* instant_service =
759 InstantServiceFactory::GetForProfile(profile);
760 if (instant_service)
761 is_instant_process = instant_service->IsInstantProcess(process_id);
762
763 DCHECK_EQ(is_instant_process,
764 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
765 if (!is_renderer_initiated || is_instant_process) {
766 // If the input |url| should be assigned to the Instant renderer, make its
767 // privileged URL distinct from other URLs on the search provider's domain.
768 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
769 return chrome::GetPrivilegedURLForInstant(url, profile);
770 }
771
772 return url;
773}
774
[email protected]3d7474ff2011-07-27 17:47:37775GURL ChromeContentBrowserClient::GetEffectiveURL(
776 content::BrowserContext* browser_context, const GURL& url) {
777 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52778 if (!profile)
779 return url;
780
[email protected]d5bcd06f2013-04-21 08:07:24781#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30782 // If the input |url| should be assigned to the Signin renderer, make its
783 // effective URL distinct from other URLs on the signin service's domain.
784 // Note that the signin renderer will be allowed to sign the user in to
785 // Chrome.
786 if (SigninManager::IsWebBasedSigninFlowURL(url))
787 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24788#endif
[email protected]970c63e2013-03-07 00:25:30789
[email protected]c5dec6292013-01-25 04:54:52790 // If the input |url| is part of an installed app, the effective URL is an
791 // extension URL with the ID of that extension as the host. This has the
792 // effect of grouping apps together in a common SiteInstance.
793 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13794 extensions::ExtensionSystem::Get(profile)->extension_service();
795 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08796 return url;
797
[email protected]06bdd2b2012-11-30 18:47:13798 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44799 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08800 if (!extension)
801 return url;
802
[email protected]15877ca2011-11-18 22:40:52803 // Bookmark apps do not use the hosted app process model, and should be
804 // treated as normal URLs.
805 if (extension->from_bookmark())
806 return url;
807
[email protected]36fb2c7c2011-04-04 15:49:08808 // If the URL is part of an extension's web extent, convert it to an
809 // extension URL.
810 return extension->GetResourceURL(url.path());
811}
812
[email protected]056ad2a2011-07-12 02:13:55813bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37814 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52815 // Non-extension, non-Instant URLs should generally use
816 // process-per-site-instance. Because we expect to use the effective URL,
817 // URLs for hosted apps (apart from bookmark apps) should have an extension
818 // scheme by now.
819
820 Profile* profile = Profile::FromBrowserContext(browser_context);
821 if (!profile)
822 return false;
823
[email protected]165fe422013-03-27 06:34:03824 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52825 return true;
826
[email protected]d5bcd06f2013-04-21 08:07:24827#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30828 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
829 return true;
[email protected]d5bcd06f2013-04-21 08:07:24830#endif
[email protected]970c63e2013-03-07 00:25:30831
[email protected]885c0e92012-11-13 20:27:42832 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55833 return false;
834
[email protected]c5dec6292013-01-25 04:54:52835 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13836 extensions::ExtensionSystem::Get(profile)->extension_service();
837 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55838 return false;
839
[email protected]06bdd2b2012-11-30 18:47:13840 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44841 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55842 if (!extension)
843 return false;
844
845 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53846 // permission, or that does not allow JavaScript access to the background
847 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55848 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40849 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06850 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29851 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53852 return false;
853 }
854 }
[email protected]056ad2a2011-07-12 02:13:55855
[email protected]7b54ca02012-03-02 18:06:53856 // Hosted apps that have script access to their background page must use
857 // process per site, since all instances can make synchronous calls to the
858 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55859 return true;
860}
861
[email protected]672c8c12013-03-07 12:30:06862// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41863void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
864 std::vector<std::string>* additional_schemes) {
865 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06866}
867
[email protected]6bd30072013-02-08 18:17:11868net::URLRequestContextGetter*
869ChromeContentBrowserClient::CreateRequestContext(
870 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06871 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11872 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06873 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11874}
875
876net::URLRequestContextGetter*
877ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
878 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40879 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11880 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06881 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11882 Profile* profile = Profile::FromBrowserContext(browser_context);
883 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06884 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11885}
886
[email protected]46fb9442011-12-09 17:57:47887bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
888 return ProfileIOData::IsHandledURL(url);
889}
890
[email protected]c4365fa42013-05-14 01:08:24891bool ChromeContentBrowserClient::CanCommitURL(
892 content::RenderProcessHost* process_host,
893 const GURL& url) {
894 // We need to let most extension URLs commit in any process, since this can
895 // be allowed due to web_accessible_resources. Most hosted app URLs may also
896 // load in any process (e.g., in an iframe). However, the Chrome Web Store
897 // cannot be loaded in iframes and should never be requested outside its
898 // process.
899 Profile* profile =
900 Profile::FromBrowserContext(process_host->GetBrowserContext());
901 ExtensionService* service =
902 extensions::ExtensionSystem::Get(profile)->extension_service();
903 if (!service)
904 return true;
905 const Extension* new_extension =
906 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
907 if (new_extension &&
908 new_extension->is_hosted_app() &&
909 new_extension->id() == extension_misc::kWebStoreAppId &&
910 !service->process_map()->Contains(new_extension->id(),
911 process_host->GetID())) {
912 return false;
913 }
914
915 return true;
916}
917
[email protected]2a5221b2011-09-27 23:07:31918bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30919 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31920 const GURL& site_url) {
921 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30922 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52923 // This may be NULL during tests. In that case, just assume any site can
924 // share any host.
925 if (!profile)
926 return true;
927
[email protected]d43f99fe2013-04-03 00:20:14928 // Instant URLs should only be in the instant process and instant process
929 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52930 InstantService* instant_service =
931 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14932 if (instant_service) {
933 bool is_instant_process = instant_service->IsInstantProcess(
934 process_host->GetID());
935 bool should_be_in_instant_process =
936 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
937 if (is_instant_process || should_be_in_instant_process)
938 return is_instant_process && should_be_in_instant_process;
939 }
[email protected]c5dec6292013-01-25 04:54:52940
[email protected]d5bcd06f2013-04-21 08:07:24941#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30942 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
943 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
944 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:24945#endif
[email protected]970c63e2013-03-07 00:25:30946
[email protected]06bdd2b2012-11-30 18:47:13947 ExtensionService* service =
948 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46949 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31950
[email protected]ffa97602011-11-17 17:55:52951 // Don't allow the Task Manager to share a process with anything else.
952 // Otherwise it can affect the renderers it is observing.
953 // Note: we could create another RenderProcessHostPrivilege bucket for
954 // this to allow multiple chrome://tasks instances to share, but that's
955 // a very unlikely case without serious consequences.
956 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
957 return false;
958
[email protected]8d3132f62011-10-12 07:13:42959 // These may be NULL during tests. In that case, just assume any site can
960 // share any host.
[email protected]6f371442011-11-09 06:45:46961 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31962 return true;
963
[email protected]eec0b33c2011-12-05 22:09:45964 // Otherwise, just make sure the process privilege matches the privilege
965 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57966 RenderProcessHostPrivilege privilege_required =
967 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45968 return GetProcessPrivilege(process_host, process_map, service) ==
969 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31970}
971
[email protected]76411f412012-02-22 18:56:06972// This function is trying to limit the amount of processes used by extensions
973// with background pages. It uses a globally set percentage of processes to
974// run such extensions and if the limit is exceeded, it returns true, to
975// indicate to the content module to group extensions together.
976bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
977 content::BrowserContext* browser_context, const GURL& url) {
978 // It has to be a valid URL for us to check for an extension.
979 if (!url.is_valid())
980 return false;
981
982 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19983 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13984 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06985 if (!service)
986 return false;
987
988 // We have to have a valid extension with background page to proceed.
989 const Extension* extension =
990 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
991 if (!extension)
992 return false;
[email protected]9367eabc2013-03-01 01:29:29993 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06994 return false;
995
996 std::set<int> process_ids;
997 size_t max_process_count =
998 content::RenderProcessHost::GetMaxRendererProcessCount();
999
1000 // Go through all profiles to ensure we have total count of extension
1001 // processes containing background pages, otherwise one profile can
1002 // starve the other.
1003 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
1004 GetLoadedProfiles();
1005 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:031006 ExtensionProcessManager* epm =
1007 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:321008 for (ExtensionProcessManager::const_iterator iter =
1009 epm->background_hosts().begin();
1010 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:131011 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:321012 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:061013 }
1014 }
1015
1016 if (process_ids.size() >
1017 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
1018 return true;
1019 }
1020
1021 return false;
1022}
1023
[email protected]6f371442011-11-09 06:45:461024void ChromeContentBrowserClient::SiteInstanceGotProcess(
1025 SiteInstance* site_instance) {
1026 CHECK(site_instance->HasProcess());
1027
1028 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021029 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521030 if (!profile)
1031 return;
1032
1033 // Remember the ID of the Instant process to signal the renderer process
1034 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031035 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321036 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521037 InstantService* instant_service =
1038 InstantServiceFactory::GetForProfile(profile);
1039 if (instant_service)
1040 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1041 }
1042
[email protected]d5bcd06f2013-04-21 08:07:241043#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301044 // We only expect there to be one signin process as we use process-per-site
1045 // for signin URLs. The signin process will be cleared from SigninManager
1046 // when the renderer is destroyed.
1047 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1048 SigninManager* signin_manager =
1049 SigninManagerFactory::GetForProfile(profile);
1050 if (signin_manager)
1051 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
[email protected]1deace22013-05-22 06:14:461052 BrowserThread::PostTask(
1053 BrowserThread::IO, FROM_HERE,
1054 base::Bind(&ExtensionInfoMap::SetSigninProcess,
1055 extensions::ExtensionSystem::Get(profile)->info_map(),
1056 site_instance->GetProcess()->GetID()));
[email protected]970c63e2013-03-07 00:25:301057 }
[email protected]d5bcd06f2013-04-21 08:07:241058#endif
[email protected]970c63e2013-03-07 00:25:301059
[email protected]06bdd2b2012-11-30 18:47:131060 ExtensionService* service =
1061 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461062 if (!service)
1063 return;
1064
1065 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441066 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591067 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461068 if (!extension)
1069 return;
1070
[email protected]6bc04fd82011-12-04 02:29:351071 service->process_map()->Insert(extension->id(),
1072 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331073 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461074 BrowserThread::PostTask(
1075 BrowserThread::IO, FROM_HERE,
1076 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591077 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461078 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351079 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331080 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461081}
1082
1083void ChromeContentBrowserClient::SiteInstanceDeleting(
1084 SiteInstance* site_instance) {
1085 if (!site_instance->HasProcess())
1086 return;
1087
1088 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021089 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131090 ExtensionService* service =
1091 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461092 if (!service)
1093 return;
1094
1095 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441096 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591097 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461098 if (!extension)
1099 return;
1100
[email protected]6bc04fd82011-12-04 02:29:351101 service->process_map()->Remove(extension->id(),
1102 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331103 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461104 BrowserThread::PostTask(
1105 BrowserThread::IO, FROM_HERE,
1106 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591107 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461108 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351109 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331110 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461111}
1112
[email protected]f05763972012-06-06 18:17:261113bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141114 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081115 const GURL& current_url,
1116 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261117 if (current_url.is_empty()) {
1118 // Always choose a new process when navigating to extension URLs. The
1119 // process grouping logic will combine all of a given extension's pages
1120 // into the same process.
[email protected]885c0e92012-11-13 20:27:421121 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261122 return true;
[email protected]e3daf3c2011-10-05 21:17:081123
[email protected]f05763972012-06-06 18:17:261124 return false;
1125 }
1126
1127 // Also, we must switch if one is an extension and the other is not the exact
1128 // same extension.
[email protected]885c0e92012-11-13 20:27:421129 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1130 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261131 if (current_url.GetOrigin() != new_url.GetOrigin())
1132 return true;
1133 }
1134
[email protected]e9841fbd2013-02-22 23:12:141135 // The checks below only matter if we can retrieve which extensions are
1136 // installed.
1137 Profile* profile =
1138 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1139 ExtensionService* service =
1140 extensions::ExtensionSystem::Get(profile)->extension_service();
1141 if (!service)
1142 return false;
1143
1144 // We must swap if the URL is for an extension and we are not using an
1145 // extension process.
1146 const Extension* new_extension =
1147 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1148 // Ignore all hosted apps except the Chrome Web Store, since they do not
1149 // require their own BrowsingInstance (e.g., postMessage is ok).
1150 if (new_extension &&
1151 new_extension->is_hosted_app() &&
1152 new_extension->id() != extension_misc::kWebStoreAppId)
1153 new_extension = NULL;
1154 if (new_extension &&
1155 site_instance->HasProcess() &&
1156 !service->process_map()->Contains(new_extension->id(),
1157 site_instance->GetProcess()->GetID()))
1158 return true;
1159
[email protected]f05763972012-06-06 18:17:261160 return false;
[email protected]e3daf3c2011-10-05 21:17:081161}
1162
[email protected]395045c2012-05-22 15:04:381163bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1164 content::ResourceContext* resource_context, const GURL& current_url,
1165 const GURL& new_url) {
1166 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1167 return extensions::CrossesExtensionProcessBoundary(
1168 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171169 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381170}
1171
[email protected]763ec4ca2011-04-29 15:48:121172std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1173 const std::string& alias_name) {
1174 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1175}
1176
[email protected]b80f68432011-05-02 17:22:301177void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1178 CommandLine* command_line, int child_process_id) {
1179#if defined(USE_LINUX_BREAKPAD)
1180 if (IsCrashReporterEnabled()) {
1181 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1182 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1183 }
1184#elif defined(OS_MACOSX)
1185 if (IsCrashReporterEnabled()) {
1186 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1187 child_process_logging::GetClientId());
1188 }
1189#endif // OS_MACOSX
1190
[email protected]f1933792011-06-14 00:49:341191 if (logging::DialogsAreSuppressed())
1192 command_line->AppendSwitch(switches::kNoErrorDialogs);
1193
[email protected]b80f68432011-05-02 17:22:301194 std::string process_type =
1195 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171196 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321197
1198 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1199 command_line->AppendSwitch(switches::kChromeFrame);
1200
[email protected]718eab62011-10-05 21:16:521201 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451202 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301203 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1204 if (!user_data_dir.empty())
1205 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1206#if defined(OS_CHROMEOS)
1207 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441208 browser_command_line.GetSwitchValueASCII(
1209 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301210 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441211 command_line->AppendSwitchASCII(
1212 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301213#endif
1214
[email protected]f3b1a082011-11-18 00:34:301215 content::RenderProcessHost* process =
1216 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371217 if (process) {
1218 Profile* profile = Profile::FromBrowserContext(
1219 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131220 ExtensionService* extension_service =
1221 extensions::ExtensionSystem::Get(profile)->extension_service();
1222 if (extension_service) {
1223 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001224 if (process_map && process_map->Contains(process->GetID()))
1225 command_line->AppendSwitch(switches::kExtensionProcess);
1226 }
[email protected]b80f68432011-05-02 17:22:301227
[email protected]a8d851f82011-12-21 00:32:371228 PrefService* prefs = profile->GetPrefs();
1229 // Currently this pref is only registered if applied via a policy.
1230 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1231 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1232 // Turn this policy into a command line switch.
1233 command_line->AppendSwitch(switches::kDisable3DAPIs);
1234 }
[email protected]718eab62011-10-05 21:16:521235
[email protected]a8d851f82011-12-21 00:32:371236 // Disable client-side phishing detection in the renderer if it is
1237 // disabled in the Profile preferences or the browser process.
1238 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1239 !g_browser_process->safe_browsing_detection_service()) {
1240 command_line->AppendSwitch(
1241 switches::kDisableClientSidePhishingDetection);
1242 }
[email protected]0045b0f42012-07-26 11:52:081243
1244 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211245 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521246
1247 InstantService* instant_service =
1248 InstantServiceFactory::GetForProfile(profile);
1249 if (instant_service &&
1250 instant_service->IsInstantProcess(process->GetID()))
1251 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301252
[email protected]d5bcd06f2013-04-21 08:07:241253#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301254 SigninManager* signin_manager =
1255 SigninManagerFactory::GetForProfile(profile);
1256 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1257 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241258#endif
[email protected]47c7ec82012-01-18 03:29:211259 }
[email protected]4287a3d2011-06-13 23:56:511260
[email protected]87552982012-11-02 17:21:401261 if (content::IsThreadedCompositingEnabled())
1262 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1263
[email protected]16dc42452013-04-09 04:37:191264 if (message_center::IsRichNotificationEnabled())
1265 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]16dc42452013-04-09 04:37:191266
[email protected]47c7ec82012-01-18 03:29:211267 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511268 static const char* const kSwitchNames[] = {
[email protected]000f3ad2013-05-16 02:19:171269 autofill::switches::kDisableInteractiveAutocomplete,
[email protected]e217c5632013-04-12 19:11:481270 autofill::switches::kEnableExperimentalFormFilling,
[email protected]000f3ad2013-05-16 02:19:171271 autofill::switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511272 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481273 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511274 switches::kAllowScriptingGallery,
1275 switches::kAppsCheckoutURL,
1276 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311277 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511278 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501279 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531280 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111281 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531282 switches::kEnableAdview,
1283 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211284 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511285 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511286 switches::kEnableIPCFuzzing,
1287 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451288 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481289 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051290 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511291 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291292 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511293 switches::kMemoryProfiling,
1294 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371295 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371296 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511297 switches::kPpapiFlashArgs,
1298 switches::kPpapiFlashInProcess,
1299 switches::kPpapiFlashPath,
1300 switches::kPpapiFlashVersion,
1301 switches::kProfilingAtStart,
1302 switches::kProfilingFile,
1303 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371304 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511305 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291306 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381307 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511308 };
1309
1310 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1311 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171312 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381313 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351314 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381315 switches::kEnableExperimentalExtensionApis,
1316 switches::kWhitelistedExtensionID,
1317 };
1318
1319 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1320 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511321 } else if (process_type == switches::kPluginProcess) {
1322 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441323#if defined(OS_CHROMEOS)
1324 chromeos::switches::kLoginProfile,
1325#endif
[email protected]4287a3d2011-06-13 23:56:511326 switches::kMemoryProfiling,
1327 switches::kSilentDumpOnDCHECK,
1328 switches::kUserDataDir,
1329 };
1330
1331 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1332 arraysize(kSwitchNames));
1333 } else if (process_type == switches::kZygoteProcess) {
1334 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511335 switches::kUserDataDir, // Make logs go to the right file.
1336 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501337 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511338 switches::kPpapiFlashInProcess,
1339 switches::kPpapiFlashPath,
1340 switches::kPpapiFlashVersion,
1341 };
1342
1343 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1344 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111345 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001346 base::FilePath user_data_dir =
1347 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1348 if (!user_data_dir.empty())
1349 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111350 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1351 // because GPU is expected to be unreliable.
1352 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1353 !command_line->HasSwitch(switches::kDisableBreakpad))
1354 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301355 }
[email protected]6f08af82011-09-15 01:19:031356
1357 // The command line switch kEnableBenchmarking needs to be specified along
1358 // with the kEnableStatsTable switch to ensure that the stats table global
1359 // is initialized correctly.
1360 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1361 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301362}
1363
1364std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431365 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351366 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301367 return g_browser_process->GetApplicationLocale();
1368}
1369
[email protected]597a867b2011-11-18 18:31:201370std::string ChromeContentBrowserClient::GetAcceptLangs(
1371 content::BrowserContext* context) {
1372 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371373 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081374}
1375
[email protected]9ec0f452012-05-31 15:58:531376gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221377 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531378 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081379}
1380
[email protected]a2176792011-05-08 19:30:491381bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091382 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191383 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201384 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201386 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051387 return io_data->GetCookieSettings()->
1388 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491389}
1390
[email protected]ed24fad2011-05-10 22:44:011391bool ChromeContentBrowserClient::AllowGetCookie(
1392 const GURL& url,
1393 const GURL& first_party,
1394 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201395 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011396 int render_process_id,
1397 int render_view_id) {
1398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201399 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051400 bool allow = io_data->GetCookieSettings()->
1401 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011402
[email protected]8093a542011-05-13 07:29:321403 BrowserThread::PostTask(
1404 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031405 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431406 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011407 return allow;
1408}
1409
1410bool ChromeContentBrowserClient::AllowSetCookie(
1411 const GURL& url,
1412 const GURL& first_party,
1413 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201414 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011415 int render_process_id,
1416 int render_view_id,
1417 net::CookieOptions* options) {
1418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201419 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051420 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1421 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1422
[email protected]8093a542011-05-13 07:29:321423 BrowserThread::PostTask(
1424 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031425 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431426 render_view_id, url, first_party, cookie_line, *options,
1427 !allow));
[email protected]ed24fad2011-05-10 22:44:011428 return allow;
1429}
1430
[email protected]d5a19162011-06-30 18:51:541431bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201432 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541433 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201434 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431435 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1436 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261437
[email protected]bf510ed2012-06-05 08:31:431438 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1439 // Could we even support per-origin settings?
1440 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541441}
1442
[email protected]5c5a88e2011-11-12 00:45:351443bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351444 const GURL& url,
1445 const string16& name,
1446 const string16& display_name,
1447 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201448 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481449 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201451 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351452 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1453 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1454
[email protected]62151052012-02-01 18:40:481455 // Record access to database for potential display in UI.
1456 std::vector<std::pair<int, int> >::const_iterator i;
1457 for (i = render_views.begin(); i != render_views.end(); ++i) {
1458 BrowserThread::PostTask(
1459 BrowserThread::UI, FROM_HERE,
1460 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1461 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351462 }
1463
1464 return allow;
1465}
1466
1467bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351468 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201469 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481470 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201472 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351473 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1474 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1475
[email protected]62151052012-02-01 18:40:481476 // Record access to file system for potential display in UI.
1477 std::vector<std::pair<int, int> >::const_iterator i;
1478 for (i = render_views.begin(); i != render_views.end(); ++i) {
1479 BrowserThread::PostTask(
1480 BrowserThread::UI, FROM_HERE,
1481 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1482 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351483 }
1484
1485 return allow;
1486}
1487
[email protected]7c5ff9a2012-03-02 07:42:491488bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1489 const GURL& url,
1490 const string16& name,
1491 content::ResourceContext* context,
1492 const std::vector<std::pair<int, int> >& render_views) {
1493 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1494 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1495 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1496 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1497
1498 // Record access to IndexedDB for potential display in UI.
1499 std::vector<std::pair<int, int> >::const_iterator i;
1500 for (i = render_views.begin(); i != render_views.end(); ++i) {
1501 BrowserThread::PostTask(
1502 BrowserThread::UI, FROM_HERE,
1503 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1504 i->first, i->second, url, name, !allow));
1505 }
1506
1507 return allow;
1508}
1509
[email protected]6133f922011-07-01 21:34:341510net::URLRequestContext*
1511ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201512 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421514 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201515 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341516 return io_data->extensions_request_context();
1517 }
1518
1519 return NULL;
1520}
1521
[email protected]317f96c92011-05-31 06:53:411522QuotaPermissionContext*
1523ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1524 return new ChromeQuotaPermissionContext();
1525}
1526
[email protected]848dd042011-06-04 18:24:031527void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171528 int render_process_id,
1529 int render_view_id,
1530 int cert_error,
1531 const net::SSLInfo& ssl_info,
1532 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021533 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031534 bool overridable,
[email protected]d9be47702012-05-16 03:41:221535 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171536 const base::Callback<void(bool)>& callback,
1537 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021538 if (resource_type != ResourceType::MAIN_FRAME) {
1539 // A sub-resource has a certificate error. The user doesn't really
1540 // have a context for making the right decision, so block the
1541 // request hard, without an info bar to allow showing the insecure
1542 // content.
1543 *cancel_request = true;
1544 return;
1545 }
1546
[email protected]f9034cf2011-07-21 12:43:411547 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131548 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171549 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411550 if (!tab) {
1551 NOTREACHED();
1552 return;
1553 }
1554 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501555 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301556 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011557 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1558 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411559 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171560 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411561 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171562 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411563 return;
1564 }
1565 }
1566
[email protected]1e87df32012-09-12 04:53:191567#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231568 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1569 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1570 if (captive_portal_tab_helper)
1571 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191572#endif
1573
[email protected]f9034cf2011-07-21 12:43:411574 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221575 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1576 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031577}
1578
[email protected]c99c442e2011-08-24 11:37:301579void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451580 int render_process_id,
1581 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401582 const net::HttpNetworkSession* network_session,
1583 net::SSLCertRequestInfo* cert_request_info,
1584 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131585 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451586 render_process_id, render_view_id);
1587 if (!tab) {
1588 NOTREACHED();
1589 return;
1590 }
1591
[email protected]6786bf402011-12-03 15:19:451592 GURL requesting_url("https://" + cert_request_info->host_and_port);
1593 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1594 << cert_request_info->host_and_port;
1595
[email protected]627e0512011-12-21 22:55:301596 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451597 scoped_ptr<Value> filter(
1598 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1599 requesting_url,
1600 requesting_url,
1601 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1602 std::string(), NULL));
1603
1604 if (filter.get()) {
1605 // Try to automatically select a client certificate.
1606 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1607 DictionaryValue* filter_dict =
1608 static_cast<DictionaryValue*>(filter.get());
1609
1610 const std::vector<scoped_refptr<net::X509Certificate> >&
1611 all_client_certs = cert_request_info->client_certs;
1612 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1613 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1614 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401615 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451616 return;
1617 }
1618 }
1619 } else {
1620 NOTREACHED();
1621 }
1622 }
1623
[email protected]11feec322012-09-18 03:58:521624 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1625 if (!ssl_tab_helper) {
1626 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451627 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141628 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401629 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451630 return;
1631 }
[email protected]11feec322012-09-18 03:58:521632 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401633 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451634}
1635
[email protected]3b455502012-12-11 18:22:581636void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451637 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581638 net::CertificateMimeType cert_type,
1639 const void* cert_data,
1640 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451641 int render_process_id,
1642 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581643 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1644 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451645}
1646
[email protected]dc73a7b2012-03-25 15:27:181647content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561648 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181649}
1650
[email protected]941623e2011-06-07 23:06:041651void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1652 const GURL& source_origin,
1653 int callback_context,
1654 int render_process_id,
1655 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111656#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1658 WebContents* contents =
1659 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1660 if (!contents) {
[email protected]941623e2011-06-07 23:06:041661 NOTREACHED();
1662 return;
1663 }
1664
[email protected]d0d9c3ee2012-06-19 03:07:021665 // Skip showing the infobar if the request comes from an extension, and that
1666 // extension has the 'notify' permission. (If the extension does not have the
1667 // permission, the user will still be prompted.)
1668 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011669 ExtensionInfoMap* extension_info_map =
1670 extensions::ExtensionSystem::Get(profile)->info_map();
1671 DesktopNotificationService* notification_service =
1672 DesktopNotificationServiceFactory::GetForProfile(profile);
1673 const Extension* extension = NULL;
1674 if (extension_info_map) {
1675 ExtensionSet extensions;
1676 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1677 source_origin, render_process_id,
1678 extensions::APIPermission::kNotification, &extensions);
1679 for (ExtensionSet::const_iterator iter = extensions.begin();
1680 iter != extensions.end(); ++iter) {
1681 if (notification_service->IsExtensionEnabled((*iter)->id())) {
1682 extension = *iter;
1683 break;
1684 }
1685 }
1686 }
[email protected]eb4832a2012-12-08 01:57:521687 RenderViewHost* rvh =
1688 RenderViewHost::FromID(render_process_id, render_view_id);
1689 if (IsExtensionWithPermissionOrSuggestInConsole(
1690 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021691 if (rvh)
1692 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1693 return;
1694 }
1695
[email protected]c7cd5942013-04-30 03:31:011696 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021697 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111698#else
1699 NOTIMPLEMENTED();
1700#endif
[email protected]941623e2011-06-07 23:06:041701}
1702
1703WebKit::WebNotificationPresenter::Permission
1704 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021705 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201706 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021707 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111708#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041709 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201710 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041711
[email protected]c7cd5942013-04-30 03:31:011712 DesktopNotificationService* notification_service =
1713 io_data->GetNotificationService();
1714 if (notification_service) {
1715 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1716 ExtensionSet extensions;
1717 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1718 source_origin, render_process_id,
1719 extensions::APIPermission::kNotification, &extensions);
1720 for (ExtensionSet::const_iterator iter = extensions.begin();
1721 iter != extensions.end(); ++iter) {
1722 if (notification_service->IsExtensionEnabled((*iter)->id()))
1723 return WebKit::WebNotificationPresenter::PermissionAllowed;
1724 }
1725
1726 return notification_service->HasPermission(source_origin);
1727 }
1728
1729 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111730#else
1731 return WebKit::WebNotificationPresenter::PermissionAllowed;
1732#endif
[email protected]941623e2011-06-07 23:06:041733}
1734
1735void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171736 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041737 int render_process_id,
1738 int render_view_id,
1739 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111740#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041741 RenderViewHost* rvh = RenderViewHost::FromID(
1742 render_process_id, render_view_id);
1743 if (!rvh) {
1744 NOTREACHED();
1745 return;
1746 }
1747
[email protected]9f76c1e2012-03-05 15:15:581748 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301749 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041750 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371751 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041752 service->ShowDesktopNotification(
1753 params, render_process_id, render_view_id,
1754 worker ? DesktopNotificationService::WorkerNotification :
1755 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111756#else
1757 NOTIMPLEMENTED();
1758#endif
[email protected]941623e2011-06-07 23:06:041759}
1760
1761void ChromeContentBrowserClient::CancelDesktopNotification(
1762 int render_process_id,
1763 int render_view_id,
1764 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111765#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041766 RenderViewHost* rvh = RenderViewHost::FromID(
1767 render_process_id, render_view_id);
1768 if (!rvh) {
1769 NOTREACHED();
1770 return;
1771 }
1772
[email protected]9f76c1e2012-03-05 15:15:581773 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301774 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041775 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371776 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041777 service->CancelDesktopNotification(
1778 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111779#else
1780 NOTIMPLEMENTED();
1781#endif
[email protected]941623e2011-06-07 23:06:041782}
1783
[email protected]9f3fba52011-06-08 20:37:191784bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351785 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021786 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191787 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201788 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011789 int render_process_id,
1790 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191791 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011792
1793 *no_javascript_access = false;
1794
[email protected]9f3fba52011-06-08 20:37:191795 // If the opener is trying to create a background window but doesn't have
1796 // the appropriate permission, fail the attempt.
1797 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201798 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531799 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1800
[email protected]03b6d552012-03-29 04:03:011801 if (!map->SecurityOriginHasAPIPermission(
1802 source_origin,
1803 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061804 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011805 return false;
1806 }
1807
[email protected]7b54ca02012-03-02 18:06:531808 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1809 // return a recently installed Extension even if this CanCreateWindow call
1810 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011811 // because the permission check above would have caused an early return
1812 // already. We must use the full URL to find hosted apps, though, and not
1813 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531814 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351815 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291816 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011817 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191818 }
[email protected]056efdc2013-04-06 00:14:531819
1820 // No new browser window (popup or tab) in app mode.
1821 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1822 chrome::IsRunningInForcedAppMode()) {
1823 return false;
1824 }
1825
[email protected]9f3fba52011-06-08 20:37:191826 return true;
1827}
1828
1829std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201830 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191831 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1832 // Check if it's an extension-created worker, in which case we want to use
1833 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201834 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191835 const Extension* extension =
1836 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1837 return extension ? extension->name() : std::string();
1838}
1839
[email protected]99907362012-01-11 05:41:401840void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1841 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171842}
1843
[email protected]7a06d282013-05-03 04:39:331844// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021845content::SpeechRecognitionManagerDelegate*
1846 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321847#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021848 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321849#else
1850 return NULL;
1851#endif
[email protected]66cfec62012-02-24 17:57:511852}
1853
[email protected]ae6e9912011-07-27 01:18:281854net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1855 return g_browser_process->net_log();
1856}
1857
[email protected]32538d92011-08-25 00:09:231858AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1859 return new ChromeAccessTokenStore();
1860}
1861
[email protected]dbae6b02011-06-29 23:51:411862bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011863 return true;
[email protected]dbae6b02011-06-29 23:51:411864}
1865
[email protected]64d69de42012-02-06 00:19:541866void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321867 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061868 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581869 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061870 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061871
[email protected]f3986f82012-01-03 20:00:061872 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541873 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061874 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541875 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061876 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541877 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061878 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541879 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061880 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541881 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061882 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541883 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031884 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1885 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061886
[email protected]64d69de42012-02-06 00:19:541887 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401888 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541889 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401890 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541891 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401892 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541893 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401894 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061895
[email protected]ddf72142012-05-22 04:52:401896 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061897
[email protected]64d69de42012-02-06 00:19:541898 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401899 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541900 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061901 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541902 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061903 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1904 const DictionaryValue* inspector_settings =
1905 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1906 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181907 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1908 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061909 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181910 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541911 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181912 std::make_pair(iter.key(), value));
1913 }
[email protected]f3986f82012-01-03 20:00:061914 }
1915 }
[email protected]64d69de42012-02-06 00:19:541916 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061917
[email protected]ddf72142012-05-22 04:52:401918 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541919 web_prefs->javascript_enabled = false;
1920 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1921 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401922 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541923 web_prefs->plugins_enabled = false;
1924 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1925 web_prefs->java_enabled = false;
1926 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401927 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061928
[email protected]64d69de42012-02-06 00:19:541929 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1930 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061931
[email protected]64d69de42012-02-06 00:19:541932 web_prefs->memory_info_enabled =
1933 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1934 web_prefs->allow_displaying_insecure_content =
1935 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1936 web_prefs->allow_running_insecure_content =
1937 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321938#if defined(OS_ANDROID)
1939 web_prefs->font_scale_factor =
1940 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1941 web_prefs->force_enable_zoom =
1942 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451943#if defined(GOOGLE_TV)
1944 web_prefs->user_gesture_required_for_media_playback = false;
1945#endif
[email protected]d3b935f2012-10-19 23:14:321946#endif
[email protected]5c915252013-05-07 13:15:391947
[email protected]9d06d88d2012-02-23 22:37:081948 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]5c915252013-05-07 13:15:391949#if defined(OS_CHROMEOS)
1950 // Enable password echo during OOBE when keyboard driven flag is set.
1951 if (chromeos::UserManager::IsInitialized() &&
1952 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
1953 !chromeos::StartupUtils::IsOobeCompleted()) {
1954 bool keyboard_driven_oobe = false;
1955 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]e8f3f9982013-05-10 20:59:531956 chromeos::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:391957 if (keyboard_driven_oobe)
1958 web_prefs->password_echo_enabled = true;
1959 }
1960#endif
[email protected]f3986f82012-01-03 20:00:061961
[email protected]46f8e742013-05-03 18:37:141962#if defined(OS_ANDROID)
1963 web_prefs->user_style_sheet_enabled = false;
1964#else
[email protected]64d69de42012-02-06 00:19:541965 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151966 UserStyleSheetWatcher* user_style_sheet_watcher =
1967 UserStyleSheetWatcherFactory::GetForProfile(profile);
1968 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541969 web_prefs->user_style_sheet_enabled = true;
1970 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151971 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541972 } else {
1973 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061974 }
[email protected]46f8e742013-05-03 18:37:141975#endif
[email protected]f3986f82012-01-03 20:00:061976
[email protected]cfadadd2013-04-03 04:43:021977 web_prefs->asynchronous_spell_checking_enabled = true;
1978 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:571979
[email protected]64d69de42012-02-06 00:19:541980 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061981 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541982 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061983 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541984 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061985 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1986
1987 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541988 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061989 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541990 web_prefs->default_encoding);
1991 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401992 prefs->ClearPref(prefs::kDefaultCharset);
1993 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061994 }
[email protected]64d69de42012-02-06 00:19:541995 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061996
[email protected]88ecf66d2012-12-11 22:53:471997 if (content::IsForceCompositingModeEnabled())
1998 web_prefs->force_compositing_mode = true;
1999
[email protected]299d7f12012-05-23 05:31:152000 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:232001 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:132002 ExtensionService* service =
2003 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:062004 if (service) {
[email protected]1bc28312012-11-08 08:31:532005 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
2006 const Extension* extension = service->extensions()->GetByID(url.host());
2007 // Ensure that we are only granting extension preferences to URLs with
2008 // the correct scheme. Without this check, chrome-guest:// schemes used by
2009 // webview tags as well as hosts that happen to match the id of an
2010 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:422011 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:532012 extension_webkit_preferences::SetPreferences(
2013 extension, view_type, web_prefs);
2014 }
[email protected]f3986f82012-01-03 20:00:062015 }
2016
[email protected]cb2edf22013-04-01 20:25:232017 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:542018 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:232019 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:062020 // Disable all kinds of acceleration for background pages.
2021 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:542022 web_prefs->force_compositing_mode = false;
2023 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:062024 }
[email protected]2e21fe292012-03-02 22:52:322025
2026#if defined(FILE_MANAGER_EXTENSION)
2027 // Override the default of suppressing HW compositing for WebUI pages for the
2028 // file manager, which is implemented using WebUI but wants HW acceleration
2029 // for video decode & render.
2030 if (url.spec() == chrome::kChromeUIFileManagerURL) {
2031 web_prefs->accelerated_compositing_enabled = true;
2032 web_prefs->accelerated_2d_canvas_enabled = true;
2033 }
2034#endif
[email protected]181a95ee2011-07-12 19:26:362035}
2036
2037void ChromeContentBrowserClient::UpdateInspectorSetting(
2038 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062039 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582040 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062041 DictionaryPrefUpdate update(
2042 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2043 prefs::kWebKitInspectorSettings);
2044 DictionaryValue* inspector_settings = update.Get();
2045 inspector_settings->SetWithoutPathExpansion(key,
2046 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362047}
2048
[email protected]b8148ac2011-07-13 22:03:252049void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2050 BrowserURLHandler* handler) {
2051 // Add the default URL handlers.
2052 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2053 BrowserURLHandler::null_handler());
2054 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2055 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2056
[email protected]b3adbd02011-11-30 22:23:272057 // about: handler. Must come before chrome: handler, since it will
2058 // rewrite about: urls to chrome: URLs and then expect chrome: to
2059 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252060 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2061 BrowserURLHandler::null_handler());
2062 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242063 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252064}
2065
2066void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372067 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582068 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472069 BrowsingDataRemover* remover =
2070 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552071 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2072 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252073 // BrowsingDataRemover takes care of deleting itself when done.
2074}
2075
2076void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372077 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582078 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472079 BrowsingDataRemover* remover =
2080 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232081 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552082 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252083 // BrowsingDataRemover takes care of deleting itself when done.
2084}
2085
[email protected]650b2d52013-02-10 03:41:452086base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322087 return download_util::GetDefaultDownloadDirectory();
2088}
2089
[email protected]c9b6eb62011-10-18 20:49:392090std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2091 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2092}
2093
[email protected]b7631cc2012-09-15 05:08:382094void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2095 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542096#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382097 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2098 scoped_ptr<ppapi::host::HostFactory>(
2099 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542100#endif
[email protected]b7631cc2012-09-15 05:08:382101}
2102
[email protected]0c7193742012-11-07 19:05:032103content::BrowserPpapiHost*
2104 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2105 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132106 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032107 while (!iter.Done()) {
2108 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2109 if (host->process() &&
2110 host->process()->GetData().id == plugin_process_id) {
2111 // Found the plugin.
2112 return host->browser_ppapi_host();
2113 }
2114 ++iter;
2115 }
2116 return NULL;
2117}
2118
[email protected]7b38b192013-03-23 18:39:312119bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2120 content::BrowserContext* browser_context, const GURL& site_url) {
2121 if (CommandLine::ForCurrentProcess()->HasSwitch(
2122 switches::kEnableBrowserPluginForAllViewTypes))
2123 return true;
2124
2125 Profile* profile = Profile::FromBrowserContext(browser_context);
2126 ExtensionService* service =
2127 extensions::ExtensionSystem::Get(profile)->extension_service();
2128 if (!service)
2129 return false;
2130
2131 const Extension* extension = service->extensions()->
2132 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2133 if (!extension)
2134 return false;
2135
[email protected]c2d2f102013-04-29 16:42:582136 return extension->HasAPIPermission(APIPermission::kWebView) ||
2137 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312138}
2139
[email protected]38cd8f7f2012-06-15 22:06:072140bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582141 content::BrowserContext* browser_context,
2142 const GURL& url,
2143 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:292144 if (!url.is_valid())
2145 return false;
2146
2147 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:422148 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]b71313232013-05-06 06:16:292149 HostIsInSet(host, allowed_socket_origins_)) {
[email protected]a658d452012-03-02 12:45:292150 return true;
[email protected]885c0e92012-11-13 20:27:422151 }
[email protected]a658d452012-03-02 12:45:292152
[email protected]9a5940d2012-04-27 19:16:232153 Profile* profile = Profile::FromBrowserContext(browser_context);
2154 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:192155 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:132156 extensions::ExtensionSystem::Get(profile)->extension_service();
2157 if (extension_service) {
2158 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:232159 GetExtensionOrAppByURL(ExtensionURLInfo(url));
2160 }
2161
[email protected]b71313232013-05-06 06:16:292162 // Check the modules that are imported by this extension to see if any of them
2163 // is whitelisted.
2164 if (extension) {
2165 const std::vector<extensions::SharedModuleInfo::ImportInfo>& imports =
2166 extensions::SharedModuleInfo::GetImports(extension);
2167 std::vector<extensions::SharedModuleInfo::ImportInfo>::const_iterator it;
2168 for (it = imports.begin(); it != imports.end(); ++it) {
2169 const Extension* imported_extension = extension_service->
2170 GetExtensionById(it->extension_id, false);
2171 if (imported_extension &&
2172 extensions::SharedModuleInfo::IsSharedModule(imported_extension) &&
2173 HostIsInSet(it->extension_id, allowed_socket_origins_)) {
2174 return true;
2175 }
2176 }
2177 }
2178
[email protected]f237c0f2012-03-10 07:49:102179 // Need to check this now and not on construction because otherwise it won't
2180 // work with browser_tests.
2181 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2182 std::string allowed_list =
2183 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:232184 if (allowed_list == "*") {
2185 // The wildcard allows socket API only for packaged and platform apps.
2186 return extension &&
[email protected]1d5e58b2013-01-31 08:41:402187 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
2188 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:232189 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:392190 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:102191 while (t.GetNext()) {
2192 if (t.token() == host)
2193 return true;
2194 }
2195 }
2196
[email protected]a658d452012-03-02 12:45:292197 return false;
[email protected]e461da2f2012-02-16 19:06:402198}
2199
[email protected]650b2d52013-02-10 03:41:452200base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2201 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142202 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2203 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2204}
2205
[email protected]a28e3302013-02-03 03:50:432206ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2207 WebContents* web_contents) {
2208 return new ChromeSelectFilePolicy(web_contents);
2209}
2210
[email protected]7d9424702013-04-14 13:14:162211void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2212 std::vector<std::string>* additional_allowed_schemes) {
2213 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2214 additional_allowed_schemes);
2215 additional_allowed_schemes->push_back(kChromeUIScheme);
2216 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2217}
2218
[email protected]02250952013-04-24 23:52:532219void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2220 const base::FilePath& storage_partition_path,
2221 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2222#if !defined(OS_ANDROID)
2223 additional_providers->push_back(new MediaFileSystemMountPointProvider(
2224 storage_partition_path));
2225#endif
2226}
2227
[email protected]e60c0232011-11-11 19:56:352228#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182229void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2230 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382231 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082232 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392233#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452234 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392235 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2236 DCHECK(!data_path.empty());
2237
2238 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452239 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392240 base::PlatformFile f =
2241 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2242 DCHECK(f != base::kInvalidPlatformFileValue);
2243 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2244 FileDescriptor(f, true)));
2245
[email protected]650b2d52013-02-10 03:41:452246 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392247 data_path.AppendASCII("chrome_100_percent.pak");
2248 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2249 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372250 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392251 FileDescriptor(f, true)));
2252
2253 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452254 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392255 GetLocaleFilePath(locale, false);
2256 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2257 DCHECK(f != base::kInvalidPlatformFileValue);
2258 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2259 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382260
[email protected]650b2d52013-02-10 03:41:452261 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372262 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2263 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2264 DCHECK(f != base::kInvalidPlatformFileValue);
2265 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2266 FileDescriptor(f, true)));
2267
[email protected]40da3e0c2012-10-24 22:03:382268#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432269 if (IsCrashReporterEnabled()) {
2270 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2271 if (f == base::kInvalidPlatformFileValue) {
2272 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2273 "be disabled for this process.";
2274 } else {
2275 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2276 FileDescriptor(f, true)));
2277 }
[email protected]40da3e0c2012-10-24 22:03:382278 }
2279#endif // defined(USE_LINUX_BREAKPAD)
2280
2281#else
2282 int crash_signal_fd = GetCrashSignalFD(command_line);
2283 if (crash_signal_fd >= 0) {
2284 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2285 FileDescriptor(crash_signal_fd,
2286 false)));
2287 }
[email protected]29699c22012-10-03 23:57:392288#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302289}
[email protected]e60c0232011-11-11 19:56:352290#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302291
[email protected]4a65826d2011-08-25 16:04:012292#if defined(OS_WIN)
2293const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2294 return chrome::kBrowserResourcesDll;
2295}
[email protected]34f48682013-03-20 00:30:182296
2297void ChromeContentBrowserClient::PreSpawnRenderer(
2298 sandbox::TargetPolicy* policy,
2299 bool* success) {
2300 // This code is duplicated in nacl_exe_win_64.cc.
2301 // Allow the server side of a pipe restricted to the "chrome.nacl."
2302 // namespace so that it cannot impersonate other system or other chrome
2303 // service pipes.
2304 sandbox::ResultCode result = policy->AddRule(
2305 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2306 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2307 L"\\\\.\\pipe\\chrome.nacl.*");
2308 if (result != sandbox::SBOX_ALL_OK) {
2309 *success = false;
2310 return;
2311 }
2312
2313 // Renderers need to send named pipe handles and shared memory
2314 // segment handles to NaCl loader processes.
2315 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2316 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2317 L"File");
2318 if (result != sandbox::SBOX_ALL_OK) {
2319 *success = false;
2320 return;
2321 }
2322}
[email protected]4a65826d2011-08-25 16:04:012323#endif
2324
[email protected]37a72af2011-06-13 05:42:012325#if defined(USE_NSS)
2326crypto::CryptoModuleBlockingPasswordDelegate*
2327 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2328 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292329 return chrome::NewCryptoModuleBlockingDialogDelegate(
2330 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012331}
2332#endif
2333
[email protected]d977f9c2011-03-14 16:10:262334} // namespace chrome