blob: 2c7b4b2b7676e24a317239bd6f98465e2a77be6a [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]24665682013-02-25 20:59:3835#include "chrome/browser/extensions/activity_log.h"
[email protected]2b33dcd02012-03-18 01:34:1636#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0637#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0438#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3339#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2640#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0841#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2542#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0643#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]eb4832a2012-12-08 01:57:5244#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2345#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1246#include "chrome/browser/google/google_util.h"
[email protected]11158e2d2013-02-01 02:31:5647#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]95132f52013-04-12 02:19:0448#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
[email protected]0c7193742012-11-07 19:05:0349#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2850#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0451#include "chrome/browser/notifications/desktop_notification_service.h"
52#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4253#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5654#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0655#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4156#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5057#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0758#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4159#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1460#include "chrome/browser/printing/printing_message_filter.h"
61#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3262#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0663#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1464#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]b7631cc2012-09-15 05:08:3865#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]a7b8e43d2013-03-18 18:52:4366#include "chrome/browser/search/instant_service.h"
67#include "chrome/browser/search/instant_service_factory.h"
68#include "chrome/browser/search/search.h"
[email protected]05fcf982011-04-19 00:44:1469#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0270#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]7a06d282013-05-03 04:39:3371#include "chrome/browser/speech/tts_message_filter.h"
[email protected]8ec71262011-07-28 08:12:4672#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5873#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0374#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5275#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4576#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5477#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4378#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]b5d73422012-06-02 23:46:4479#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5080#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]970c63e2013-03-07 00:25:3081#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
[email protected]f3986f82012-01-03 20:00:0682#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1583#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]1352ca92013-04-30 02:30:2784#include "chrome/browser/validation_message_message_filter.h"
[email protected]b80f68432011-05-02 17:22:3085#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0186#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1487#include "chrome/common/chrome_paths.h"
[email protected]f3b357692013-03-22 05:16:1388#include "chrome/common/chrome_process_type.h"
[email protected]b80f68432011-05-02 17:22:3089#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2990#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0491#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3892#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4493#include "chrome/common/extensions/extension_set.h"
[email protected]561e33d52013-04-03 06:58:4394#include "chrome/common/extensions/manifest_handlers/app_isolation_info.h"
[email protected]b71313232013-05-06 06:16:2995#include "chrome/common/extensions/manifest_handlers/shared_module_info.h"
[email protected]157cc902012-11-02 06:31:5896#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3497#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1298#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3899#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:09100#include "chrome/common/url_constants.h"
[email protected]e8f3f9982013-05-10 20:59:53101#include "chromeos/chromeos_constants.h"
[email protected]75fee372013-03-06 00:42:44102#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:43103#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:30104#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:38105#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:31106#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03107#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59108#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36109#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30110#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33111#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05112#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33113#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19114#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10115#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43116#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18117#include "content/public/common/content_descriptors.h"
[email protected]cb2edf22013-04-01 20:25:23118#include "extensions/browser/view_type_utils.h"
[email protected]885c0e92012-11-13 20:27:42119#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39120#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23121#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53122#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58123#include "net/base/mime_util.h"
[email protected]5b9bc352012-07-18 13:13:34124#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06125#include "net/cookies/cookie_options.h"
[email protected]536fd0b2013-03-14 17:41:57126#include "net/ssl/ssl_cert_request_info.h"
[email protected]b7631cc2012-09-15 05:08:38127#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39128#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08129#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36130#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04131#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26132
[email protected]b48c9182011-10-26 18:03:30133#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38134#include "chrome/browser/chrome_browser_main_win.h"
[email protected]34f48682013-03-20 00:30:18135#include "sandbox/win/src/sandbox_policy.h"
[email protected]199fc7a2011-09-28 22:45:38136#elif defined(OS_MACOSX)
137#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56138#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30139#elif defined(OS_CHROMEOS)
140#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]5c915252013-05-07 13:15:39141#include "chrome/browser/chromeos/login/startup_utils.h"
[email protected]fe69558d2012-03-12 11:34:49142#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]5c915252013-05-07 13:15:39143#include "chrome/browser/chromeos/system/statistics_provider.h"
[email protected]931d1042013-04-05 17:50:44144#include "chromeos/chromeos_switches.h"
[email protected]81ce2c42012-03-24 01:43:26145#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30146#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09147#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38148#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09149#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39150#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30151#elif defined(OS_POSIX)
152#include "chrome/browser/chrome_browser_main_posix.h"
153#endif
154
[email protected]6653c192012-04-10 22:52:44155#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30156#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12157#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43158#endif
[email protected]b80f68432011-05-02 17:22:30159
[email protected]1e87df32012-09-12 04:53:19160#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
161#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
162#endif
163
[email protected]16dc42452013-04-09 04:37:19164#if defined(ENABLE_MESSAGE_CENTER)
165#include "ui/message_center/message_center_util.h"
166#endif
167
[email protected]29699c22012-10-03 23:57:39168#if defined(OS_ANDROID)
169#include "ui/base/ui_base_paths.h"
170#endif
171
[email protected]37a72af2011-06-13 05:42:01172#if defined(USE_NSS)
173#include "chrome/browser/ui/crypto_module_password_dialog.h"
174#endif
175
[email protected]d5bcd06f2013-04-21 08:07:24176#if !defined(OS_CHROMEOS)
177#include "chrome/browser/signin/signin_manager.h"
178#include "chrome/browser/signin/signin_manager_factory.h"
179#endif
180
[email protected]02250952013-04-24 23:52:53181#if !defined(OS_ANDROID)
182#include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_provider.h"
183#endif
184
[email protected]c7abd422012-09-25 00:20:08185using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47186using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03187using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39188using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31189using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59190using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08191using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00192using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11193using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33194using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13195using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06196using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34197using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40198using extensions::Manifest;
[email protected]631bb742011-11-02 11:29:39199
[email protected]c5dbef02011-05-13 05:06:09200namespace {
201
[email protected]eabbfb12013-04-05 23:28:35202// Cached version of the locale so we can return the locale on the I/O
203// thread.
204base::LazyInstance<std::string> g_io_thread_application_locale;
205
[email protected]e461da2f2012-02-16 19:06:40206const char* kPredefinedAllowedSocketOrigins[] = {
207 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18208 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45209 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
210 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
211 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
212 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35213 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54214 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
215 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
216 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
217 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
218 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
219 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38220 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58221 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
[email protected]b71313232013-05-06 06:16:29222 "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080
223 "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789
224 "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084
225 "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084
226 "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084
[email protected]e461da2f2012-02-16 19:06:40227};
228
[email protected]f8f93eb2012-09-25 03:06:24229// Returns a copy of the given url with its host set to given host and path set
230// to given path. Other parts of the url will be the same.
231GURL ReplaceURLHostAndPath(const GURL& url,
232 const std::string& host,
233 const std::string& path) {
234 url_canon::Replacements<char> replacements;
235 replacements.SetHost(host.c_str(),
236 url_parse::Component(0, host.length()));
237 replacements.SetPath(path.c_str(),
238 url_parse::Component(0, path.length()));
239 return url.ReplaceComponents(replacements);
240}
241
242// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
243GURL AddUberHost(const GURL& url) {
244 const std::string uber_host = chrome::kChromeUIUberHost;
245 const std::string new_path = url.host() + url.path();
246
247 return ReplaceURLHostAndPath(url, uber_host, new_path);
248}
249
[email protected]045bf7c2012-09-28 20:27:36250// If url->host() is "chrome" and url->path() has characters other than the
251// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
252// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24253bool RemoveUberHost(GURL* url) {
254 if (url->host() != chrome::kChromeUIUberHost)
255 return false;
256
[email protected]045bf7c2012-09-28 20:27:36257 if (url->path().empty() || url->path() == "/")
258 return false;
259
[email protected]f8f93eb2012-09-25 03:06:24260 const std::string old_path = url->path();
261
262 const std::string::size_type separator = old_path.find('/', 1);
263 std::string new_host;
264 std::string new_path;
265 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36266 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24267 } else {
268 new_host = old_path.substr(1, separator - 1);
269 new_path = old_path.substr(separator);
270 }
271
272 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
273
274 return true;
275}
276
[email protected]b8148ac2011-07-13 22:03:25277// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42278bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24279 // Do not handle special URLs such as "about:foo"
280 if (!url->host().empty()) {
281 const GURL chrome_url = AddUberHost(*url);
282
283 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
284 // be called.
285 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
286 browser_context, chrome_url))
287 return true;
288 }
289
[email protected]863f70a2012-01-27 02:05:50290 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
291 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25292 return false;
293
[email protected]fe69558d2012-03-12 11:34:49294#if defined(OS_CHROMEOS)
295 // Special case : in ChromeOS in Guest mode bookmarks and history are
296 // disabled for security reasons. New tab page explains the reasons, so
297 // we redirect user to new tab page.
298 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
299 if (url->SchemeIs(chrome::kChromeUIScheme) &&
300 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
301 url->DomainIs(chrome::kChromeUIHistoryHost))) {
302 // Rewrite with new tab URL
303 *url = GURL(chrome::kChromeUINewTabURL);
304 }
305 }
306#endif
307
[email protected]b8148ac2011-07-13 22:03:25308 // Special case the new tab page. In older versions of Chrome, the new tab
309 // page was hosted at chrome-internal:<blah>. This might be in people's saved
310 // sessions or bookmarks, so we say any URL with that scheme triggers the new
311 // tab page.
312 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
313 // Rewrite it with the proper new tab URL.
314 *url = GURL(chrome::kChromeUINewTabURL);
315 }
316
317 return true;
318}
319
[email protected]f8f93eb2012-09-25 03:06:24320// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
321// "chrome://foo/".
322bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
323 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
324 return false;
325
326 return RemoveUberHost(url);
327}
328
[email protected]8d3132f62011-10-12 07:13:42329// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
330// below. Extension, and isolated apps require different privileges to be
331// granted to their RenderProcessHosts. This classification allows us to make
332// sure URLs are served by hosts with the right set of privileges.
333enum RenderProcessHostPrivilege {
334 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45335 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42336 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45337 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42338};
339
340RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
341 const GURL& url,
342 ExtensionService* service) {
343 // Default to a normal renderer cause it is lower privileged. This should only
344 // occur if the URL on a site instance is either malformed, or uninitialized.
345 // If it is malformed, then there is no need for better privileges anyways.
346 // If it is uninitialized, but eventually settles on being an a scheme other
347 // than normal webrenderer, the navigation logic will correct us out of band
348 // anyways.
349 if (!url.is_valid())
350 return PRIV_NORMAL;
351
[email protected]885c0e92012-11-13 20:27:42352 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44353 const Extension* extension =
354 service->extensions()->GetByID(url.host());
[email protected]561e33d52013-04-03 06:58:43355 if (extension &&
356 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42357 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45358 if (extension && extension->is_hosted_app())
359 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42360
361 return PRIV_EXTENSION;
362 }
363
364 return PRIV_NORMAL;
365}
366
367RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30368 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46369 extensions::ProcessMap* process_map,
370 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46371 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30372 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46373 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21374 return PRIV_NORMAL;
375
[email protected]6f371442011-11-09 06:45:46376 for (std::set<std::string>::iterator iter = extension_ids.begin();
377 iter != extension_ids.end(); ++iter) {
378 const Extension* extension = service->GetExtensionById(*iter, false);
[email protected]561e33d52013-04-03 06:58:43379 if (extension &&
380 extensions::AppIsolationInfo::HasIsolatedStorage(extension))
[email protected]8d3132f62011-10-12 07:13:42381 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45382 if (extension && extension->is_hosted_app())
383 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42384 }
385
[email protected]676f6ab2011-10-19 20:23:21386 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42387}
388
[email protected]6786bf402011-12-03 15:19:45389bool CertMatchesFilter(const net::X509Certificate& cert,
390 const base::DictionaryValue& filter) {
391 // TODO(markusheintz): This is the minimal required filter implementation.
392 // Implement a better matcher.
393
394 // An empty filter matches any client certificate since no requirements are
395 // specified at all.
396 if (filter.empty())
397 return true;
398
399 std::string common_name;
400 if (filter.GetString("ISSUER.CN", &common_name) &&
401 (cert.issuer().common_name == common_name)) {
402 return true;
403 }
404 return false;
405}
406
[email protected]f3986f82012-01-03 20:00:06407// Fills |map| with the per-script font prefs under path |map_name|.
408void FillFontFamilyMap(const PrefService* prefs,
409 const char* map_name,
[email protected]3184f90b2013-05-01 18:17:53410 webkit_glue::ScriptFontFamilyMap* map) {
[email protected]f3986f82012-01-03 20:00:06411 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
412 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
413 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
414 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23415 if (!font_family.empty())
416 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06417 }
418}
419
[email protected]a1733df2012-06-22 11:24:18420#if defined(OS_POSIX) && !defined(OS_MACOSX)
421int GetCrashSignalFD(const CommandLine& command_line) {
422 if (command_line.HasSwitch(switches::kExtensionProcess)) {
423 ExtensionCrashHandlerHostLinux* crash_handler =
424 ExtensionCrashHandlerHostLinux::GetInstance();
425 return crash_handler->GetDeathSignalSocket();
426 }
427
428 std::string process_type =
429 command_line.GetSwitchValueASCII(switches::kProcessType);
430
431 if (process_type == switches::kRendererProcess)
432 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
433
434 if (process_type == switches::kPluginProcess)
435 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
436
437 if (process_type == switches::kPpapiPluginProcess)
438 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
439
440 if (process_type == switches::kGpuProcess)
441 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
442
443 return -1;
444}
445#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
446
[email protected]d5bcd06f2013-04-21 08:07:24447#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30448GURL GetEffectiveURLForSignin(const GURL& url) {
449 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
450
451 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
[email protected]fab8bbed42013-03-07 01:13:03452 // Copy the path because the argument to SetPathStr must outlive
453 // the Replacements object.
454 const std::string path_copy(url.path());
[email protected]970c63e2013-03-07 00:25:30455 GURL::Replacements replacements;
[email protected]fab8bbed42013-03-07 01:13:03456 replacements.SetPathStr(path_copy);
[email protected]970c63e2013-03-07 00:25:30457 effective_url = effective_url.ReplaceComponents(replacements);
458 return effective_url;
459}
[email protected]d5bcd06f2013-04-21 08:07:24460#endif
[email protected]970c63e2013-03-07 00:25:30461
[email protected]eabbfb12013-04-05 23:28:35462void SetApplicationLocaleOnIOThread(const std::string& locale) {
463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
464 g_io_thread_application_locale.Get() = locale;
465}
466
[email protected]b71313232013-05-06 06:16:29467std::string HashHost(const std::string& host) {
468 const std::string id_hash = base::SHA1HashString(host);
469 DCHECK(id_hash.length() == base::kSHA1Length);
470 return base::HexEncode(id_hash.c_str(), id_hash.length());
471}
472
473bool HostIsInSet(const std::string& host, const std::set<std::string>& set) {
474 return set.count(host) > 0 || set.count(HashHost(host)) > 0;
475}
476
[email protected]9dbfff12011-07-01 19:37:07477} // namespace
[email protected]c5dbef02011-05-13 05:06:09478
[email protected]d977f9c2011-03-14 16:10:26479namespace chrome {
480
[email protected]e461da2f2012-02-16 19:06:40481ChromeContentBrowserClient::ChromeContentBrowserClient() {
482 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
483 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40484}
485
486ChromeContentBrowserClient::~ChromeContentBrowserClient() {
487}
488
[email protected]bca18382012-06-25 19:15:23489// static
[email protected]c753f142013-02-10 13:14:04490void ChromeContentBrowserClient::RegisterUserPrefs(
[email protected]443e9312013-05-06 06:17:34491 user_prefs::PrefRegistrySyncable* registry) {
492 registry->RegisterBooleanPref(
493 prefs::kDisable3DAPIs,
494 false,
495 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
496 registry->RegisterBooleanPref(
497 prefs::kEnableHyperlinkAuditing,
498 true,
499 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
500 registry->RegisterBooleanPref(
501 prefs::kEnableMemoryInfo,
502 false,
503 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23504}
505
[email protected]eabbfb12013-04-05 23:28:35506// static
507void ChromeContentBrowserClient::SetApplicationLocale(
508 const std::string& locale) {
509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
510
511 // This object is guaranteed to outlive all threads so we don't have to
512 // worry about the lack of refcounting and can just post as Unretained.
513 //
514 // The common case is that this function is called early in Chrome startup
515 // before any threads are created (it will also be called later if the user
516 // changes the pref). In this case, there will be no threads created and
517 // posting will fail. When there are no threads, we can just set the string
518 // without worrying about threadsafety.
519 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
520 base::Bind(&SetApplicationLocaleOnIOThread, locale))) {
521 g_io_thread_application_locale.Get() = locale;
522 }
523}
524
[email protected]50462bf02011-11-21 19:13:31525content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
526 const content::MainFunctionParams& parameters) {
527 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30528 // Construct the Main browser parts based on the OS type.
529#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31530 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04531#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31532 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30533#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22534 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26535#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31536 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14537#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09538 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30539#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31540 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04541#else
[email protected]b48c9182011-10-26 18:03:30542 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31543 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30544#endif
545
[email protected]c7480942011-11-08 19:18:27546 // Construct additional browser parts. Stages are called in the order in
547 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22548#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41549 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04550#endif
[email protected]c7480942011-11-08 19:18:27551
552#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41553 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27554#endif
555
[email protected]dc04be7c2012-03-15 23:57:49556#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41557 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49558#endif
559
[email protected]e050ef142012-03-21 01:04:24560#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41561 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24562#endif
563
[email protected]95132f52013-04-12 02:19:04564 chrome::AddMetricsExtraParts(main_parts);
565
[email protected]50462bf02011-11-21 19:13:31566 return main_parts;
[email protected]f967b722011-09-07 00:58:04567}
568
[email protected]e94bbcb2012-09-07 05:33:57569std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19570 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57571 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53572 std::string partition_id;
573
574 // The partition ID for webview guest processes is the string value of its
575 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
576 if (site.SchemeIs(chrome::kGuestScheme))
577 partition_id = site.spec();
578
[email protected]056efdc2013-04-06 00:14:53579 DCHECK(IsValidStoragePartitionId(browser_context, partition_id));
[email protected]1bc28312012-11-08 08:31:53580 return partition_id;
581}
582
583bool ChromeContentBrowserClient::IsValidStoragePartitionId(
584 content::BrowserContext* browser_context,
585 const std::string& partition_id) {
586 // The default ID is empty and is always valid.
587 if (partition_id.empty())
588 return true;
589
590 return GURL(partition_id).is_valid();
591}
592
593void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
594 content::BrowserContext* browser_context,
595 const GURL& site,
[email protected]14acc642012-11-17 12:20:10596 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53597 std::string* partition_domain,
598 std::string* partition_name,
599 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10600 // Default to the browser-wide storage partition and override based on |site|
601 // below.
602 partition_domain->clear();
603 partition_name->clear();
604 *in_memory = false;
605
[email protected]1bc28312012-11-08 08:31:53606 // For the webview tag, we create special guest processes, which host the
607 // tag content separately from the main application that embeds the tag.
608 // A webview tag can specify both the partition name and whether the storage
609 // for that partition should be persisted. Each tag gets a SiteInstance with
610 // a specially formatted URL, based on the application it is hosted by and
611 // the partition requested by it. The format for that URL is:
612 // chrome-guest://partition_domain/persist?partition_name
613 if (site.SchemeIs(chrome::kGuestScheme)) {
614 // Since guest URLs are only used for packaged apps, there must be an app
615 // id in the URL.
616 CHECK(site.has_host());
617 *partition_domain = site.host();
618 // Since persistence is optional, the path must either be empty or the
619 // literal string.
620 *in_memory = (site.path() != "/persist");
621 // The partition name is user supplied value, which we have encoded when the
622 // URL was created, so it needs to be decoded.
623 *partition_name = net::UnescapeURLComponent(site.query(),
624 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10625 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
626 // If |can_be_default| is false, the caller is stating that the |site|
627 // should be parsed as if it had isolated storage. In particular it is
628 // important to NOT check ExtensionService for the is_storage_isolated()
629 // attribute because this code path is run during Extension uninstall
630 // to do cleanup after the Extension has already been unloaded from the
631 // ExtensionService.
632 bool is_isolated = !can_be_default;
633 if (can_be_default) {
634 const Extension* extension = NULL;
635 Profile* profile = Profile::FromBrowserContext(browser_context);
636 ExtensionService* extension_service =
637 extensions::ExtensionSystem::Get(profile)->extension_service();
638 if (extension_service) {
639 extension = extension_service->extensions()->
640 GetExtensionOrAppByURL(ExtensionURLInfo(site));
[email protected]561e33d52013-04-03 06:58:43641 if (extension &&
642 extensions::AppIsolationInfo::HasIsolatedStorage(extension)) {
[email protected]14acc642012-11-17 12:20:10643 is_isolated = true;
644 }
645 }
646 }
[email protected]1bc28312012-11-08 08:31:53647
[email protected]14acc642012-11-17 12:20:10648 if (is_isolated) {
649 CHECK(site.has_host());
650 // For extensions with isolated storage, the the host of the |site| is
651 // the |partition_domain|. The |in_memory| and |partition_name| are only
652 // used in guest schemes so they are cleared here.
653 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53654 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10655 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53656 }
[email protected]d1198fd2012-08-13 22:50:19657 }
658
[email protected]14acc642012-11-17 12:20:10659 // Assert that if |can_be_default| is false, the code above must have found a
660 // non-default partition. If this fails, the caller has a serious logic
661 // error about which StoragePartition they expect to be in and it is not
662 // safe to continue.
663 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44664}
665
[email protected]38b098f2012-03-14 21:11:57666content::WebContentsViewDelegate*
667 ChromeContentBrowserClient::GetWebContentsViewDelegate(
668 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27669 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32670}
671
[email protected]24665682013-02-25 20:59:38672// Check if the extension activity log is enabled for the profile.
673static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
674 extensions::ActivityLog* activity_log =
675 extensions::ActivityLog::GetInstance(profile);
676 return activity_log->IsLogEnabled();
677}
678
[email protected]44703cc72013-01-24 04:56:06679void ChromeContentBrowserClient::GuestWebContentsCreated(
680 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
681 Profile* profile = Profile::FromBrowserContext(
682 embedder_web_contents->GetBrowserContext());
683 ExtensionService* service =
684 extensions::ExtensionSystem::Get(profile)->extension_service();
685 if (!service)
686 return;
687 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
688 const Extension* extension = service->extensions()->
689 GetExtensionOrAppByURL(ExtensionURLInfo(url));
690 if (!extension)
691 return;
692 std::vector<ExtensionMsg_Loaded_Params> extensions;
693 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
694 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
695}
696
[email protected]f3b1a082011-11-18 00:34:30697void ChromeContentBrowserClient::RenderProcessHostCreated(
698 content::RenderProcessHost* host) {
699 int id = host->GetID();
700 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41701 net::URLRequestContextGetter* context =
702 profile->GetRequestContextForRenderProcess(id);
703
[email protected]f3b1a082011-11-18 00:34:30704 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41705 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55706#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30707 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55708#endif
[email protected]658677f2012-06-09 06:04:02709#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08710 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03711#endif
[email protected]f3b1a082011-11-18 00:34:30712 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02713 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30714 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56715#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21716 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56717#endif
[email protected]43535512013-02-20 20:41:41718 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
719 id, profile, context));
[email protected]2736c032012-05-11 18:06:07720 host->GetChannel()->AddFilter(
721 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27722 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33723#if !defined(OS_ANDROID)
724 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
725#endif
[email protected]3e69bc82011-05-26 23:22:38726
[email protected]2ccf45c2011-08-19 23:35:50727 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
728 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07729
[email protected]24665682013-02-25 20:59:38730 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
731 IsExtensionActivityLogEnabledForProfile(profile)));
732
[email protected]39a5b532011-10-22 01:47:07733 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56734
735 RendererContentSettingRules rules;
736 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
737 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14738}
739
[email protected]95c95552013-05-03 04:21:22740GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
741 content::BrowserContext* browser_context,
742 const GURL& url,
743 bool is_renderer_initiated,
744 content::SiteInstance* current_instance) {
745 Profile* profile = Profile::FromBrowserContext(browser_context);
746 if (!profile)
747 return url;
748
749 // Only return the privileged instant URL if we are entering from a browser-
750 // initiated navigation or if we are already in the instant process.
751 bool is_instant_process = false;
752 int process_id = current_instance->GetProcess()->GetID();
753 InstantService* instant_service =
754 InstantServiceFactory::GetForProfile(profile);
755 if (instant_service)
756 is_instant_process = instant_service->IsInstantProcess(process_id);
757
758 DCHECK_EQ(is_instant_process,
759 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
760 if (!is_renderer_initiated || is_instant_process) {
761 // If the input |url| should be assigned to the Instant renderer, make its
762 // privileged URL distinct from other URLs on the search provider's domain.
763 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
764 return chrome::GetPrivilegedURLForInstant(url, profile);
765 }
766
767 return url;
768}
769
[email protected]3d7474ff2011-07-27 17:47:37770GURL ChromeContentBrowserClient::GetEffectiveURL(
771 content::BrowserContext* browser_context, const GURL& url) {
772 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52773 if (!profile)
774 return url;
775
[email protected]d5bcd06f2013-04-21 08:07:24776#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30777 // If the input |url| should be assigned to the Signin renderer, make its
778 // effective URL distinct from other URLs on the signin service's domain.
779 // Note that the signin renderer will be allowed to sign the user in to
780 // Chrome.
781 if (SigninManager::IsWebBasedSigninFlowURL(url))
782 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24783#endif
[email protected]970c63e2013-03-07 00:25:30784
[email protected]c5dec6292013-01-25 04:54:52785 // If the input |url| is part of an installed app, the effective URL is an
786 // extension URL with the ID of that extension as the host. This has the
787 // effect of grouping apps together in a common SiteInstance.
788 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13789 extensions::ExtensionSystem::Get(profile)->extension_service();
790 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08791 return url;
792
[email protected]06bdd2b2012-11-30 18:47:13793 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44794 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08795 if (!extension)
796 return url;
797
[email protected]15877ca2011-11-18 22:40:52798 // Bookmark apps do not use the hosted app process model, and should be
799 // treated as normal URLs.
800 if (extension->from_bookmark())
801 return url;
802
[email protected]36fb2c7c2011-04-04 15:49:08803 // If the URL is part of an extension's web extent, convert it to an
804 // extension URL.
805 return extension->GetResourceURL(url.path());
806}
807
[email protected]056ad2a2011-07-12 02:13:55808bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37809 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52810 // Non-extension, non-Instant URLs should generally use
811 // process-per-site-instance. Because we expect to use the effective URL,
812 // URLs for hosted apps (apart from bookmark apps) should have an extension
813 // scheme by now.
814
815 Profile* profile = Profile::FromBrowserContext(browser_context);
816 if (!profile)
817 return false;
818
[email protected]165fe422013-03-27 06:34:03819 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52820 return true;
821
[email protected]d5bcd06f2013-04-21 08:07:24822#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30823 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
824 return true;
[email protected]d5bcd06f2013-04-21 08:07:24825#endif
[email protected]970c63e2013-03-07 00:25:30826
[email protected]885c0e92012-11-13 20:27:42827 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55828 return false;
829
[email protected]c5dec6292013-01-25 04:54:52830 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13831 extensions::ExtensionSystem::Get(profile)->extension_service();
832 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55833 return false;
834
[email protected]06bdd2b2012-11-30 18:47:13835 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44836 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55837 if (!extension)
838 return false;
839
840 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53841 // permission, or that does not allow JavaScript access to the background
842 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55843 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40844 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06845 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29846 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53847 return false;
848 }
849 }
[email protected]056ad2a2011-07-12 02:13:55850
[email protected]7b54ca02012-03-02 18:06:53851 // Hosted apps that have script access to their background page must use
852 // process per site, since all instances can make synchronous calls to the
853 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55854 return true;
855}
856
[email protected]672c8c12013-03-07 12:30:06857// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41858void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
859 std::vector<std::string>* additional_schemes) {
860 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06861}
862
[email protected]6bd30072013-02-08 18:17:11863net::URLRequestContextGetter*
864ChromeContentBrowserClient::CreateRequestContext(
865 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06866 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11867 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06868 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11869}
870
871net::URLRequestContextGetter*
872ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
873 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40874 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11875 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06876 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11877 Profile* profile = Profile::FromBrowserContext(browser_context);
878 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06879 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11880}
881
[email protected]46fb9442011-12-09 17:57:47882bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
883 return ProfileIOData::IsHandledURL(url);
884}
885
[email protected]2a5221b2011-09-27 23:07:31886bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30887 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31888 const GURL& site_url) {
889 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30890 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52891 // This may be NULL during tests. In that case, just assume any site can
892 // share any host.
893 if (!profile)
894 return true;
895
[email protected]d43f99fe2013-04-03 00:20:14896 // Instant URLs should only be in the instant process and instant process
897 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52898 InstantService* instant_service =
899 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14900 if (instant_service) {
901 bool is_instant_process = instant_service->IsInstantProcess(
902 process_host->GetID());
903 bool should_be_in_instant_process =
904 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
905 if (is_instant_process || should_be_in_instant_process)
906 return is_instant_process && should_be_in_instant_process;
907 }
[email protected]c5dec6292013-01-25 04:54:52908
[email protected]d5bcd06f2013-04-21 08:07:24909#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30910 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
911 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
912 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:24913#endif
[email protected]970c63e2013-03-07 00:25:30914
[email protected]06bdd2b2012-11-30 18:47:13915 ExtensionService* service =
916 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46917 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31918
[email protected]ffa97602011-11-17 17:55:52919 // Don't allow the Task Manager to share a process with anything else.
920 // Otherwise it can affect the renderers it is observing.
921 // Note: we could create another RenderProcessHostPrivilege bucket for
922 // this to allow multiple chrome://tasks instances to share, but that's
923 // a very unlikely case without serious consequences.
924 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
925 return false;
926
[email protected]8d3132f62011-10-12 07:13:42927 // These may be NULL during tests. In that case, just assume any site can
928 // share any host.
[email protected]6f371442011-11-09 06:45:46929 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31930 return true;
931
[email protected]eec0b33c2011-12-05 22:09:45932 // Otherwise, just make sure the process privilege matches the privilege
933 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57934 RenderProcessHostPrivilege privilege_required =
935 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45936 return GetProcessPrivilege(process_host, process_map, service) ==
937 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31938}
939
[email protected]76411f412012-02-22 18:56:06940// This function is trying to limit the amount of processes used by extensions
941// with background pages. It uses a globally set percentage of processes to
942// run such extensions and if the limit is exceeded, it returns true, to
943// indicate to the content module to group extensions together.
944bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
945 content::BrowserContext* browser_context, const GURL& url) {
946 // It has to be a valid URL for us to check for an extension.
947 if (!url.is_valid())
948 return false;
949
950 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19951 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13952 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06953 if (!service)
954 return false;
955
956 // We have to have a valid extension with background page to proceed.
957 const Extension* extension =
958 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
959 if (!extension)
960 return false;
[email protected]9367eabc2013-03-01 01:29:29961 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06962 return false;
963
964 std::set<int> process_ids;
965 size_t max_process_count =
966 content::RenderProcessHost::GetMaxRendererProcessCount();
967
968 // Go through all profiles to ensure we have total count of extension
969 // processes containing background pages, otherwise one profile can
970 // starve the other.
971 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
972 GetLoadedProfiles();
973 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03974 ExtensionProcessManager* epm =
975 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32976 for (ExtensionProcessManager::const_iterator iter =
977 epm->background_hosts().begin();
978 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13979 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32980 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06981 }
982 }
983
984 if (process_ids.size() >
985 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
986 return true;
987 }
988
989 return false;
990}
991
[email protected]6f371442011-11-09 06:45:46992void ChromeContentBrowserClient::SiteInstanceGotProcess(
993 SiteInstance* site_instance) {
994 CHECK(site_instance->HasProcess());
995
996 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02997 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52998 if (!profile)
999 return;
1000
1001 // Remember the ID of the Instant process to signal the renderer process
1002 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031003 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321004 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521005 InstantService* instant_service =
1006 InstantServiceFactory::GetForProfile(profile);
1007 if (instant_service)
1008 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1009 }
1010
[email protected]d5bcd06f2013-04-21 08:07:241011#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301012 // We only expect there to be one signin process as we use process-per-site
1013 // for signin URLs. The signin process will be cleared from SigninManager
1014 // when the renderer is destroyed.
1015 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1016 SigninManager* signin_manager =
1017 SigninManagerFactory::GetForProfile(profile);
1018 if (signin_manager)
1019 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
1020 }
[email protected]d5bcd06f2013-04-21 08:07:241021#endif
[email protected]970c63e2013-03-07 00:25:301022
[email protected]06bdd2b2012-11-30 18:47:131023 ExtensionService* service =
1024 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461025 if (!service)
1026 return;
1027
1028 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441029 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591030 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461031 if (!extension)
1032 return;
1033
[email protected]6bc04fd82011-12-04 02:29:351034 service->process_map()->Insert(extension->id(),
1035 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331036 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461037 BrowserThread::PostTask(
1038 BrowserThread::IO, FROM_HERE,
1039 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591040 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461041 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351042 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331043 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461044}
1045
1046void ChromeContentBrowserClient::SiteInstanceDeleting(
1047 SiteInstance* site_instance) {
1048 if (!site_instance->HasProcess())
1049 return;
1050
1051 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021052 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131053 ExtensionService* service =
1054 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461055 if (!service)
1056 return;
1057
1058 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441059 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591060 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461061 if (!extension)
1062 return;
1063
[email protected]6bc04fd82011-12-04 02:29:351064 service->process_map()->Remove(extension->id(),
1065 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331066 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461067 BrowserThread::PostTask(
1068 BrowserThread::IO, FROM_HERE,
1069 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591070 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461071 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351072 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331073 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461074}
1075
[email protected]f05763972012-06-06 18:17:261076bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141077 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081078 const GURL& current_url,
1079 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261080 if (current_url.is_empty()) {
1081 // Always choose a new process when navigating to extension URLs. The
1082 // process grouping logic will combine all of a given extension's pages
1083 // into the same process.
[email protected]885c0e92012-11-13 20:27:421084 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261085 return true;
[email protected]e3daf3c2011-10-05 21:17:081086
[email protected]f05763972012-06-06 18:17:261087 return false;
1088 }
1089
1090 // Also, we must switch if one is an extension and the other is not the exact
1091 // same extension.
[email protected]885c0e92012-11-13 20:27:421092 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1093 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261094 if (current_url.GetOrigin() != new_url.GetOrigin())
1095 return true;
1096 }
1097
[email protected]e9841fbd2013-02-22 23:12:141098 // The checks below only matter if we can retrieve which extensions are
1099 // installed.
1100 Profile* profile =
1101 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1102 ExtensionService* service =
1103 extensions::ExtensionSystem::Get(profile)->extension_service();
1104 if (!service)
1105 return false;
1106
1107 // We must swap if the URL is for an extension and we are not using an
1108 // extension process.
1109 const Extension* new_extension =
1110 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1111 // Ignore all hosted apps except the Chrome Web Store, since they do not
1112 // require their own BrowsingInstance (e.g., postMessage is ok).
1113 if (new_extension &&
1114 new_extension->is_hosted_app() &&
1115 new_extension->id() != extension_misc::kWebStoreAppId)
1116 new_extension = NULL;
1117 if (new_extension &&
1118 site_instance->HasProcess() &&
1119 !service->process_map()->Contains(new_extension->id(),
1120 site_instance->GetProcess()->GetID()))
1121 return true;
1122
[email protected]f05763972012-06-06 18:17:261123 return false;
[email protected]e3daf3c2011-10-05 21:17:081124}
1125
[email protected]395045c2012-05-22 15:04:381126bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1127 content::ResourceContext* resource_context, const GURL& current_url,
1128 const GURL& new_url) {
1129 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1130 return extensions::CrossesExtensionProcessBoundary(
1131 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171132 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381133}
1134
[email protected]763ec4ca2011-04-29 15:48:121135std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1136 const std::string& alias_name) {
1137 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1138}
1139
[email protected]b80f68432011-05-02 17:22:301140void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1141 CommandLine* command_line, int child_process_id) {
1142#if defined(USE_LINUX_BREAKPAD)
1143 if (IsCrashReporterEnabled()) {
1144 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1145 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1146 }
1147#elif defined(OS_MACOSX)
1148 if (IsCrashReporterEnabled()) {
1149 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1150 child_process_logging::GetClientId());
1151 }
1152#endif // OS_MACOSX
1153
[email protected]f1933792011-06-14 00:49:341154 if (logging::DialogsAreSuppressed())
1155 command_line->AppendSwitch(switches::kNoErrorDialogs);
1156
[email protected]b80f68432011-05-02 17:22:301157 std::string process_type =
1158 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171159 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321160
1161 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1162 command_line->AppendSwitch(switches::kChromeFrame);
1163
[email protected]718eab62011-10-05 21:16:521164 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451165 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301166 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1167 if (!user_data_dir.empty())
1168 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1169#if defined(OS_CHROMEOS)
1170 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441171 browser_command_line.GetSwitchValueASCII(
1172 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301173 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441174 command_line->AppendSwitchASCII(
1175 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301176#endif
1177
[email protected]f3b1a082011-11-18 00:34:301178 content::RenderProcessHost* process =
1179 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371180 if (process) {
1181 Profile* profile = Profile::FromBrowserContext(
1182 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131183 ExtensionService* extension_service =
1184 extensions::ExtensionSystem::Get(profile)->extension_service();
1185 if (extension_service) {
1186 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001187 if (process_map && process_map->Contains(process->GetID()))
1188 command_line->AppendSwitch(switches::kExtensionProcess);
1189 }
[email protected]b80f68432011-05-02 17:22:301190
[email protected]a8d851f82011-12-21 00:32:371191 PrefService* prefs = profile->GetPrefs();
1192 // Currently this pref is only registered if applied via a policy.
1193 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1194 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1195 // Turn this policy into a command line switch.
1196 command_line->AppendSwitch(switches::kDisable3DAPIs);
1197 }
[email protected]718eab62011-10-05 21:16:521198
[email protected]a8d851f82011-12-21 00:32:371199 // Disable client-side phishing detection in the renderer if it is
1200 // disabled in the Profile preferences or the browser process.
1201 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1202 !g_browser_process->safe_browsing_detection_service()) {
1203 command_line->AppendSwitch(
1204 switches::kDisableClientSidePhishingDetection);
1205 }
[email protected]0045b0f42012-07-26 11:52:081206
1207 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211208 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521209
1210 InstantService* instant_service =
1211 InstantServiceFactory::GetForProfile(profile);
1212 if (instant_service &&
1213 instant_service->IsInstantProcess(process->GetID()))
1214 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301215
[email protected]d5bcd06f2013-04-21 08:07:241216#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301217 SigninManager* signin_manager =
1218 SigninManagerFactory::GetForProfile(profile);
1219 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1220 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241221#endif
[email protected]47c7ec82012-01-18 03:29:211222 }
[email protected]4287a3d2011-06-13 23:56:511223
[email protected]87552982012-11-02 17:21:401224 if (content::IsThreadedCompositingEnabled())
1225 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1226
[email protected]16dc42452013-04-09 04:37:191227#if defined(ENABLE_MESSAGE_CENTER)
1228 if (message_center::IsRichNotificationEnabled())
1229 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
1230#endif
1231
[email protected]47c7ec82012-01-18 03:29:211232 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511233 static const char* const kSwitchNames[] = {
[email protected]e217c5632013-04-12 19:11:481234 autofill::switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511235 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481236 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511237 switches::kAllowScriptingGallery,
1238 switches::kAppsCheckoutURL,
1239 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311240 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511241 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501242 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531243 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111244 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531245 switches::kEnableAdview,
1246 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211247 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511248 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511249 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511250 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511251 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451252 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481253 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051254 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511255 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291256 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511257 switches::kMemoryProfiling,
1258 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371259 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371260 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511261 switches::kPpapiFlashArgs,
1262 switches::kPpapiFlashInProcess,
1263 switches::kPpapiFlashPath,
1264 switches::kPpapiFlashVersion,
1265 switches::kProfilingAtStart,
1266 switches::kProfilingFile,
1267 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371268 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511269 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291270 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381271 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511272 };
1273
1274 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1275 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171276 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381277 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351278 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381279 switches::kEnableExperimentalExtensionApis,
1280 switches::kWhitelistedExtensionID,
1281 };
1282
1283 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1284 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511285 } else if (process_type == switches::kPluginProcess) {
1286 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441287#if defined(OS_CHROMEOS)
1288 chromeos::switches::kLoginProfile,
1289#endif
[email protected]4287a3d2011-06-13 23:56:511290 switches::kMemoryProfiling,
1291 switches::kSilentDumpOnDCHECK,
1292 switches::kUserDataDir,
1293 };
1294
1295 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1296 arraysize(kSwitchNames));
1297 } else if (process_type == switches::kZygoteProcess) {
1298 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511299 switches::kUserDataDir, // Make logs go to the right file.
1300 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501301 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511302 switches::kPpapiFlashInProcess,
1303 switches::kPpapiFlashPath,
1304 switches::kPpapiFlashVersion,
1305 };
1306
1307 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1308 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111309 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001310 base::FilePath user_data_dir =
1311 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1312 if (!user_data_dir.empty())
1313 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111314 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1315 // because GPU is expected to be unreliable.
1316 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1317 !command_line->HasSwitch(switches::kDisableBreakpad))
1318 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301319 }
[email protected]6f08af82011-09-15 01:19:031320
1321 // The command line switch kEnableBenchmarking needs to be specified along
1322 // with the kEnableStatsTable switch to ensure that the stats table global
1323 // is initialized correctly.
1324 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1325 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301326}
1327
1328std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431329 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351330 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301331 return g_browser_process->GetApplicationLocale();
1332}
1333
[email protected]597a867b2011-11-18 18:31:201334std::string ChromeContentBrowserClient::GetAcceptLangs(
1335 content::BrowserContext* context) {
1336 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371337 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081338}
1339
[email protected]9ec0f452012-05-31 15:58:531340gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221341 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531342 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081343}
1344
[email protected]a2176792011-05-08 19:30:491345bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091346 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191347 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201348 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201350 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051351 return io_data->GetCookieSettings()->
1352 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491353}
1354
[email protected]ed24fad2011-05-10 22:44:011355bool ChromeContentBrowserClient::AllowGetCookie(
1356 const GURL& url,
1357 const GURL& first_party,
1358 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201359 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011360 int render_process_id,
1361 int render_view_id) {
1362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201363 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051364 bool allow = io_data->GetCookieSettings()->
1365 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011366
[email protected]8093a542011-05-13 07:29:321367 BrowserThread::PostTask(
1368 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031369 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431370 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011371 return allow;
1372}
1373
1374bool ChromeContentBrowserClient::AllowSetCookie(
1375 const GURL& url,
1376 const GURL& first_party,
1377 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201378 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011379 int render_process_id,
1380 int render_view_id,
1381 net::CookieOptions* options) {
1382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201383 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051384 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1385 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1386
[email protected]8093a542011-05-13 07:29:321387 BrowserThread::PostTask(
1388 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031389 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431390 render_view_id, url, first_party, cookie_line, *options,
1391 !allow));
[email protected]ed24fad2011-05-10 22:44:011392 return allow;
1393}
1394
[email protected]d5a19162011-06-30 18:51:541395bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201396 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201398 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431399 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1400 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261401
[email protected]bf510ed2012-06-05 08:31:431402 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1403 // Could we even support per-origin settings?
1404 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541405}
1406
[email protected]5c5a88e2011-11-12 00:45:351407bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351408 const GURL& url,
1409 const string16& name,
1410 const string16& display_name,
1411 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201412 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481413 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201415 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351416 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1417 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1418
[email protected]62151052012-02-01 18:40:481419 // Record access to database for potential display in UI.
1420 std::vector<std::pair<int, int> >::const_iterator i;
1421 for (i = render_views.begin(); i != render_views.end(); ++i) {
1422 BrowserThread::PostTask(
1423 BrowserThread::UI, FROM_HERE,
1424 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1425 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351426 }
1427
1428 return allow;
1429}
1430
1431bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351432 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201433 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481434 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201436 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351437 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1438 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1439
[email protected]62151052012-02-01 18:40:481440 // Record access to file system for potential display in UI.
1441 std::vector<std::pair<int, int> >::const_iterator i;
1442 for (i = render_views.begin(); i != render_views.end(); ++i) {
1443 BrowserThread::PostTask(
1444 BrowserThread::UI, FROM_HERE,
1445 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1446 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351447 }
1448
1449 return allow;
1450}
1451
[email protected]7c5ff9a2012-03-02 07:42:491452bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1453 const GURL& url,
1454 const string16& name,
1455 content::ResourceContext* context,
1456 const std::vector<std::pair<int, int> >& render_views) {
1457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1458 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1459 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1460 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1461
1462 // Record access to IndexedDB for potential display in UI.
1463 std::vector<std::pair<int, int> >::const_iterator i;
1464 for (i = render_views.begin(); i != render_views.end(); ++i) {
1465 BrowserThread::PostTask(
1466 BrowserThread::UI, FROM_HERE,
1467 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1468 i->first, i->second, url, name, !allow));
1469 }
1470
1471 return allow;
1472}
1473
[email protected]6133f922011-07-01 21:34:341474net::URLRequestContext*
1475ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201476 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421478 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201479 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341480 return io_data->extensions_request_context();
1481 }
1482
1483 return NULL;
1484}
1485
[email protected]317f96c92011-05-31 06:53:411486QuotaPermissionContext*
1487ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1488 return new ChromeQuotaPermissionContext();
1489}
1490
[email protected]848dd042011-06-04 18:24:031491void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171492 int render_process_id,
1493 int render_view_id,
1494 int cert_error,
1495 const net::SSLInfo& ssl_info,
1496 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021497 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031498 bool overridable,
[email protected]d9be47702012-05-16 03:41:221499 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171500 const base::Callback<void(bool)>& callback,
1501 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021502 if (resource_type != ResourceType::MAIN_FRAME) {
1503 // A sub-resource has a certificate error. The user doesn't really
1504 // have a context for making the right decision, so block the
1505 // request hard, without an info bar to allow showing the insecure
1506 // content.
1507 *cancel_request = true;
1508 return;
1509 }
1510
[email protected]f9034cf2011-07-21 12:43:411511 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131512 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171513 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411514 if (!tab) {
1515 NOTREACHED();
1516 return;
1517 }
1518 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501519 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301520 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011521 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1522 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411523 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171524 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411525 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171526 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411527 return;
1528 }
1529 }
1530
[email protected]1e87df32012-09-12 04:53:191531#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231532 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1533 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1534 if (captive_portal_tab_helper)
1535 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191536#endif
1537
[email protected]f9034cf2011-07-21 12:43:411538 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221539 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1540 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031541}
1542
[email protected]c99c442e2011-08-24 11:37:301543void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451544 int render_process_id,
1545 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401546 const net::HttpNetworkSession* network_session,
1547 net::SSLCertRequestInfo* cert_request_info,
1548 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131549 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451550 render_process_id, render_view_id);
1551 if (!tab) {
1552 NOTREACHED();
1553 return;
1554 }
1555
[email protected]6786bf402011-12-03 15:19:451556 GURL requesting_url("https://" + cert_request_info->host_and_port);
1557 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1558 << cert_request_info->host_and_port;
1559
[email protected]627e0512011-12-21 22:55:301560 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451561 scoped_ptr<Value> filter(
1562 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1563 requesting_url,
1564 requesting_url,
1565 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1566 std::string(), NULL));
1567
1568 if (filter.get()) {
1569 // Try to automatically select a client certificate.
1570 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1571 DictionaryValue* filter_dict =
1572 static_cast<DictionaryValue*>(filter.get());
1573
1574 const std::vector<scoped_refptr<net::X509Certificate> >&
1575 all_client_certs = cert_request_info->client_certs;
1576 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1577 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1578 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401579 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451580 return;
1581 }
1582 }
1583 } else {
1584 NOTREACHED();
1585 }
1586 }
1587
[email protected]11feec322012-09-18 03:58:521588 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1589 if (!ssl_tab_helper) {
1590 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451591 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141592 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401593 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451594 return;
1595 }
[email protected]11feec322012-09-18 03:58:521596 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401597 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451598}
1599
[email protected]3b455502012-12-11 18:22:581600void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451601 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581602 net::CertificateMimeType cert_type,
1603 const void* cert_data,
1604 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451605 int render_process_id,
1606 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581607 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1608 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451609}
1610
[email protected]dc73a7b2012-03-25 15:27:181611content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561612 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181613}
1614
[email protected]941623e2011-06-07 23:06:041615void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1616 const GURL& source_origin,
1617 int callback_context,
1618 int render_process_id,
1619 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111620#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1622 WebContents* contents =
1623 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1624 if (!contents) {
[email protected]941623e2011-06-07 23:06:041625 NOTREACHED();
1626 return;
1627 }
1628
[email protected]d0d9c3ee2012-06-19 03:07:021629 // Skip showing the infobar if the request comes from an extension, and that
1630 // extension has the 'notify' permission. (If the extension does not have the
1631 // permission, the user will still be prompted.)
1632 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011633 ExtensionInfoMap* extension_info_map =
1634 extensions::ExtensionSystem::Get(profile)->info_map();
1635 DesktopNotificationService* notification_service =
1636 DesktopNotificationServiceFactory::GetForProfile(profile);
1637 const Extension* extension = NULL;
1638 if (extension_info_map) {
1639 ExtensionSet extensions;
1640 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1641 source_origin, render_process_id,
1642 extensions::APIPermission::kNotification, &extensions);
1643 for (ExtensionSet::const_iterator iter = extensions.begin();
1644 iter != extensions.end(); ++iter) {
1645 if (notification_service->IsExtensionEnabled((*iter)->id())) {
1646 extension = *iter;
1647 break;
1648 }
1649 }
1650 }
[email protected]eb4832a2012-12-08 01:57:521651 RenderViewHost* rvh =
1652 RenderViewHost::FromID(render_process_id, render_view_id);
1653 if (IsExtensionWithPermissionOrSuggestInConsole(
1654 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021655 if (rvh)
1656 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1657 return;
1658 }
1659
[email protected]c7cd5942013-04-30 03:31:011660 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021661 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111662#else
1663 NOTIMPLEMENTED();
1664#endif
[email protected]941623e2011-06-07 23:06:041665}
1666
1667WebKit::WebNotificationPresenter::Permission
1668 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021669 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201670 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021671 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111672#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041673 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201674 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041675
[email protected]c7cd5942013-04-30 03:31:011676 DesktopNotificationService* notification_service =
1677 io_data->GetNotificationService();
1678 if (notification_service) {
1679 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1680 ExtensionSet extensions;
1681 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1682 source_origin, render_process_id,
1683 extensions::APIPermission::kNotification, &extensions);
1684 for (ExtensionSet::const_iterator iter = extensions.begin();
1685 iter != extensions.end(); ++iter) {
1686 if (notification_service->IsExtensionEnabled((*iter)->id()))
1687 return WebKit::WebNotificationPresenter::PermissionAllowed;
1688 }
1689
1690 return notification_service->HasPermission(source_origin);
1691 }
1692
1693 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111694#else
1695 return WebKit::WebNotificationPresenter::PermissionAllowed;
1696#endif
[email protected]941623e2011-06-07 23:06:041697}
1698
1699void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171700 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041701 int render_process_id,
1702 int render_view_id,
1703 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111704#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041705 RenderViewHost* rvh = RenderViewHost::FromID(
1706 render_process_id, render_view_id);
1707 if (!rvh) {
1708 NOTREACHED();
1709 return;
1710 }
1711
[email protected]9f76c1e2012-03-05 15:15:581712 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301713 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041714 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371715 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041716 service->ShowDesktopNotification(
1717 params, render_process_id, render_view_id,
1718 worker ? DesktopNotificationService::WorkerNotification :
1719 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111720#else
1721 NOTIMPLEMENTED();
1722#endif
[email protected]941623e2011-06-07 23:06:041723}
1724
1725void ChromeContentBrowserClient::CancelDesktopNotification(
1726 int render_process_id,
1727 int render_view_id,
1728 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111729#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041730 RenderViewHost* rvh = RenderViewHost::FromID(
1731 render_process_id, render_view_id);
1732 if (!rvh) {
1733 NOTREACHED();
1734 return;
1735 }
1736
[email protected]9f76c1e2012-03-05 15:15:581737 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301738 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041739 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371740 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041741 service->CancelDesktopNotification(
1742 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111743#else
1744 NOTIMPLEMENTED();
1745#endif
[email protected]941623e2011-06-07 23:06:041746}
1747
[email protected]9f3fba52011-06-08 20:37:191748bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351749 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021750 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191751 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201752 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011753 int render_process_id,
1754 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191755 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011756
1757 *no_javascript_access = false;
1758
[email protected]9f3fba52011-06-08 20:37:191759 // If the opener is trying to create a background window but doesn't have
1760 // the appropriate permission, fail the attempt.
1761 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201762 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531763 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1764
[email protected]03b6d552012-03-29 04:03:011765 if (!map->SecurityOriginHasAPIPermission(
1766 source_origin,
1767 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061768 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011769 return false;
1770 }
1771
[email protected]7b54ca02012-03-02 18:06:531772 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1773 // return a recently installed Extension even if this CanCreateWindow call
1774 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011775 // because the permission check above would have caused an early return
1776 // already. We must use the full URL to find hosted apps, though, and not
1777 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531778 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351779 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291780 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011781 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191782 }
[email protected]056efdc2013-04-06 00:14:531783
1784 // No new browser window (popup or tab) in app mode.
1785 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1786 chrome::IsRunningInForcedAppMode()) {
1787 return false;
1788 }
1789
[email protected]9f3fba52011-06-08 20:37:191790 return true;
1791}
1792
1793std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201794 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191795 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1796 // Check if it's an extension-created worker, in which case we want to use
1797 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201798 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191799 const Extension* extension =
1800 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1801 return extension ? extension->name() : std::string();
1802}
1803
[email protected]99907362012-01-11 05:41:401804void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1805 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171806}
1807
[email protected]7a06d282013-05-03 04:39:331808// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021809content::SpeechRecognitionManagerDelegate*
1810 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321811#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021812 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321813#else
1814 return NULL;
1815#endif
[email protected]66cfec62012-02-24 17:57:511816}
1817
[email protected]ae6e9912011-07-27 01:18:281818net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1819 return g_browser_process->net_log();
1820}
1821
[email protected]32538d92011-08-25 00:09:231822AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1823 return new ChromeAccessTokenStore();
1824}
1825
[email protected]dbae6b02011-06-29 23:51:411826bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011827 return true;
[email protected]dbae6b02011-06-29 23:51:411828}
1829
[email protected]64d69de42012-02-06 00:19:541830void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321831 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061832 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581833 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061834 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061835
[email protected]f3986f82012-01-03 20:00:061836 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541837 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061838 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541839 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061840 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541841 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061842 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541843 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061844 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541845 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061846 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541847 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031848 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1849 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061850
[email protected]64d69de42012-02-06 00:19:541851 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401852 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541853 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401854 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541855 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401856 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541857 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401858 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061859
[email protected]ddf72142012-05-22 04:52:401860 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061861
[email protected]64d69de42012-02-06 00:19:541862 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401863 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541864 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061865 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541866 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061867 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1868 const DictionaryValue* inspector_settings =
1869 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1870 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181871 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1872 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061873 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181874 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541875 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181876 std::make_pair(iter.key(), value));
1877 }
[email protected]f3986f82012-01-03 20:00:061878 }
1879 }
[email protected]64d69de42012-02-06 00:19:541880 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061881
[email protected]ddf72142012-05-22 04:52:401882 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541883 web_prefs->javascript_enabled = false;
1884 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1885 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401886 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541887 web_prefs->plugins_enabled = false;
1888 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1889 web_prefs->java_enabled = false;
1890 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401891 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061892
[email protected]64d69de42012-02-06 00:19:541893 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1894 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061895
[email protected]64d69de42012-02-06 00:19:541896 web_prefs->memory_info_enabled =
1897 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1898 web_prefs->allow_displaying_insecure_content =
1899 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1900 web_prefs->allow_running_insecure_content =
1901 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321902#if defined(OS_ANDROID)
1903 web_prefs->font_scale_factor =
1904 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1905 web_prefs->force_enable_zoom =
1906 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451907#if defined(GOOGLE_TV)
1908 web_prefs->user_gesture_required_for_media_playback = false;
1909#endif
[email protected]d3b935f2012-10-19 23:14:321910#endif
[email protected]5c915252013-05-07 13:15:391911
[email protected]9d06d88d2012-02-23 22:37:081912 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]5c915252013-05-07 13:15:391913#if defined(OS_CHROMEOS)
1914 // Enable password echo during OOBE when keyboard driven flag is set.
1915 if (chromeos::UserManager::IsInitialized() &&
1916 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
1917 !chromeos::StartupUtils::IsOobeCompleted()) {
1918 bool keyboard_driven_oobe = false;
1919 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]e8f3f9982013-05-10 20:59:531920 chromeos::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:391921 if (keyboard_driven_oobe)
1922 web_prefs->password_echo_enabled = true;
1923 }
1924#endif
[email protected]f3986f82012-01-03 20:00:061925
[email protected]46f8e742013-05-03 18:37:141926#if defined(OS_ANDROID)
1927 web_prefs->user_style_sheet_enabled = false;
1928#else
[email protected]64d69de42012-02-06 00:19:541929 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151930 UserStyleSheetWatcher* user_style_sheet_watcher =
1931 UserStyleSheetWatcherFactory::GetForProfile(profile);
1932 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541933 web_prefs->user_style_sheet_enabled = true;
1934 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151935 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541936 } else {
1937 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061938 }
[email protected]46f8e742013-05-03 18:37:141939#endif
[email protected]f3986f82012-01-03 20:00:061940
[email protected]cfadadd2013-04-03 04:43:021941 web_prefs->asynchronous_spell_checking_enabled = true;
1942 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:571943
[email protected]64d69de42012-02-06 00:19:541944 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061945 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541946 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061947 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541948 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061949 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1950
1951 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541952 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061953 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541954 web_prefs->default_encoding);
1955 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401956 prefs->ClearPref(prefs::kDefaultCharset);
1957 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061958 }
[email protected]64d69de42012-02-06 00:19:541959 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061960
[email protected]88ecf66d2012-12-11 22:53:471961 if (content::IsForceCompositingModeEnabled())
1962 web_prefs->force_compositing_mode = true;
1963
[email protected]299d7f12012-05-23 05:31:151964 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:231965 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131966 ExtensionService* service =
1967 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061968 if (service) {
[email protected]1bc28312012-11-08 08:31:531969 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1970 const Extension* extension = service->extensions()->GetByID(url.host());
1971 // Ensure that we are only granting extension preferences to URLs with
1972 // the correct scheme. Without this check, chrome-guest:// schemes used by
1973 // webview tags as well as hosts that happen to match the id of an
1974 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421975 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531976 extension_webkit_preferences::SetPreferences(
1977 extension, view_type, web_prefs);
1978 }
[email protected]f3986f82012-01-03 20:00:061979 }
1980
[email protected]cb2edf22013-04-01 20:25:231981 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541982 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:231983 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061984 // Disable all kinds of acceleration for background pages.
1985 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541986 web_prefs->force_compositing_mode = false;
1987 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061988 }
[email protected]2e21fe292012-03-02 22:52:321989
1990#if defined(FILE_MANAGER_EXTENSION)
1991 // Override the default of suppressing HW compositing for WebUI pages for the
1992 // file manager, which is implemented using WebUI but wants HW acceleration
1993 // for video decode & render.
1994 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1995 web_prefs->accelerated_compositing_enabled = true;
1996 web_prefs->accelerated_2d_canvas_enabled = true;
1997 }
1998#endif
[email protected]181a95ee2011-07-12 19:26:361999}
2000
2001void ChromeContentBrowserClient::UpdateInspectorSetting(
2002 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062003 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582004 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062005 DictionaryPrefUpdate update(
2006 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2007 prefs::kWebKitInspectorSettings);
2008 DictionaryValue* inspector_settings = update.Get();
2009 inspector_settings->SetWithoutPathExpansion(key,
2010 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362011}
2012
[email protected]b8148ac2011-07-13 22:03:252013void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2014 BrowserURLHandler* handler) {
2015 // Add the default URL handlers.
2016 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2017 BrowserURLHandler::null_handler());
2018 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2019 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2020
[email protected]b3adbd02011-11-30 22:23:272021 // about: handler. Must come before chrome: handler, since it will
2022 // rewrite about: urls to chrome: URLs and then expect chrome: to
2023 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252024 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2025 BrowserURLHandler::null_handler());
2026 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242027 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252028}
2029
2030void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372031 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582032 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472033 BrowsingDataRemover* remover =
2034 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552035 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2036 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252037 // BrowsingDataRemover takes care of deleting itself when done.
2038}
2039
2040void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372041 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582042 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472043 BrowsingDataRemover* remover =
2044 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232045 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552046 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252047 // BrowsingDataRemover takes care of deleting itself when done.
2048}
2049
[email protected]650b2d52013-02-10 03:41:452050base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322051 return download_util::GetDefaultDownloadDirectory();
2052}
2053
[email protected]c9b6eb62011-10-18 20:49:392054std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2055 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2056}
2057
[email protected]b7631cc2012-09-15 05:08:382058void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2059 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542060#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382061 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2062 scoped_ptr<ppapi::host::HostFactory>(
2063 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542064#endif
[email protected]b7631cc2012-09-15 05:08:382065}
2066
[email protected]0c7193742012-11-07 19:05:032067content::BrowserPpapiHost*
2068 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2069 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132070 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032071 while (!iter.Done()) {
2072 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2073 if (host->process() &&
2074 host->process()->GetData().id == plugin_process_id) {
2075 // Found the plugin.
2076 return host->browser_ppapi_host();
2077 }
2078 ++iter;
2079 }
2080 return NULL;
2081}
2082
[email protected]7b38b192013-03-23 18:39:312083bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2084 content::BrowserContext* browser_context, const GURL& site_url) {
2085 if (CommandLine::ForCurrentProcess()->HasSwitch(
2086 switches::kEnableBrowserPluginForAllViewTypes))
2087 return true;
2088
2089 Profile* profile = Profile::FromBrowserContext(browser_context);
2090 ExtensionService* service =
2091 extensions::ExtensionSystem::Get(profile)->extension_service();
2092 if (!service)
2093 return false;
2094
2095 const Extension* extension = service->extensions()->
2096 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2097 if (!extension)
2098 return false;
2099
[email protected]c2d2f102013-04-29 16:42:582100 return extension->HasAPIPermission(APIPermission::kWebView) ||
2101 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312102}
2103
[email protected]38cd8f7f2012-06-15 22:06:072104bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582105 content::BrowserContext* browser_context,
2106 const GURL& url,
2107 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:292108 if (!url.is_valid())
2109 return false;
2110
2111 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:422112 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]b71313232013-05-06 06:16:292113 HostIsInSet(host, allowed_socket_origins_)) {
[email protected]a658d452012-03-02 12:45:292114 return true;
[email protected]885c0e92012-11-13 20:27:422115 }
[email protected]a658d452012-03-02 12:45:292116
[email protected]9a5940d2012-04-27 19:16:232117 Profile* profile = Profile::FromBrowserContext(browser_context);
2118 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:192119 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:132120 extensions::ExtensionSystem::Get(profile)->extension_service();
2121 if (extension_service) {
2122 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:232123 GetExtensionOrAppByURL(ExtensionURLInfo(url));
2124 }
2125
[email protected]b71313232013-05-06 06:16:292126 // Check the modules that are imported by this extension to see if any of them
2127 // is whitelisted.
2128 if (extension) {
2129 const std::vector<extensions::SharedModuleInfo::ImportInfo>& imports =
2130 extensions::SharedModuleInfo::GetImports(extension);
2131 std::vector<extensions::SharedModuleInfo::ImportInfo>::const_iterator it;
2132 for (it = imports.begin(); it != imports.end(); ++it) {
2133 const Extension* imported_extension = extension_service->
2134 GetExtensionById(it->extension_id, false);
2135 if (imported_extension &&
2136 extensions::SharedModuleInfo::IsSharedModule(imported_extension) &&
2137 HostIsInSet(it->extension_id, allowed_socket_origins_)) {
2138 return true;
2139 }
2140 }
2141 }
2142
[email protected]f237c0f2012-03-10 07:49:102143 // Need to check this now and not on construction because otherwise it won't
2144 // work with browser_tests.
2145 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2146 std::string allowed_list =
2147 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:232148 if (allowed_list == "*") {
2149 // The wildcard allows socket API only for packaged and platform apps.
2150 return extension &&
[email protected]1d5e58b2013-01-31 08:41:402151 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
2152 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:232153 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:392154 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:102155 while (t.GetNext()) {
2156 if (t.token() == host)
2157 return true;
2158 }
2159 }
2160
[email protected]a658d452012-03-02 12:45:292161 return false;
[email protected]e461da2f2012-02-16 19:06:402162}
2163
[email protected]650b2d52013-02-10 03:41:452164base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2165 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142166 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2167 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2168}
2169
[email protected]a28e3302013-02-03 03:50:432170ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2171 WebContents* web_contents) {
2172 return new ChromeSelectFilePolicy(web_contents);
2173}
2174
[email protected]7d9424702013-04-14 13:14:162175void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2176 std::vector<std::string>* additional_allowed_schemes) {
2177 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2178 additional_allowed_schemes);
2179 additional_allowed_schemes->push_back(kChromeUIScheme);
2180 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2181}
2182
[email protected]02250952013-04-24 23:52:532183void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2184 const base::FilePath& storage_partition_path,
2185 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2186#if !defined(OS_ANDROID)
2187 additional_providers->push_back(new MediaFileSystemMountPointProvider(
2188 storage_partition_path));
2189#endif
2190}
2191
[email protected]e60c0232011-11-11 19:56:352192#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182193void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2194 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382195 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082196 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392197#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452198 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392199 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2200 DCHECK(!data_path.empty());
2201
2202 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452203 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392204 base::PlatformFile f =
2205 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2206 DCHECK(f != base::kInvalidPlatformFileValue);
2207 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2208 FileDescriptor(f, true)));
2209
[email protected]650b2d52013-02-10 03:41:452210 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392211 data_path.AppendASCII("chrome_100_percent.pak");
2212 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2213 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372214 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392215 FileDescriptor(f, true)));
2216
2217 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452218 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392219 GetLocaleFilePath(locale, false);
2220 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2221 DCHECK(f != base::kInvalidPlatformFileValue);
2222 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2223 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382224
[email protected]650b2d52013-02-10 03:41:452225 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372226 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2227 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2228 DCHECK(f != base::kInvalidPlatformFileValue);
2229 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2230 FileDescriptor(f, true)));
2231
[email protected]40da3e0c2012-10-24 22:03:382232#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432233 if (IsCrashReporterEnabled()) {
2234 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2235 if (f == base::kInvalidPlatformFileValue) {
2236 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2237 "be disabled for this process.";
2238 } else {
2239 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2240 FileDescriptor(f, true)));
2241 }
[email protected]40da3e0c2012-10-24 22:03:382242 }
2243#endif // defined(USE_LINUX_BREAKPAD)
2244
2245#else
2246 int crash_signal_fd = GetCrashSignalFD(command_line);
2247 if (crash_signal_fd >= 0) {
2248 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2249 FileDescriptor(crash_signal_fd,
2250 false)));
2251 }
[email protected]29699c22012-10-03 23:57:392252#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302253}
[email protected]e60c0232011-11-11 19:56:352254#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302255
[email protected]4a65826d2011-08-25 16:04:012256#if defined(OS_WIN)
2257const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2258 return chrome::kBrowserResourcesDll;
2259}
[email protected]34f48682013-03-20 00:30:182260
2261void ChromeContentBrowserClient::PreSpawnRenderer(
2262 sandbox::TargetPolicy* policy,
2263 bool* success) {
2264 // This code is duplicated in nacl_exe_win_64.cc.
2265 // Allow the server side of a pipe restricted to the "chrome.nacl."
2266 // namespace so that it cannot impersonate other system or other chrome
2267 // service pipes.
2268 sandbox::ResultCode result = policy->AddRule(
2269 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2270 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2271 L"\\\\.\\pipe\\chrome.nacl.*");
2272 if (result != sandbox::SBOX_ALL_OK) {
2273 *success = false;
2274 return;
2275 }
2276
2277 // Renderers need to send named pipe handles and shared memory
2278 // segment handles to NaCl loader processes.
2279 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2280 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2281 L"File");
2282 if (result != sandbox::SBOX_ALL_OK) {
2283 *success = false;
2284 return;
2285 }
2286}
[email protected]4a65826d2011-08-25 16:04:012287#endif
2288
[email protected]37a72af2011-06-13 05:42:012289#if defined(USE_NSS)
2290crypto::CryptoModuleBlockingPasswordDelegate*
2291 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2292 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292293 return chrome::NewCryptoModuleBlockingDialogDelegate(
2294 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012295}
2296#endif
2297
[email protected]d977f9c2011-03-14 16:10:262298} // namespace chrome