blob: cfe049364f861fb1b999ceb9ab4d5c3c4dcc302e [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]9a224572013-05-12 23:08:56164#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));
[email protected]c4c2312c2013-05-13 05:04:11695 // TODO(fsamuel): This should be replaced with WebViewGuest or AdViewGuest
696 // once they are ready.
697 extensions::TabHelper::CreateForWebContents(guest_web_contents);
[email protected]44703cc72013-01-24 04:56:06698}
699
[email protected]f3b1a082011-11-18 00:34:30700void ChromeContentBrowserClient::RenderProcessHostCreated(
701 content::RenderProcessHost* host) {
702 int id = host->GetID();
703 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41704 net::URLRequestContextGetter* context =
705 profile->GetRequestContextForRenderProcess(id);
706
[email protected]f3b1a082011-11-18 00:34:30707 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41708 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55709#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30710 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55711#endif
[email protected]658677f2012-06-09 06:04:02712#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08713 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03714#endif
[email protected]f3b1a082011-11-18 00:34:30715 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02716 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30717 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56718#if defined(OS_MACOSX)
[email protected]628cad4d2013-04-13 00:36:21719 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac(id));
[email protected]7ceb99012011-12-21 08:05:56720#endif
[email protected]43535512013-02-20 20:41:41721 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
722 id, profile, context));
[email protected]2736c032012-05-11 18:06:07723 host->GetChannel()->AddFilter(
724 new prerender::PrerenderMessageFilter(id, profile));
[email protected]1352ca92013-04-30 02:30:27725 host->GetChannel()->AddFilter(new ValidationMessageMessageFilter(id));
[email protected]7a06d282013-05-03 04:39:33726#if !defined(OS_ANDROID)
727 host->GetChannel()->AddFilter(new TtsMessageFilter(id, profile));
728#endif
[email protected]3e69bc82011-05-26 23:22:38729
[email protected]2ccf45c2011-08-19 23:35:50730 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
731 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07732
[email protected]24665682013-02-25 20:59:38733 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
734 IsExtensionActivityLogEnabledForProfile(profile)));
735
[email protected]39a5b532011-10-22 01:47:07736 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56737
738 RendererContentSettingRules rules;
739 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
740 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14741}
742
[email protected]95c95552013-05-03 04:21:22743GURL ChromeContentBrowserClient::GetPossiblyPrivilegedURL(
744 content::BrowserContext* browser_context,
745 const GURL& url,
746 bool is_renderer_initiated,
747 content::SiteInstance* current_instance) {
748 Profile* profile = Profile::FromBrowserContext(browser_context);
749 if (!profile)
750 return url;
751
752 // Only return the privileged instant URL if we are entering from a browser-
753 // initiated navigation or if we are already in the instant process.
754 bool is_instant_process = false;
755 int process_id = current_instance->GetProcess()->GetID();
756 InstantService* instant_service =
757 InstantServiceFactory::GetForProfile(profile);
758 if (instant_service)
759 is_instant_process = instant_service->IsInstantProcess(process_id);
760
761 DCHECK_EQ(is_instant_process,
762 chrome::IsPrivilegedURLForInstant(current_instance->GetSiteURL()));
763 if (!is_renderer_initiated || is_instant_process) {
764 // If the input |url| should be assigned to the Instant renderer, make its
765 // privileged URL distinct from other URLs on the search provider's domain.
766 if (chrome::ShouldAssignURLToInstantRenderer(url, profile))
767 return chrome::GetPrivilegedURLForInstant(url, profile);
768 }
769
770 return url;
771}
772
[email protected]3d7474ff2011-07-27 17:47:37773GURL ChromeContentBrowserClient::GetEffectiveURL(
774 content::BrowserContext* browser_context, const GURL& url) {
775 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52776 if (!profile)
777 return url;
778
[email protected]d5bcd06f2013-04-21 08:07:24779#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30780 // If the input |url| should be assigned to the Signin renderer, make its
781 // effective URL distinct from other URLs on the signin service's domain.
782 // Note that the signin renderer will be allowed to sign the user in to
783 // Chrome.
784 if (SigninManager::IsWebBasedSigninFlowURL(url))
785 return GetEffectiveURLForSignin(url);
[email protected]d5bcd06f2013-04-21 08:07:24786#endif
[email protected]970c63e2013-03-07 00:25:30787
[email protected]c5dec6292013-01-25 04:54:52788 // If the input |url| is part of an installed app, the effective URL is an
789 // extension URL with the ID of that extension as the host. This has the
790 // effect of grouping apps together in a common SiteInstance.
791 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13792 extensions::ExtensionSystem::Get(profile)->extension_service();
793 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08794 return url;
795
[email protected]06bdd2b2012-11-30 18:47:13796 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44797 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08798 if (!extension)
799 return url;
800
[email protected]15877ca2011-11-18 22:40:52801 // Bookmark apps do not use the hosted app process model, and should be
802 // treated as normal URLs.
803 if (extension->from_bookmark())
804 return url;
805
[email protected]36fb2c7c2011-04-04 15:49:08806 // If the URL is part of an extension's web extent, convert it to an
807 // extension URL.
808 return extension->GetResourceURL(url.path());
809}
810
[email protected]056ad2a2011-07-12 02:13:55811bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37812 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52813 // Non-extension, non-Instant URLs should generally use
814 // process-per-site-instance. Because we expect to use the effective URL,
815 // URLs for hosted apps (apart from bookmark apps) should have an extension
816 // scheme by now.
817
818 Profile* profile = Profile::FromBrowserContext(browser_context);
819 if (!profile)
820 return false;
821
[email protected]165fe422013-03-27 06:34:03822 if (chrome::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52823 return true;
824
[email protected]d5bcd06f2013-04-21 08:07:24825#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30826 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
827 return true;
[email protected]d5bcd06f2013-04-21 08:07:24828#endif
[email protected]970c63e2013-03-07 00:25:30829
[email protected]885c0e92012-11-13 20:27:42830 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55831 return false;
832
[email protected]c5dec6292013-01-25 04:54:52833 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13834 extensions::ExtensionSystem::Get(profile)->extension_service();
835 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55836 return false;
837
[email protected]06bdd2b2012-11-30 18:47:13838 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44839 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55840 if (!extension)
841 return false;
842
843 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53844 // permission, or that does not allow JavaScript access to the background
845 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55846 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40847 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06848 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29849 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53850 return false;
851 }
852 }
[email protected]056ad2a2011-07-12 02:13:55853
[email protected]7b54ca02012-03-02 18:06:53854 // Hosted apps that have script access to their background page must use
855 // process per site, since all instances can make synchronous calls to the
856 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55857 return true;
858}
859
[email protected]672c8c12013-03-07 12:30:06860// These are treated as WebUI schemes but do not get WebUI bindings.
[email protected]8f89dd412013-04-17 02:35:41861void ChromeContentBrowserClient::GetAdditionalWebUISchemes(
862 std::vector<std::string>* additional_schemes) {
863 additional_schemes->push_back(chrome::kChromeSearchScheme);
[email protected]672c8c12013-03-07 12:30:06864}
865
[email protected]6bd30072013-02-08 18:17:11866net::URLRequestContextGetter*
867ChromeContentBrowserClient::CreateRequestContext(
868 content::BrowserContext* browser_context,
[email protected]672c8c12013-03-07 12:30:06869 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11870 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]672c8c12013-03-07 12:30:06871 return profile->CreateRequestContext(protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11872}
873
874net::URLRequestContextGetter*
875ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
876 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40877 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11878 bool in_memory,
[email protected]672c8c12013-03-07 12:30:06879 content::ProtocolHandlerMap* protocol_handlers) {
[email protected]6bd30072013-02-08 18:17:11880 Profile* profile = Profile::FromBrowserContext(browser_context);
881 return profile->CreateRequestContextForStoragePartition(
[email protected]672c8c12013-03-07 12:30:06882 partition_path, in_memory, protocol_handlers);
[email protected]6bd30072013-02-08 18:17:11883}
884
[email protected]46fb9442011-12-09 17:57:47885bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
886 return ProfileIOData::IsHandledURL(url);
887}
888
[email protected]2a5221b2011-09-27 23:07:31889bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30890 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31891 const GURL& site_url) {
892 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30893 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52894 // This may be NULL during tests. In that case, just assume any site can
895 // share any host.
896 if (!profile)
897 return true;
898
[email protected]d43f99fe2013-04-03 00:20:14899 // Instant URLs should only be in the instant process and instant process
900 // should only have Instant URLs.
[email protected]c5dec6292013-01-25 04:54:52901 InstantService* instant_service =
902 InstantServiceFactory::GetForProfile(profile);
[email protected]d43f99fe2013-04-03 00:20:14903 if (instant_service) {
904 bool is_instant_process = instant_service->IsInstantProcess(
905 process_host->GetID());
906 bool should_be_in_instant_process =
907 chrome::ShouldAssignURLToInstantRenderer(site_url, profile);
908 if (is_instant_process || should_be_in_instant_process)
909 return is_instant_process && should_be_in_instant_process;
910 }
[email protected]c5dec6292013-01-25 04:54:52911
[email protected]d5bcd06f2013-04-21 08:07:24912#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:30913 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
914 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
915 return SigninManager::IsWebBasedSigninFlowURL(site_url);
[email protected]d5bcd06f2013-04-21 08:07:24916#endif
[email protected]970c63e2013-03-07 00:25:30917
[email protected]06bdd2b2012-11-30 18:47:13918 ExtensionService* service =
919 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46920 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31921
[email protected]ffa97602011-11-17 17:55:52922 // Don't allow the Task Manager to share a process with anything else.
923 // Otherwise it can affect the renderers it is observing.
924 // Note: we could create another RenderProcessHostPrivilege bucket for
925 // this to allow multiple chrome://tasks instances to share, but that's
926 // a very unlikely case without serious consequences.
927 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
928 return false;
929
[email protected]8d3132f62011-10-12 07:13:42930 // These may be NULL during tests. In that case, just assume any site can
931 // share any host.
[email protected]6f371442011-11-09 06:45:46932 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31933 return true;
934
[email protected]eec0b33c2011-12-05 22:09:45935 // Otherwise, just make sure the process privilege matches the privilege
936 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57937 RenderProcessHostPrivilege privilege_required =
938 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45939 return GetProcessPrivilege(process_host, process_map, service) ==
940 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31941}
942
[email protected]76411f412012-02-22 18:56:06943// This function is trying to limit the amount of processes used by extensions
944// with background pages. It uses a globally set percentage of processes to
945// run such extensions and if the limit is exceeded, it returns true, to
946// indicate to the content module to group extensions together.
947bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
948 content::BrowserContext* browser_context, const GURL& url) {
949 // It has to be a valid URL for us to check for an extension.
950 if (!url.is_valid())
951 return false;
952
953 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19954 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13955 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06956 if (!service)
957 return false;
958
959 // We have to have a valid extension with background page to proceed.
960 const Extension* extension =
961 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
962 if (!extension)
963 return false;
[email protected]9367eabc2013-03-01 01:29:29964 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06965 return false;
966
967 std::set<int> process_ids;
968 size_t max_process_count =
969 content::RenderProcessHost::GetMaxRendererProcessCount();
970
971 // Go through all profiles to ensure we have total count of extension
972 // processes containing background pages, otherwise one profile can
973 // starve the other.
974 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
975 GetLoadedProfiles();
976 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03977 ExtensionProcessManager* epm =
978 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32979 for (ExtensionProcessManager::const_iterator iter =
980 epm->background_hosts().begin();
981 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13982 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32983 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06984 }
985 }
986
987 if (process_ids.size() >
988 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
989 return true;
990 }
991
992 return false;
993}
994
[email protected]6f371442011-11-09 06:45:46995void ChromeContentBrowserClient::SiteInstanceGotProcess(
996 SiteInstance* site_instance) {
997 CHECK(site_instance->HasProcess());
998
999 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021000 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:521001 if (!profile)
1002 return;
1003
1004 // Remember the ID of the Instant process to signal the renderer process
1005 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]165fe422013-03-27 06:34:031006 if (chrome::ShouldAssignURLToInstantRenderer(
[email protected]7c60f5042013-02-14 03:39:321007 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:521008 InstantService* instant_service =
1009 InstantServiceFactory::GetForProfile(profile);
1010 if (instant_service)
1011 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
1012 }
1013
[email protected]d5bcd06f2013-04-21 08:07:241014#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301015 // We only expect there to be one signin process as we use process-per-site
1016 // for signin URLs. The signin process will be cleared from SigninManager
1017 // when the renderer is destroyed.
1018 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
1019 SigninManager* signin_manager =
1020 SigninManagerFactory::GetForProfile(profile);
1021 if (signin_manager)
1022 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
1023 }
[email protected]d5bcd06f2013-04-21 08:07:241024#endif
[email protected]970c63e2013-03-07 00:25:301025
[email protected]06bdd2b2012-11-30 18:47:131026 ExtensionService* service =
1027 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461028 if (!service)
1029 return;
1030
1031 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441032 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:591033 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461034 if (!extension)
1035 return;
1036
[email protected]6bc04fd82011-12-04 02:29:351037 service->process_map()->Insert(extension->id(),
1038 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331039 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461040 BrowserThread::PostTask(
1041 BrowserThread::IO, FROM_HERE,
1042 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591043 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461044 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351045 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331046 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461047}
1048
1049void ChromeContentBrowserClient::SiteInstanceDeleting(
1050 SiteInstance* site_instance) {
1051 if (!site_instance->HasProcess())
1052 return;
1053
1054 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:021055 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131056 ExtensionService* service =
1057 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:461058 if (!service)
1059 return;
1060
1061 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441062 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591063 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461064 if (!extension)
1065 return;
1066
[email protected]6bc04fd82011-12-04 02:29:351067 service->process_map()->Remove(extension->id(),
1068 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331069 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461070 BrowserThread::PostTask(
1071 BrowserThread::IO, FROM_HERE,
1072 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591073 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461074 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351075 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331076 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461077}
1078
[email protected]f05763972012-06-06 18:17:261079bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141080 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081081 const GURL& current_url,
1082 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261083 if (current_url.is_empty()) {
1084 // Always choose a new process when navigating to extension URLs. The
1085 // process grouping logic will combine all of a given extension's pages
1086 // into the same process.
[email protected]885c0e92012-11-13 20:27:421087 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261088 return true;
[email protected]e3daf3c2011-10-05 21:17:081089
[email protected]f05763972012-06-06 18:17:261090 return false;
1091 }
1092
1093 // Also, we must switch if one is an extension and the other is not the exact
1094 // same extension.
[email protected]885c0e92012-11-13 20:27:421095 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1096 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261097 if (current_url.GetOrigin() != new_url.GetOrigin())
1098 return true;
1099 }
1100
[email protected]e9841fbd2013-02-22 23:12:141101 // The checks below only matter if we can retrieve which extensions are
1102 // installed.
1103 Profile* profile =
1104 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1105 ExtensionService* service =
1106 extensions::ExtensionSystem::Get(profile)->extension_service();
1107 if (!service)
1108 return false;
1109
1110 // We must swap if the URL is for an extension and we are not using an
1111 // extension process.
1112 const Extension* new_extension =
1113 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1114 // Ignore all hosted apps except the Chrome Web Store, since they do not
1115 // require their own BrowsingInstance (e.g., postMessage is ok).
1116 if (new_extension &&
1117 new_extension->is_hosted_app() &&
1118 new_extension->id() != extension_misc::kWebStoreAppId)
1119 new_extension = NULL;
1120 if (new_extension &&
1121 site_instance->HasProcess() &&
1122 !service->process_map()->Contains(new_extension->id(),
1123 site_instance->GetProcess()->GetID()))
1124 return true;
1125
[email protected]f05763972012-06-06 18:17:261126 return false;
[email protected]e3daf3c2011-10-05 21:17:081127}
1128
[email protected]395045c2012-05-22 15:04:381129bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1130 content::ResourceContext* resource_context, const GURL& current_url,
1131 const GURL& new_url) {
1132 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1133 return extensions::CrossesExtensionProcessBoundary(
1134 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171135 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381136}
1137
[email protected]763ec4ca2011-04-29 15:48:121138std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1139 const std::string& alias_name) {
1140 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1141}
1142
[email protected]b80f68432011-05-02 17:22:301143void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1144 CommandLine* command_line, int child_process_id) {
1145#if defined(USE_LINUX_BREAKPAD)
1146 if (IsCrashReporterEnabled()) {
1147 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1148 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1149 }
1150#elif defined(OS_MACOSX)
1151 if (IsCrashReporterEnabled()) {
1152 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1153 child_process_logging::GetClientId());
1154 }
1155#endif // OS_MACOSX
1156
[email protected]f1933792011-06-14 00:49:341157 if (logging::DialogsAreSuppressed())
1158 command_line->AppendSwitch(switches::kNoErrorDialogs);
1159
[email protected]b80f68432011-05-02 17:22:301160 std::string process_type =
1161 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171162 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]9206f2a02013-03-20 01:10:321163
1164 if (browser_command_line.HasSwitch(switches::kChromeFrame))
1165 command_line->AppendSwitch(switches::kChromeFrame);
1166
[email protected]718eab62011-10-05 21:16:521167 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451168 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301169 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1170 if (!user_data_dir.empty())
1171 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1172#if defined(OS_CHROMEOS)
1173 const std::string& login_profile =
[email protected]931d1042013-04-05 17:50:441174 browser_command_line.GetSwitchValueASCII(
1175 chromeos::switches::kLoginProfile);
[email protected]b80f68432011-05-02 17:22:301176 if (!login_profile.empty())
[email protected]931d1042013-04-05 17:50:441177 command_line->AppendSwitchASCII(
1178 chromeos::switches::kLoginProfile, login_profile);
[email protected]b80f68432011-05-02 17:22:301179#endif
1180
[email protected]f3b1a082011-11-18 00:34:301181 content::RenderProcessHost* process =
1182 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371183 if (process) {
1184 Profile* profile = Profile::FromBrowserContext(
1185 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131186 ExtensionService* extension_service =
1187 extensions::ExtensionSystem::Get(profile)->extension_service();
1188 if (extension_service) {
1189 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001190 if (process_map && process_map->Contains(process->GetID()))
1191 command_line->AppendSwitch(switches::kExtensionProcess);
1192 }
[email protected]b80f68432011-05-02 17:22:301193
[email protected]a8d851f82011-12-21 00:32:371194 PrefService* prefs = profile->GetPrefs();
1195 // Currently this pref is only registered if applied via a policy.
1196 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1197 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1198 // Turn this policy into a command line switch.
1199 command_line->AppendSwitch(switches::kDisable3DAPIs);
1200 }
[email protected]718eab62011-10-05 21:16:521201
[email protected]a8d851f82011-12-21 00:32:371202 // Disable client-side phishing detection in the renderer if it is
1203 // disabled in the Profile preferences or the browser process.
1204 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1205 !g_browser_process->safe_browsing_detection_service()) {
1206 command_line->AppendSwitch(
1207 switches::kDisableClientSidePhishingDetection);
1208 }
[email protected]0045b0f42012-07-26 11:52:081209
1210 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211211 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521212
1213 InstantService* instant_service =
1214 InstantServiceFactory::GetForProfile(profile);
1215 if (instant_service &&
1216 instant_service->IsInstantProcess(process->GetID()))
1217 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301218
[email protected]d5bcd06f2013-04-21 08:07:241219#if !defined(OS_CHROMEOS)
[email protected]970c63e2013-03-07 00:25:301220 SigninManager* signin_manager =
1221 SigninManagerFactory::GetForProfile(profile);
1222 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1223 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]d5bcd06f2013-04-21 08:07:241224#endif
[email protected]47c7ec82012-01-18 03:29:211225 }
[email protected]4287a3d2011-06-13 23:56:511226
[email protected]87552982012-11-02 17:21:401227 if (content::IsThreadedCompositingEnabled())
1228 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1229
[email protected]9a224572013-05-12 23:08:561230#if defined(ENABLE_MESSAGE_CENTER)
[email protected]16dc42452013-04-09 04:37:191231 if (message_center::IsRichNotificationEnabled())
1232 command_line->AppendSwitch(switches::kDisableHTMLNotifications);
[email protected]9a224572013-05-12 23:08:561233#endif
[email protected]16dc42452013-04-09 04:37:191234
[email protected]47c7ec82012-01-18 03:29:211235 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511236 static const char* const kSwitchNames[] = {
[email protected]e217c5632013-04-12 19:11:481237 autofill::switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511238 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481239 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511240 switches::kAllowScriptingGallery,
1241 switches::kAppsCheckoutURL,
1242 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311243 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511244 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501245 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531246 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111247 switches::kDisableScriptedPrintThrottling,
[email protected]e9cddd52013-03-23 17:37:531248 switches::kEnableAdview,
1249 switches::kEnableAdviewSrcAttribute,
[email protected]47c7ec82012-01-18 03:29:211250 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511251 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511252 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511253 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511254 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451255 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481256 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051257 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511258 switches::kEnableWatchdog,
[email protected]ac2e2acd2013-03-21 12:57:291259 switches::kExtensionsOnChromeURLs,
[email protected]4287a3d2011-06-13 23:56:511260 switches::kMemoryProfiling,
1261 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371262 switches::kNoJsRandomness,
[email protected]f45c5f32012-04-18 19:26:371263 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511264 switches::kPpapiFlashArgs,
1265 switches::kPpapiFlashInProcess,
1266 switches::kPpapiFlashPath,
1267 switches::kPpapiFlashVersion,
1268 switches::kProfilingAtStart,
1269 switches::kProfilingFile,
1270 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371271 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511272 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291273 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381274 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511275 };
1276
1277 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1278 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171279 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381280 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351281 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381282 switches::kEnableExperimentalExtensionApis,
1283 switches::kWhitelistedExtensionID,
1284 };
1285
1286 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1287 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511288 } else if (process_type == switches::kPluginProcess) {
1289 static const char* const kSwitchNames[] = {
[email protected]931d1042013-04-05 17:50:441290#if defined(OS_CHROMEOS)
1291 chromeos::switches::kLoginProfile,
1292#endif
[email protected]4287a3d2011-06-13 23:56:511293 switches::kMemoryProfiling,
1294 switches::kSilentDumpOnDCHECK,
1295 switches::kUserDataDir,
1296 };
1297
1298 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1299 arraysize(kSwitchNames));
1300 } else if (process_type == switches::kZygoteProcess) {
1301 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511302 switches::kUserDataDir, // Make logs go to the right file.
1303 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501304 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511305 switches::kPpapiFlashInProcess,
1306 switches::kPpapiFlashPath,
1307 switches::kPpapiFlashVersion,
1308 };
1309
1310 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1311 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111312 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001313 base::FilePath user_data_dir =
1314 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1315 if (!user_data_dir.empty())
1316 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111317 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1318 // because GPU is expected to be unreliable.
1319 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1320 !command_line->HasSwitch(switches::kDisableBreakpad))
1321 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301322 }
[email protected]6f08af82011-09-15 01:19:031323
1324 // The command line switch kEnableBenchmarking needs to be specified along
1325 // with the kEnableStatsTable switch to ensure that the stats table global
1326 // is initialized correctly.
1327 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1328 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301329}
1330
1331std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431332 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
[email protected]eabbfb12013-04-05 23:28:351333 return g_io_thread_application_locale.Get();
[email protected]b80f68432011-05-02 17:22:301334 return g_browser_process->GetApplicationLocale();
1335}
1336
[email protected]597a867b2011-11-18 18:31:201337std::string ChromeContentBrowserClient::GetAcceptLangs(
1338 content::BrowserContext* context) {
1339 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371340 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081341}
1342
[email protected]9ec0f452012-05-31 15:58:531343gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221344 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531345 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081346}
1347
[email protected]a2176792011-05-08 19:30:491348bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091349 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191350 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201351 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201353 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051354 return io_data->GetCookieSettings()->
1355 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491356}
1357
[email protected]ed24fad2011-05-10 22:44:011358bool ChromeContentBrowserClient::AllowGetCookie(
1359 const GURL& url,
1360 const GURL& first_party,
1361 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201362 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011363 int render_process_id,
1364 int render_view_id) {
1365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201366 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051367 bool allow = io_data->GetCookieSettings()->
1368 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011369
[email protected]8093a542011-05-13 07:29:321370 BrowserThread::PostTask(
1371 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031372 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431373 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011374 return allow;
1375}
1376
1377bool ChromeContentBrowserClient::AllowSetCookie(
1378 const GURL& url,
1379 const GURL& first_party,
1380 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201381 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011382 int render_process_id,
1383 int render_view_id,
1384 net::CookieOptions* options) {
1385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201386 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051387 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1388 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1389
[email protected]8093a542011-05-13 07:29:321390 BrowserThread::PostTask(
1391 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031392 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431393 render_view_id, url, first_party, cookie_line, *options,
1394 !allow));
[email protected]ed24fad2011-05-10 22:44:011395 return allow;
1396}
1397
[email protected]d5a19162011-06-30 18:51:541398bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201399 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201401 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431402 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1403 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261404
[email protected]bf510ed2012-06-05 08:31:431405 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1406 // Could we even support per-origin settings?
1407 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541408}
1409
[email protected]5c5a88e2011-11-12 00:45:351410bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351411 const GURL& url,
1412 const string16& name,
1413 const string16& display_name,
1414 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201415 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481416 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201418 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351419 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1420 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1421
[email protected]62151052012-02-01 18:40:481422 // Record access to database for potential display in UI.
1423 std::vector<std::pair<int, int> >::const_iterator i;
1424 for (i = render_views.begin(); i != render_views.end(); ++i) {
1425 BrowserThread::PostTask(
1426 BrowserThread::UI, FROM_HERE,
1427 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1428 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351429 }
1430
1431 return allow;
1432}
1433
1434bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351435 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201436 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481437 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201439 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351440 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1441 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1442
[email protected]62151052012-02-01 18:40:481443 // Record access to file system for potential display in UI.
1444 std::vector<std::pair<int, int> >::const_iterator i;
1445 for (i = render_views.begin(); i != render_views.end(); ++i) {
1446 BrowserThread::PostTask(
1447 BrowserThread::UI, FROM_HERE,
1448 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1449 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351450 }
1451
1452 return allow;
1453}
1454
[email protected]7c5ff9a2012-03-02 07:42:491455bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1456 const GURL& url,
1457 const string16& name,
1458 content::ResourceContext* context,
1459 const std::vector<std::pair<int, int> >& render_views) {
1460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1461 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1462 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1463 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1464
1465 // Record access to IndexedDB for potential display in UI.
1466 std::vector<std::pair<int, int> >::const_iterator i;
1467 for (i = render_views.begin(); i != render_views.end(); ++i) {
1468 BrowserThread::PostTask(
1469 BrowserThread::UI, FROM_HERE,
1470 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1471 i->first, i->second, url, name, !allow));
1472 }
1473
1474 return allow;
1475}
1476
[email protected]6133f922011-07-01 21:34:341477net::URLRequestContext*
1478ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201479 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421481 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201482 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341483 return io_data->extensions_request_context();
1484 }
1485
1486 return NULL;
1487}
1488
[email protected]317f96c92011-05-31 06:53:411489QuotaPermissionContext*
1490ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1491 return new ChromeQuotaPermissionContext();
1492}
1493
[email protected]848dd042011-06-04 18:24:031494void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171495 int render_process_id,
1496 int render_view_id,
1497 int cert_error,
1498 const net::SSLInfo& ssl_info,
1499 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021500 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031501 bool overridable,
[email protected]d9be47702012-05-16 03:41:221502 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171503 const base::Callback<void(bool)>& callback,
1504 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021505 if (resource_type != ResourceType::MAIN_FRAME) {
1506 // A sub-resource has a certificate error. The user doesn't really
1507 // have a context for making the right decision, so block the
1508 // request hard, without an info bar to allow showing the insecure
1509 // content.
1510 *cancel_request = true;
1511 return;
1512 }
1513
[email protected]f9034cf2011-07-21 12:43:411514 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131515 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171516 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411517 if (!tab) {
1518 NOTREACHED();
1519 return;
1520 }
1521 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501522 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301523 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011524 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1525 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411526 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171527 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411528 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171529 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411530 return;
1531 }
1532 }
1533
[email protected]1e87df32012-09-12 04:53:191534#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231535 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1536 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1537 if (captive_portal_tab_helper)
1538 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191539#endif
1540
[email protected]f9034cf2011-07-21 12:43:411541 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221542 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1543 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031544}
1545
[email protected]c99c442e2011-08-24 11:37:301546void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451547 int render_process_id,
1548 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401549 const net::HttpNetworkSession* network_session,
1550 net::SSLCertRequestInfo* cert_request_info,
1551 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131552 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451553 render_process_id, render_view_id);
1554 if (!tab) {
1555 NOTREACHED();
1556 return;
1557 }
1558
[email protected]6786bf402011-12-03 15:19:451559 GURL requesting_url("https://" + cert_request_info->host_and_port);
1560 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1561 << cert_request_info->host_and_port;
1562
[email protected]627e0512011-12-21 22:55:301563 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451564 scoped_ptr<Value> filter(
1565 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1566 requesting_url,
1567 requesting_url,
1568 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1569 std::string(), NULL));
1570
1571 if (filter.get()) {
1572 // Try to automatically select a client certificate.
1573 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1574 DictionaryValue* filter_dict =
1575 static_cast<DictionaryValue*>(filter.get());
1576
1577 const std::vector<scoped_refptr<net::X509Certificate> >&
1578 all_client_certs = cert_request_info->client_certs;
1579 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1580 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1581 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401582 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451583 return;
1584 }
1585 }
1586 } else {
1587 NOTREACHED();
1588 }
1589 }
1590
[email protected]11feec322012-09-18 03:58:521591 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1592 if (!ssl_tab_helper) {
1593 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451594 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141595 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401596 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451597 return;
1598 }
[email protected]11feec322012-09-18 03:58:521599 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401600 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451601}
1602
[email protected]3b455502012-12-11 18:22:581603void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451604 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581605 net::CertificateMimeType cert_type,
1606 const void* cert_data,
1607 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451608 int render_process_id,
1609 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581610 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1611 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451612}
1613
[email protected]dc73a7b2012-03-25 15:27:181614content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561615 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181616}
1617
[email protected]941623e2011-06-07 23:06:041618void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1619 const GURL& source_origin,
1620 int callback_context,
1621 int render_process_id,
1622 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111623#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021624 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1625 WebContents* contents =
1626 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1627 if (!contents) {
[email protected]941623e2011-06-07 23:06:041628 NOTREACHED();
1629 return;
1630 }
1631
[email protected]d0d9c3ee2012-06-19 03:07:021632 // Skip showing the infobar if the request comes from an extension, and that
1633 // extension has the 'notify' permission. (If the extension does not have the
1634 // permission, the user will still be prompted.)
1635 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]c7cd5942013-04-30 03:31:011636 ExtensionInfoMap* extension_info_map =
1637 extensions::ExtensionSystem::Get(profile)->info_map();
1638 DesktopNotificationService* notification_service =
1639 DesktopNotificationServiceFactory::GetForProfile(profile);
1640 const Extension* extension = NULL;
1641 if (extension_info_map) {
1642 ExtensionSet extensions;
1643 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1644 source_origin, render_process_id,
1645 extensions::APIPermission::kNotification, &extensions);
1646 for (ExtensionSet::const_iterator iter = extensions.begin();
1647 iter != extensions.end(); ++iter) {
1648 if (notification_service->IsExtensionEnabled((*iter)->id())) {
1649 extension = *iter;
1650 break;
1651 }
1652 }
1653 }
[email protected]eb4832a2012-12-08 01:57:521654 RenderViewHost* rvh =
1655 RenderViewHost::FromID(render_process_id, render_view_id);
1656 if (IsExtensionWithPermissionOrSuggestInConsole(
1657 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021658 if (rvh)
1659 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1660 return;
1661 }
1662
[email protected]c7cd5942013-04-30 03:31:011663 notification_service->RequestPermission(source_origin, render_process_id,
[email protected]d0d9c3ee2012-06-19 03:07:021664 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111665#else
1666 NOTIMPLEMENTED();
1667#endif
[email protected]941623e2011-06-07 23:06:041668}
1669
1670WebKit::WebNotificationPresenter::Permission
1671 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021672 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201673 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021674 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111675#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041676 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201677 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]941623e2011-06-07 23:06:041678
[email protected]c7cd5942013-04-30 03:31:011679 DesktopNotificationService* notification_service =
1680 io_data->GetNotificationService();
1681 if (notification_service) {
1682 ExtensionInfoMap* extension_info_map = io_data->GetExtensionInfoMap();
1683 ExtensionSet extensions;
1684 extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
1685 source_origin, render_process_id,
1686 extensions::APIPermission::kNotification, &extensions);
1687 for (ExtensionSet::const_iterator iter = extensions.begin();
1688 iter != extensions.end(); ++iter) {
1689 if (notification_service->IsExtensionEnabled((*iter)->id()))
1690 return WebKit::WebNotificationPresenter::PermissionAllowed;
1691 }
1692
1693 return notification_service->HasPermission(source_origin);
1694 }
1695
1696 return WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111697#else
1698 return WebKit::WebNotificationPresenter::PermissionAllowed;
1699#endif
[email protected]941623e2011-06-07 23:06:041700}
1701
1702void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171703 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041704 int render_process_id,
1705 int render_view_id,
1706 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111707#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041708 RenderViewHost* rvh = RenderViewHost::FromID(
1709 render_process_id, render_view_id);
1710 if (!rvh) {
1711 NOTREACHED();
1712 return;
1713 }
1714
[email protected]9f76c1e2012-03-05 15:15:581715 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301716 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041717 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371718 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041719 service->ShowDesktopNotification(
1720 params, render_process_id, render_view_id,
1721 worker ? DesktopNotificationService::WorkerNotification :
1722 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111723#else
1724 NOTIMPLEMENTED();
1725#endif
[email protected]941623e2011-06-07 23:06:041726}
1727
1728void ChromeContentBrowserClient::CancelDesktopNotification(
1729 int render_process_id,
1730 int render_view_id,
1731 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111732#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041733 RenderViewHost* rvh = RenderViewHost::FromID(
1734 render_process_id, render_view_id);
1735 if (!rvh) {
1736 NOTREACHED();
1737 return;
1738 }
1739
[email protected]9f76c1e2012-03-05 15:15:581740 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301741 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041742 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371743 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041744 service->CancelDesktopNotification(
1745 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111746#else
1747 NOTIMPLEMENTED();
1748#endif
[email protected]941623e2011-06-07 23:06:041749}
1750
[email protected]9f3fba52011-06-08 20:37:191751bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351752 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021753 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191754 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201755 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011756 int render_process_id,
1757 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191758 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011759
1760 *no_javascript_access = false;
1761
[email protected]9f3fba52011-06-08 20:37:191762 // If the opener is trying to create a background window but doesn't have
1763 // the appropriate permission, fail the attempt.
1764 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201765 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531766 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1767
[email protected]03b6d552012-03-29 04:03:011768 if (!map->SecurityOriginHasAPIPermission(
1769 source_origin,
1770 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061771 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011772 return false;
1773 }
1774
[email protected]7b54ca02012-03-02 18:06:531775 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1776 // return a recently installed Extension even if this CanCreateWindow call
1777 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011778 // because the permission check above would have caused an early return
1779 // already. We must use the full URL to find hosted apps, though, and not
1780 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531781 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351782 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291783 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011784 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191785 }
[email protected]056efdc2013-04-06 00:14:531786
1787 // No new browser window (popup or tab) in app mode.
1788 if (container_type == WINDOW_CONTAINER_TYPE_NORMAL &&
1789 chrome::IsRunningInForcedAppMode()) {
1790 return false;
1791 }
1792
[email protected]9f3fba52011-06-08 20:37:191793 return true;
1794}
1795
1796std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201797 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191798 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1799 // Check if it's an extension-created worker, in which case we want to use
1800 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201801 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191802 const Extension* extension =
1803 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1804 return extension ? extension->name() : std::string();
1805}
1806
[email protected]99907362012-01-11 05:41:401807void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1808 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171809}
1810
[email protected]7a06d282013-05-03 04:39:331811// TODO(tommi): Rename from Get to Create.
[email protected]c52b2892012-03-07 11:01:021812content::SpeechRecognitionManagerDelegate*
1813 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321814#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021815 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321816#else
1817 return NULL;
1818#endif
[email protected]66cfec62012-02-24 17:57:511819}
1820
[email protected]ae6e9912011-07-27 01:18:281821net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1822 return g_browser_process->net_log();
1823}
1824
[email protected]32538d92011-08-25 00:09:231825AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1826 return new ChromeAccessTokenStore();
1827}
1828
[email protected]dbae6b02011-06-29 23:51:411829bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011830 return true;
[email protected]dbae6b02011-06-29 23:51:411831}
1832
[email protected]64d69de42012-02-06 00:19:541833void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321834 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061835 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581836 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061837 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061838
[email protected]f3986f82012-01-03 20:00:061839 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541840 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061841 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541842 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061843 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541844 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061845 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541846 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061847 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541848 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061849 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541850 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031851 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1852 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061853
[email protected]64d69de42012-02-06 00:19:541854 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401855 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541856 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401857 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541858 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401859 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541860 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401861 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061862
[email protected]ddf72142012-05-22 04:52:401863 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061864
[email protected]64d69de42012-02-06 00:19:541865 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401866 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541867 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061868 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541869 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061870 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1871 const DictionaryValue* inspector_settings =
1872 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1873 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181874 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1875 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061876 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181877 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541878 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181879 std::make_pair(iter.key(), value));
1880 }
[email protected]f3986f82012-01-03 20:00:061881 }
1882 }
[email protected]64d69de42012-02-06 00:19:541883 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061884
[email protected]ddf72142012-05-22 04:52:401885 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541886 web_prefs->javascript_enabled = false;
1887 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1888 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401889 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541890 web_prefs->plugins_enabled = false;
1891 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1892 web_prefs->java_enabled = false;
1893 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401894 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061895
[email protected]64d69de42012-02-06 00:19:541896 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1897 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061898
[email protected]64d69de42012-02-06 00:19:541899 web_prefs->memory_info_enabled =
1900 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1901 web_prefs->allow_displaying_insecure_content =
1902 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1903 web_prefs->allow_running_insecure_content =
1904 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321905#if defined(OS_ANDROID)
1906 web_prefs->font_scale_factor =
1907 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1908 web_prefs->force_enable_zoom =
1909 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
[email protected]0b60abd2013-03-13 16:34:451910#if defined(GOOGLE_TV)
1911 web_prefs->user_gesture_required_for_media_playback = false;
1912#endif
[email protected]d3b935f2012-10-19 23:14:321913#endif
[email protected]5c915252013-05-07 13:15:391914
[email protected]9d06d88d2012-02-23 22:37:081915 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]5c915252013-05-07 13:15:391916#if defined(OS_CHROMEOS)
1917 // Enable password echo during OOBE when keyboard driven flag is set.
1918 if (chromeos::UserManager::IsInitialized() &&
1919 !chromeos::UserManager::Get()->IsUserLoggedIn() &&
1920 !chromeos::StartupUtils::IsOobeCompleted()) {
1921 bool keyboard_driven_oobe = false;
1922 chromeos::system::StatisticsProvider::GetInstance()->GetMachineFlag(
[email protected]e8f3f9982013-05-10 20:59:531923 chromeos::kOemKeyboardDrivenOobeKey, &keyboard_driven_oobe);
[email protected]5c915252013-05-07 13:15:391924 if (keyboard_driven_oobe)
1925 web_prefs->password_echo_enabled = true;
1926 }
1927#endif
[email protected]f3986f82012-01-03 20:00:061928
[email protected]46f8e742013-05-03 18:37:141929#if defined(OS_ANDROID)
1930 web_prefs->user_style_sheet_enabled = false;
1931#else
[email protected]64d69de42012-02-06 00:19:541932 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151933 UserStyleSheetWatcher* user_style_sheet_watcher =
1934 UserStyleSheetWatcherFactory::GetForProfile(profile);
1935 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541936 web_prefs->user_style_sheet_enabled = true;
1937 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151938 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541939 } else {
1940 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061941 }
[email protected]46f8e742013-05-03 18:37:141942#endif
[email protected]f3986f82012-01-03 20:00:061943
[email protected]cfadadd2013-04-03 04:43:021944 web_prefs->asynchronous_spell_checking_enabled = true;
1945 web_prefs->unified_textchecker_enabled = true;
[email protected]dd5d0fb2012-01-18 03:37:571946
[email protected]64d69de42012-02-06 00:19:541947 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061948 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541949 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061950 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541951 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061952 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1953
1954 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541955 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061956 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541957 web_prefs->default_encoding);
1958 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401959 prefs->ClearPref(prefs::kDefaultCharset);
1960 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061961 }
[email protected]64d69de42012-02-06 00:19:541962 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061963
[email protected]88ecf66d2012-12-11 22:53:471964 if (content::IsForceCompositingModeEnabled())
1965 web_prefs->force_compositing_mode = true;
1966
[email protected]299d7f12012-05-23 05:31:151967 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
[email protected]cb2edf22013-04-01 20:25:231968 extensions::ViewType view_type = extensions::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131969 ExtensionService* service =
1970 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061971 if (service) {
[email protected]1bc28312012-11-08 08:31:531972 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1973 const Extension* extension = service->extensions()->GetByID(url.host());
1974 // Ensure that we are only granting extension preferences to URLs with
1975 // the correct scheme. Without this check, chrome-guest:// schemes used by
1976 // webview tags as well as hosts that happen to match the id of an
1977 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421978 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531979 extension_webkit_preferences::SetPreferences(
1980 extension, view_type, web_prefs);
1981 }
[email protected]f3986f82012-01-03 20:00:061982 }
1983
[email protected]cb2edf22013-04-01 20:25:231984 if (view_type == extensions::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541985 web_prefs->allow_scripts_to_close_windows = true;
[email protected]cb2edf22013-04-01 20:25:231986 } else if (view_type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061987 // Disable all kinds of acceleration for background pages.
1988 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541989 web_prefs->force_compositing_mode = false;
1990 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061991 }
[email protected]2e21fe292012-03-02 22:52:321992
1993#if defined(FILE_MANAGER_EXTENSION)
1994 // Override the default of suppressing HW compositing for WebUI pages for the
1995 // file manager, which is implemented using WebUI but wants HW acceleration
1996 // for video decode & render.
1997 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1998 web_prefs->accelerated_compositing_enabled = true;
1999 web_prefs->accelerated_2d_canvas_enabled = true;
2000 }
2001#endif
[email protected]181a95ee2011-07-12 19:26:362002}
2003
2004void ChromeContentBrowserClient::UpdateInspectorSetting(
2005 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:062006 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:582007 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:062008 DictionaryPrefUpdate update(
2009 Profile::FromBrowserContext(browser_context)->GetPrefs(),
2010 prefs::kWebKitInspectorSettings);
2011 DictionaryValue* inspector_settings = update.Get();
2012 inspector_settings->SetWithoutPathExpansion(key,
2013 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:362014}
2015
[email protected]b8148ac2011-07-13 22:03:252016void ChromeContentBrowserClient::BrowserURLHandlerCreated(
2017 BrowserURLHandler* handler) {
2018 // Add the default URL handlers.
2019 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
2020 BrowserURLHandler::null_handler());
2021 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
2022 &ExtensionWebUI::HandleChromeURLOverrideReverse);
2023
[email protected]b3adbd02011-11-30 22:23:272024 // about: handler. Must come before chrome: handler, since it will
2025 // rewrite about: urls to chrome: URLs and then expect chrome: to
2026 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:252027 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
2028 BrowserURLHandler::null_handler());
2029 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:242030 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:252031}
2032
2033void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372034 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582035 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472036 BrowsingDataRemover* remover =
2037 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:552038 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
2039 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252040 // BrowsingDataRemover takes care of deleting itself when done.
2041}
2042
2043void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:372044 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:582045 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:472046 BrowsingDataRemover* remover =
2047 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:232048 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:552049 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:252050 // BrowsingDataRemover takes care of deleting itself when done.
2051}
2052
[email protected]650b2d52013-02-10 03:41:452053base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:322054 return download_util::GetDefaultDownloadDirectory();
2055}
2056
[email protected]c9b6eb62011-10-18 20:49:392057std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
2058 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
2059}
2060
[email protected]b7631cc2012-09-15 05:08:382061void ChromeContentBrowserClient::DidCreatePpapiPlugin(
2062 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:542063#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:382064 browser_host->GetPpapiHost()->AddHostFactoryFilter(
2065 scoped_ptr<ppapi::host::HostFactory>(
2066 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:542067#endif
[email protected]b7631cc2012-09-15 05:08:382068}
2069
[email protected]0c7193742012-11-07 19:05:032070content::BrowserPpapiHost*
2071 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
2072 int plugin_process_id) {
[email protected]f3b357692013-03-22 05:16:132073 BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER);
[email protected]0c7193742012-11-07 19:05:032074 while (!iter.Done()) {
2075 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
2076 if (host->process() &&
2077 host->process()->GetData().id == plugin_process_id) {
2078 // Found the plugin.
2079 return host->browser_ppapi_host();
2080 }
2081 ++iter;
2082 }
2083 return NULL;
2084}
2085
[email protected]7b38b192013-03-23 18:39:312086bool ChromeContentBrowserClient::SupportsBrowserPlugin(
2087 content::BrowserContext* browser_context, const GURL& site_url) {
2088 if (CommandLine::ForCurrentProcess()->HasSwitch(
2089 switches::kEnableBrowserPluginForAllViewTypes))
2090 return true;
2091
2092 Profile* profile = Profile::FromBrowserContext(browser_context);
2093 ExtensionService* service =
2094 extensions::ExtensionSystem::Get(profile)->extension_service();
2095 if (!service)
2096 return false;
2097
2098 const Extension* extension = service->extensions()->
2099 GetExtensionOrAppByURL(ExtensionURLInfo(site_url));
2100 if (!extension)
2101 return false;
2102
[email protected]c2d2f102013-04-29 16:42:582103 return extension->HasAPIPermission(APIPermission::kWebView) ||
2104 extension->HasAPIPermission(APIPermission::kAdView);
[email protected]7b38b192013-03-23 18:39:312105}
2106
[email protected]38cd8f7f2012-06-15 22:06:072107bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:582108 content::BrowserContext* browser_context,
2109 const GURL& url,
2110 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:292111 if (!url.is_valid())
2112 return false;
2113
2114 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:422115 if (url.SchemeIs(extensions::kExtensionScheme) &&
[email protected]b71313232013-05-06 06:16:292116 HostIsInSet(host, allowed_socket_origins_)) {
[email protected]a658d452012-03-02 12:45:292117 return true;
[email protected]885c0e92012-11-13 20:27:422118 }
[email protected]a658d452012-03-02 12:45:292119
[email protected]9a5940d2012-04-27 19:16:232120 Profile* profile = Profile::FromBrowserContext(browser_context);
2121 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:192122 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:132123 extensions::ExtensionSystem::Get(profile)->extension_service();
2124 if (extension_service) {
2125 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:232126 GetExtensionOrAppByURL(ExtensionURLInfo(url));
2127 }
2128
[email protected]b71313232013-05-06 06:16:292129 // Check the modules that are imported by this extension to see if any of them
2130 // is whitelisted.
2131 if (extension) {
2132 const std::vector<extensions::SharedModuleInfo::ImportInfo>& imports =
2133 extensions::SharedModuleInfo::GetImports(extension);
2134 std::vector<extensions::SharedModuleInfo::ImportInfo>::const_iterator it;
2135 for (it = imports.begin(); it != imports.end(); ++it) {
2136 const Extension* imported_extension = extension_service->
2137 GetExtensionById(it->extension_id, false);
2138 if (imported_extension &&
2139 extensions::SharedModuleInfo::IsSharedModule(imported_extension) &&
2140 HostIsInSet(it->extension_id, allowed_socket_origins_)) {
2141 return true;
2142 }
2143 }
2144 }
2145
[email protected]f237c0f2012-03-10 07:49:102146 // Need to check this now and not on construction because otherwise it won't
2147 // work with browser_tests.
2148 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2149 std::string allowed_list =
2150 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:232151 if (allowed_list == "*") {
2152 // The wildcard allows socket API only for packaged and platform apps.
2153 return extension &&
[email protected]1d5e58b2013-01-31 08:41:402154 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
2155 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:232156 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:392157 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:102158 while (t.GetNext()) {
2159 if (t.token() == host)
2160 return true;
2161 }
2162 }
2163
[email protected]a658d452012-03-02 12:45:292164 return false;
[email protected]e461da2f2012-02-16 19:06:402165}
2166
[email protected]650b2d52013-02-10 03:41:452167base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2168 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142169 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2170 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2171}
2172
[email protected]a28e3302013-02-03 03:50:432173ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2174 WebContents* web_contents) {
2175 return new ChromeSelectFilePolicy(web_contents);
2176}
2177
[email protected]7d9424702013-04-14 13:14:162178void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2179 std::vector<std::string>* additional_allowed_schemes) {
2180 ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem(
2181 additional_allowed_schemes);
2182 additional_allowed_schemes->push_back(kChromeUIScheme);
2183 additional_allowed_schemes->push_back(extensions::kExtensionScheme);
2184}
2185
[email protected]02250952013-04-24 23:52:532186void ChromeContentBrowserClient::GetAdditionalFileSystemMountPointProviders(
2187 const base::FilePath& storage_partition_path,
2188 ScopedVector<fileapi::FileSystemMountPointProvider>* additional_providers) {
2189#if !defined(OS_ANDROID)
2190 additional_providers->push_back(new MediaFileSystemMountPointProvider(
2191 storage_partition_path));
2192#endif
2193}
2194
[email protected]e60c0232011-11-11 19:56:352195#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182196void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2197 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382198 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082199 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392200#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452201 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392202 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2203 DCHECK(!data_path.empty());
2204
2205 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452206 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392207 base::PlatformFile f =
2208 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2209 DCHECK(f != base::kInvalidPlatformFileValue);
2210 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2211 FileDescriptor(f, true)));
2212
[email protected]650b2d52013-02-10 03:41:452213 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392214 data_path.AppendASCII("chrome_100_percent.pak");
2215 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2216 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372217 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392218 FileDescriptor(f, true)));
2219
2220 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452221 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392222 GetLocaleFilePath(locale, false);
2223 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2224 DCHECK(f != base::kInvalidPlatformFileValue);
2225 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2226 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382227
[email protected]650b2d52013-02-10 03:41:452228 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372229 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2230 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2231 DCHECK(f != base::kInvalidPlatformFileValue);
2232 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2233 FileDescriptor(f, true)));
2234
[email protected]40da3e0c2012-10-24 22:03:382235#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432236 if (IsCrashReporterEnabled()) {
2237 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2238 if (f == base::kInvalidPlatformFileValue) {
2239 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2240 "be disabled for this process.";
2241 } else {
2242 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2243 FileDescriptor(f, true)));
2244 }
[email protected]40da3e0c2012-10-24 22:03:382245 }
2246#endif // defined(USE_LINUX_BREAKPAD)
2247
2248#else
2249 int crash_signal_fd = GetCrashSignalFD(command_line);
2250 if (crash_signal_fd >= 0) {
2251 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2252 FileDescriptor(crash_signal_fd,
2253 false)));
2254 }
[email protected]29699c22012-10-03 23:57:392255#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302256}
[email protected]e60c0232011-11-11 19:56:352257#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302258
[email protected]4a65826d2011-08-25 16:04:012259#if defined(OS_WIN)
2260const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2261 return chrome::kBrowserResourcesDll;
2262}
[email protected]34f48682013-03-20 00:30:182263
2264void ChromeContentBrowserClient::PreSpawnRenderer(
2265 sandbox::TargetPolicy* policy,
2266 bool* success) {
2267 // This code is duplicated in nacl_exe_win_64.cc.
2268 // Allow the server side of a pipe restricted to the "chrome.nacl."
2269 // namespace so that it cannot impersonate other system or other chrome
2270 // service pipes.
2271 sandbox::ResultCode result = policy->AddRule(
2272 sandbox::TargetPolicy::SUBSYS_NAMED_PIPES,
2273 sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY,
2274 L"\\\\.\\pipe\\chrome.nacl.*");
2275 if (result != sandbox::SBOX_ALL_OK) {
2276 *success = false;
2277 return;
2278 }
2279
2280 // Renderers need to send named pipe handles and shared memory
2281 // segment handles to NaCl loader processes.
2282 result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_HANDLES,
2283 sandbox::TargetPolicy::HANDLES_DUP_ANY,
2284 L"File");
2285 if (result != sandbox::SBOX_ALL_OK) {
2286 *success = false;
2287 return;
2288 }
2289}
[email protected]4a65826d2011-08-25 16:04:012290#endif
2291
[email protected]37a72af2011-06-13 05:42:012292#if defined(USE_NSS)
2293crypto::CryptoModuleBlockingPasswordDelegate*
2294 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2295 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292296 return chrome::NewCryptoModuleBlockingDialogDelegate(
2297 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012298}
2299#endif
2300
[email protected]d977f9c2011-03-14 16:10:262301} // namespace chrome