blob: d7bca4e28036dc234e1f0294bc5163c5b7ea8927 [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]29699c22012-10-03 23:57:3913#include "base/path_service.h"
[email protected]3853a4c2013-02-11 17:15:5714#include "base/prefs/pref_service.h"
[email protected]f4ebe772013-02-02 00:21:3915#include "base/strings/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0616#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3017#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2518#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3019#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4720#include "chrome/browser/browsing_data/browsing_data_helper.h"
21#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1222#include "chrome/browser/character_encoding.h"
[email protected]43535512013-02-20 20:41:4123#include "chrome/browser/chrome_net_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4124#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5625#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0526#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4527#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3228#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0829#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3230#include "chrome/browser/download/download_util.h"
[email protected]24665682013-02-25 20:59:3831#include "chrome/browser/extensions/activity_log.h"
[email protected]2b33dcd02012-03-18 01:34:1632#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0633#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0434#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3335#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2636#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0837#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2538#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0639#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]40404bc2012-07-25 17:40:4940#include "chrome/browser/extensions/message_handler.h"
[email protected]eb4832a2012-12-08 01:57:5241#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2342#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1243#include "chrome/browser/google/google_util.h"
[email protected]c5dec6292013-01-25 04:54:5244#include "chrome/browser/instant/instant_service.h"
45#include "chrome/browser/instant/instant_service_factory.h"
[email protected]11158e2d2013-02-01 02:31:5646#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]0c7193742012-11-07 19:05:0347#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2848#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0449#include "chrome/browser/notifications/desktop_notification_service.h"
50#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4251#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5652#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]f3986f82012-01-03 20:00:0653#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4154#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5055#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0756#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4157#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1458#include "chrome/browser/printing/printing_message_filter.h"
59#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3260#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0661#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1462#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3363#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]b7631cc2012-09-15 05:08:3864#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]05fcf982011-04-19 00:44:1465#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]970c63e2013-03-07 00:25:3066#include "chrome/browser/signin/signin_manager.h"
67#include "chrome/browser/signin/signin_manager_factory.h"
[email protected]c52b2892012-03-07 11:01:0268#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4669#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5870#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0371#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5272#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4573#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5474#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4375#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]7c60f5042013-02-14 03:39:3276#include "chrome/browser/ui/search/search.h"
[email protected]b5d73422012-06-02 23:46:4477#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5078#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]970c63e2013-03-07 00:25:3079#include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
[email protected]f3986f82012-01-03 20:00:0680#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1581#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5382#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3083#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0184#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1485#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3086#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2987#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0488#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3889#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4490#include "chrome/common/extensions/extension_set.h"
[email protected]157cc902012-11-02 06:31:5891#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3492#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1293#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3894#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0995#include "chrome/common/url_constants.h"
[email protected]75fee372013-03-06 00:42:4496#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:4397#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3098#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:3899#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:31100#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:03101#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:59102#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36103#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30104#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33105#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05106#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33107#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19108#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10109#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43110#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18111#include "content/public/common/content_descriptors.h"
[email protected]885c0e92012-11-13 20:27:42112#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39113#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23114#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53115#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58116#include "net/base/mime_util.h"
[email protected]7a593db2012-02-13 21:19:40117#include "net/base/ssl_cert_request_info.h"
[email protected]5b9bc352012-07-18 13:13:34118#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06119#include "net/cookies/cookie_options.h"
[email protected]b7631cc2012-09-15 05:08:38120#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39121#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08122#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36123#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04124#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26125
[email protected]b48c9182011-10-26 18:03:30126#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38127#include "chrome/browser/chrome_browser_main_win.h"
128#elif defined(OS_MACOSX)
129#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56130#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30131#elif defined(OS_CHROMEOS)
132#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49133#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26134#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30135#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09136#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38137#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09138#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39139#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30140#elif defined(OS_POSIX)
141#include "chrome/browser/chrome_browser_main_posix.h"
142#endif
143
[email protected]6653c192012-04-10 22:52:44144#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30145#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12146#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43147#endif
[email protected]b80f68432011-05-02 17:22:30148
[email protected]1e87df32012-09-12 04:53:19149#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
150#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
151#endif
152
[email protected]29699c22012-10-03 23:57:39153#if defined(OS_ANDROID)
154#include "ui/base/ui_base_paths.h"
155#endif
156
[email protected]37a72af2011-06-13 05:42:01157#if defined(USE_NSS)
158#include "chrome/browser/ui/crypto_module_password_dialog.h"
159#endif
160
[email protected]c7abd422012-09-25 00:20:08161using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47162using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03163using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39164using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31165using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59166using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08167using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00168using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11169using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33170using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13171using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06172using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34173using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40174using extensions::Manifest;
[email protected]6717bf272012-05-11 23:31:25175using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39176
[email protected]c5dbef02011-05-13 05:06:09177namespace {
178
[email protected]e461da2f2012-02-16 19:06:40179const char* kPredefinedAllowedSocketOrigins[] = {
180 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18181 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45182 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
183 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
184 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
185 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35186 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54187 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
188 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
189 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
190 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
191 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
192 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38193 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58194 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
195 "iabmpiboiopbgfabjmgeedhcmjenhbla" // see crbug.com/165080
[email protected]e461da2f2012-02-16 19:06:40196};
197
[email protected]f8f93eb2012-09-25 03:06:24198// Returns a copy of the given url with its host set to given host and path set
199// to given path. Other parts of the url will be the same.
200GURL ReplaceURLHostAndPath(const GURL& url,
201 const std::string& host,
202 const std::string& path) {
203 url_canon::Replacements<char> replacements;
204 replacements.SetHost(host.c_str(),
205 url_parse::Component(0, host.length()));
206 replacements.SetPath(path.c_str(),
207 url_parse::Component(0, path.length()));
208 return url.ReplaceComponents(replacements);
209}
210
211// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
212GURL AddUberHost(const GURL& url) {
213 const std::string uber_host = chrome::kChromeUIUberHost;
214 const std::string new_path = url.host() + url.path();
215
216 return ReplaceURLHostAndPath(url, uber_host, new_path);
217}
218
[email protected]045bf7c2012-09-28 20:27:36219// If url->host() is "chrome" and url->path() has characters other than the
220// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
221// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24222bool RemoveUberHost(GURL* url) {
223 if (url->host() != chrome::kChromeUIUberHost)
224 return false;
225
[email protected]045bf7c2012-09-28 20:27:36226 if (url->path().empty() || url->path() == "/")
227 return false;
228
[email protected]f8f93eb2012-09-25 03:06:24229 const std::string old_path = url->path();
230
231 const std::string::size_type separator = old_path.find('/', 1);
232 std::string new_host;
233 std::string new_path;
234 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36235 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24236 } else {
237 new_host = old_path.substr(1, separator - 1);
238 new_path = old_path.substr(separator);
239 }
240
241 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
242
243 return true;
244}
245
[email protected]b8148ac2011-07-13 22:03:25246// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42247bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24248 // Do not handle special URLs such as "about:foo"
249 if (!url->host().empty()) {
250 const GURL chrome_url = AddUberHost(*url);
251
252 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
253 // be called.
254 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
255 browser_context, chrome_url))
256 return true;
257 }
258
[email protected]863f70a2012-01-27 02:05:50259 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
260 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25261 return false;
262
[email protected]fe69558d2012-03-12 11:34:49263#if defined(OS_CHROMEOS)
264 // Special case : in ChromeOS in Guest mode bookmarks and history are
265 // disabled for security reasons. New tab page explains the reasons, so
266 // we redirect user to new tab page.
267 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
268 if (url->SchemeIs(chrome::kChromeUIScheme) &&
269 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
270 url->DomainIs(chrome::kChromeUIHistoryHost))) {
271 // Rewrite with new tab URL
272 *url = GURL(chrome::kChromeUINewTabURL);
273 }
274 }
275#endif
276
[email protected]b8148ac2011-07-13 22:03:25277 // Special case the new tab page. In older versions of Chrome, the new tab
278 // page was hosted at chrome-internal:<blah>. This might be in people's saved
279 // sessions or bookmarks, so we say any URL with that scheme triggers the new
280 // tab page.
281 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
282 // Rewrite it with the proper new tab URL.
283 *url = GURL(chrome::kChromeUINewTabURL);
284 }
285
286 return true;
287}
288
[email protected]f8f93eb2012-09-25 03:06:24289// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
290// "chrome://foo/".
291bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
292 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
293 return false;
294
295 return RemoveUberHost(url);
296}
297
[email protected]8d3132f62011-10-12 07:13:42298// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
299// below. Extension, and isolated apps require different privileges to be
300// granted to their RenderProcessHosts. This classification allows us to make
301// sure URLs are served by hosts with the right set of privileges.
302enum RenderProcessHostPrivilege {
303 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45304 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42305 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45306 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42307};
308
309RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
310 const GURL& url,
311 ExtensionService* service) {
312 // Default to a normal renderer cause it is lower privileged. This should only
313 // occur if the URL on a site instance is either malformed, or uninitialized.
314 // If it is malformed, then there is no need for better privileges anyways.
315 // If it is uninitialized, but eventually settles on being an a scheme other
316 // than normal webrenderer, the navigation logic will correct us out of band
317 // anyways.
318 if (!url.is_valid())
319 return PRIV_NORMAL;
320
[email protected]885c0e92012-11-13 20:27:42321 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44322 const Extension* extension =
323 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45324 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42325 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45326 if (extension && extension->is_hosted_app())
327 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42328
329 return PRIV_EXTENSION;
330 }
331
332 return PRIV_NORMAL;
333}
334
335RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30336 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46337 extensions::ProcessMap* process_map,
338 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46339 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30340 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46341 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21342 return PRIV_NORMAL;
343
[email protected]6f371442011-11-09 06:45:46344 for (std::set<std::string>::iterator iter = extension_ids.begin();
345 iter != extension_ids.end(); ++iter) {
346 const Extension* extension = service->GetExtensionById(*iter, false);
347 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42348 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45349 if (extension && extension->is_hosted_app())
350 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42351 }
352
[email protected]676f6ab2011-10-19 20:23:21353 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42354}
355
[email protected]6786bf402011-12-03 15:19:45356bool CertMatchesFilter(const net::X509Certificate& cert,
357 const base::DictionaryValue& filter) {
358 // TODO(markusheintz): This is the minimal required filter implementation.
359 // Implement a better matcher.
360
361 // An empty filter matches any client certificate since no requirements are
362 // specified at all.
363 if (filter.empty())
364 return true;
365
366 std::string common_name;
367 if (filter.GetString("ISSUER.CN", &common_name) &&
368 (cert.issuer().common_name == common_name)) {
369 return true;
370 }
371 return false;
372}
373
[email protected]f3986f82012-01-03 20:00:06374// Fills |map| with the per-script font prefs under path |map_name|.
375void FillFontFamilyMap(const PrefService* prefs,
376 const char* map_name,
377 WebPreferences::ScriptFontFamilyMap* map) {
378 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
379 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
380 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
381 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23382 if (!font_family.empty())
383 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06384 }
385}
386
[email protected]a1733df2012-06-22 11:24:18387#if defined(OS_POSIX) && !defined(OS_MACOSX)
388int GetCrashSignalFD(const CommandLine& command_line) {
389 if (command_line.HasSwitch(switches::kExtensionProcess)) {
390 ExtensionCrashHandlerHostLinux* crash_handler =
391 ExtensionCrashHandlerHostLinux::GetInstance();
392 return crash_handler->GetDeathSignalSocket();
393 }
394
395 std::string process_type =
396 command_line.GetSwitchValueASCII(switches::kProcessType);
397
398 if (process_type == switches::kRendererProcess)
399 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
400
401 if (process_type == switches::kPluginProcess)
402 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
403
404 if (process_type == switches::kPpapiPluginProcess)
405 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
406
407 if (process_type == switches::kGpuProcess)
408 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
409
410 return -1;
411}
412#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
413
[email protected]7c60f5042013-02-14 03:39:32414// Transforms the input |url| into its "effective URL". The returned URL
[email protected]c5dec6292013-01-25 04:54:52415// facilitates grouping process-per-site. The |url| is transformed, for
416// example, from
417//
418// https://www.google.com/search?espv=1&q=tractors
419//
[email protected]7c60f5042013-02-14 03:39:32420// to the effective URL
[email protected]c5dec6292013-01-25 04:54:52421//
422// chrome-search://www.google.com/search?espv=1&q=tractors
423//
424// Notice the scheme change.
[email protected]7c60f5042013-02-14 03:39:32425//
426// If the input is already an effective URL then that same URL is returned.
427GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
428 CHECK(chrome::search::ShouldAssignURLToInstantRenderer(url, profile))
429 << "Error granting Instant access.";
[email protected]c5dec6292013-01-25 04:54:52430
431 if (url.SchemeIs(chrome::kChromeSearchScheme))
432 return url;
433
434 GURL effective_url(url);
435
436 // Replace the scheme with "chrome-search:".
437 url_canon::Replacements<char> replacements;
438 std::string search_scheme(chrome::kChromeSearchScheme);
439 replacements.SetScheme(search_scheme.data(),
440 url_parse::Component(0, search_scheme.length()));
441 effective_url = effective_url.ReplaceComponents(replacements);
442 return effective_url;
443}
444
[email protected]970c63e2013-03-07 00:25:30445GURL GetEffectiveURLForSignin(const GURL& url) {
446 CHECK(SigninManager::IsWebBasedSigninFlowURL(url));
447
448 GURL effective_url(SigninManager::kChromeSigninEffectiveSite);
449 GURL::Replacements replacements;
450 replacements.SetPathStr(url.path());
451 effective_url = effective_url.ReplaceComponents(replacements);
452 return effective_url;
453}
454
[email protected]9dbfff12011-07-01 19:37:07455} // namespace
[email protected]c5dbef02011-05-13 05:06:09456
[email protected]d977f9c2011-03-14 16:10:26457namespace chrome {
458
[email protected]e461da2f2012-02-16 19:06:40459ChromeContentBrowserClient::ChromeContentBrowserClient() {
460 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
461 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40462}
463
464ChromeContentBrowserClient::~ChromeContentBrowserClient() {
465}
466
[email protected]bca18382012-06-25 19:15:23467// static
[email protected]c753f142013-02-10 13:14:04468void ChromeContentBrowserClient::RegisterUserPrefs(
469 PrefRegistrySyncable* registry) {
470 registry->RegisterBooleanPref(prefs::kDisable3DAPIs,
471 false,
472 PrefRegistrySyncable::UNSYNCABLE_PREF);
473 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
474 true,
475 PrefRegistrySyncable::UNSYNCABLE_PREF);
476 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo,
477 false,
478 PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23479}
480
[email protected]50462bf02011-11-21 19:13:31481content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
482 const content::MainFunctionParams& parameters) {
483 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30484 // Construct the Main browser parts based on the OS type.
485#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31486 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04487#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31488 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30489#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22490 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26491#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31492 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14493#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09494 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30495#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31496 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04497#else
[email protected]b48c9182011-10-26 18:03:30498 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31499 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30500#endif
501
[email protected]c7480942011-11-08 19:18:27502 // Construct additional browser parts. Stages are called in the order in
503 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22504#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41505 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04506#endif
[email protected]c7480942011-11-08 19:18:27507
508#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41509 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27510#endif
511
[email protected]dc04be7c2012-03-15 23:57:49512#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41513 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49514#endif
515
[email protected]e050ef142012-03-21 01:04:24516#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41517 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24518#endif
519
[email protected]50462bf02011-11-21 19:13:31520 return main_parts;
[email protected]f967b722011-09-07 00:58:04521}
522
[email protected]e94bbcb2012-09-07 05:33:57523std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19524 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57525 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53526 std::string partition_id;
527
528 // The partition ID for webview guest processes is the string value of its
529 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
530 if (site.SchemeIs(chrome::kGuestScheme))
531 partition_id = site.spec();
532
533 DCHECK(IsValidStoragePartitionId(browser_context,partition_id));
534 return partition_id;
535}
536
537bool ChromeContentBrowserClient::IsValidStoragePartitionId(
538 content::BrowserContext* browser_context,
539 const std::string& partition_id) {
540 // The default ID is empty and is always valid.
541 if (partition_id.empty())
542 return true;
543
544 return GURL(partition_id).is_valid();
545}
546
547void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
548 content::BrowserContext* browser_context,
549 const GURL& site,
[email protected]14acc642012-11-17 12:20:10550 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53551 std::string* partition_domain,
552 std::string* partition_name,
553 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10554 // Default to the browser-wide storage partition and override based on |site|
555 // below.
556 partition_domain->clear();
557 partition_name->clear();
558 *in_memory = false;
559
[email protected]1bc28312012-11-08 08:31:53560 // For the webview tag, we create special guest processes, which host the
561 // tag content separately from the main application that embeds the tag.
562 // A webview tag can specify both the partition name and whether the storage
563 // for that partition should be persisted. Each tag gets a SiteInstance with
564 // a specially formatted URL, based on the application it is hosted by and
565 // the partition requested by it. The format for that URL is:
566 // chrome-guest://partition_domain/persist?partition_name
567 if (site.SchemeIs(chrome::kGuestScheme)) {
568 // Since guest URLs are only used for packaged apps, there must be an app
569 // id in the URL.
570 CHECK(site.has_host());
571 *partition_domain = site.host();
572 // Since persistence is optional, the path must either be empty or the
573 // literal string.
574 *in_memory = (site.path() != "/persist");
575 // The partition name is user supplied value, which we have encoded when the
576 // URL was created, so it needs to be decoded.
577 *partition_name = net::UnescapeURLComponent(site.query(),
578 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10579 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
580 // If |can_be_default| is false, the caller is stating that the |site|
581 // should be parsed as if it had isolated storage. In particular it is
582 // important to NOT check ExtensionService for the is_storage_isolated()
583 // attribute because this code path is run during Extension uninstall
584 // to do cleanup after the Extension has already been unloaded from the
585 // ExtensionService.
586 bool is_isolated = !can_be_default;
587 if (can_be_default) {
588 const Extension* extension = NULL;
589 Profile* profile = Profile::FromBrowserContext(browser_context);
590 ExtensionService* extension_service =
591 extensions::ExtensionSystem::Get(profile)->extension_service();
592 if (extension_service) {
593 extension = extension_service->extensions()->
594 GetExtensionOrAppByURL(ExtensionURLInfo(site));
595 if (extension && extension->is_storage_isolated()) {
596 is_isolated = true;
597 }
598 }
599 }
[email protected]1bc28312012-11-08 08:31:53600
[email protected]14acc642012-11-17 12:20:10601 if (is_isolated) {
602 CHECK(site.has_host());
603 // For extensions with isolated storage, the the host of the |site| is
604 // the |partition_domain|. The |in_memory| and |partition_name| are only
605 // used in guest schemes so they are cleared here.
606 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53607 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10608 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53609 }
[email protected]d1198fd2012-08-13 22:50:19610 }
611
[email protected]14acc642012-11-17 12:20:10612 // Assert that if |can_be_default| is false, the code above must have found a
613 // non-default partition. If this fails, the caller has a serious logic
614 // error about which StoragePartition they expect to be in and it is not
615 // safe to continue.
616 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44617}
618
[email protected]38b098f2012-03-14 21:11:57619content::WebContentsViewDelegate*
620 ChromeContentBrowserClient::GetWebContentsViewDelegate(
621 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27622 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32623}
624
[email protected]f364d1392011-04-08 21:03:10625void ChromeContentBrowserClient::RenderViewHostCreated(
626 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46627
[email protected]9f76c1e2012-03-05 15:15:58628 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46629 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02630 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46631
632 new ChromeRenderViewHostObserver(render_view_host,
633 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49634 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26635}
636
[email protected]24665682013-02-25 20:59:38637// Check if the extension activity log is enabled for the profile.
638static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
639 extensions::ActivityLog* activity_log =
640 extensions::ActivityLog::GetInstance(profile);
641 return activity_log->IsLogEnabled();
642}
643
[email protected]44703cc72013-01-24 04:56:06644void ChromeContentBrowserClient::GuestWebContentsCreated(
645 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
646 Profile* profile = Profile::FromBrowserContext(
647 embedder_web_contents->GetBrowserContext());
648 ExtensionService* service =
649 extensions::ExtensionSystem::Get(profile)->extension_service();
650 if (!service)
651 return;
652 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
653 const Extension* extension = service->extensions()->
654 GetExtensionOrAppByURL(ExtensionURLInfo(url));
655 if (!extension)
656 return;
657 std::vector<ExtensionMsg_Loaded_Params> extensions;
658 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
659 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
660}
661
[email protected]f3b1a082011-11-18 00:34:30662void ChromeContentBrowserClient::RenderProcessHostCreated(
663 content::RenderProcessHost* host) {
664 int id = host->GetID();
665 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41666 net::URLRequestContextGetter* context =
667 profile->GetRequestContextForRenderProcess(id);
668
[email protected]f3b1a082011-11-18 00:34:30669 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41670 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55671#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30672 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55673#endif
[email protected]658677f2012-06-09 06:04:02674#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08675 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03676#endif
[email protected]f3b1a082011-11-18 00:34:30677 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02678 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30679 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56680#if defined(OS_MACOSX)
681 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
682#endif
[email protected]43535512013-02-20 20:41:41683 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
684 id, profile, context));
[email protected]2736c032012-05-11 18:06:07685 host->GetChannel()->AddFilter(
686 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38687
[email protected]2ccf45c2011-08-19 23:35:50688 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
689 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07690
[email protected]24665682013-02-25 20:59:38691 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
692 IsExtensionActivityLogEnabledForProfile(profile)));
693
[email protected]39a5b532011-10-22 01:47:07694 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56695
696 RendererContentSettingRules rules;
697 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
698 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14699}
700
[email protected]3d7474ff2011-07-27 17:47:37701GURL ChromeContentBrowserClient::GetEffectiveURL(
702 content::BrowserContext* browser_context, const GURL& url) {
703 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52704 if (!profile)
705 return url;
706
[email protected]7c60f5042013-02-14 03:39:32707 // If the input |url| should be assigned to the Instant renderer, make its
708 // effective URL distinct from other URLs on the search provider's domain.
709 if (chrome::search::ShouldAssignURLToInstantRenderer(url, profile))
710 return GetEffectiveURLForInstant(url, profile);
[email protected]c5dec6292013-01-25 04:54:52711
[email protected]970c63e2013-03-07 00:25:30712 // If the input |url| should be assigned to the Signin renderer, make its
713 // effective URL distinct from other URLs on the signin service's domain.
714 // Note that the signin renderer will be allowed to sign the user in to
715 // Chrome.
716 if (SigninManager::IsWebBasedSigninFlowURL(url))
717 return GetEffectiveURLForSignin(url);
718
[email protected]c5dec6292013-01-25 04:54:52719 // If the input |url| is part of an installed app, the effective URL is an
720 // extension URL with the ID of that extension as the host. This has the
721 // effect of grouping apps together in a common SiteInstance.
722 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13723 extensions::ExtensionSystem::Get(profile)->extension_service();
724 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08725 return url;
726
[email protected]06bdd2b2012-11-30 18:47:13727 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44728 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08729 if (!extension)
730 return url;
731
[email protected]15877ca2011-11-18 22:40:52732 // Bookmark apps do not use the hosted app process model, and should be
733 // treated as normal URLs.
734 if (extension->from_bookmark())
735 return url;
736
[email protected]36fb2c7c2011-04-04 15:49:08737 // If the URL is part of an extension's web extent, convert it to an
738 // extension URL.
739 return extension->GetResourceURL(url.path());
740}
741
[email protected]056ad2a2011-07-12 02:13:55742bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37743 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52744 // Non-extension, non-Instant URLs should generally use
745 // process-per-site-instance. Because we expect to use the effective URL,
746 // URLs for hosted apps (apart from bookmark apps) should have an extension
747 // scheme by now.
748
749 Profile* profile = Profile::FromBrowserContext(browser_context);
750 if (!profile)
751 return false;
752
[email protected]7c60f5042013-02-14 03:39:32753 if (chrome::search::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52754 return true;
755
[email protected]970c63e2013-03-07 00:25:30756 if (SigninManager::IsWebBasedSigninFlowURL(effective_url))
757 return true;
758
[email protected]885c0e92012-11-13 20:27:42759 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55760 return false;
761
[email protected]c5dec6292013-01-25 04:54:52762 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13763 extensions::ExtensionSystem::Get(profile)->extension_service();
764 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55765 return false;
766
[email protected]06bdd2b2012-11-30 18:47:13767 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44768 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55769 if (!extension)
770 return false;
771
772 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53773 // permission, or that does not allow JavaScript access to the background
774 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55775 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40776 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06777 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29778 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53779 return false;
780 }
781 }
[email protected]056ad2a2011-07-12 02:13:55782
[email protected]7b54ca02012-03-02 18:06:53783 // Hosted apps that have script access to their background page must use
784 // process per site, since all instances can make synchronous calls to the
785 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55786 return true;
787}
788
[email protected]6bd30072013-02-08 18:17:11789net::URLRequestContextGetter*
790ChromeContentBrowserClient::CreateRequestContext(
791 content::BrowserContext* browser_context,
[email protected]9c3ed0a2013-03-06 08:57:05792 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
793 blob_protocol_handler,
794 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
795 file_system_protocol_handler,
796 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
797 developer_protocol_handler,
798 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
799 chrome_protocol_handler,
800 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
801 chrome_devtools_protocol_handler) {
[email protected]6bd30072013-02-08 18:17:11802 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]9c3ed0a2013-03-06 08:57:05803 return profile->CreateRequestContext(blob_protocol_handler.Pass(),
804 file_system_protocol_handler.Pass(),
805 developer_protocol_handler.Pass(),
806 chrome_protocol_handler.Pass(),
807 chrome_devtools_protocol_handler.Pass());
[email protected]6bd30072013-02-08 18:17:11808}
809
810net::URLRequestContextGetter*
811ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
812 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40813 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11814 bool in_memory,
[email protected]9c3ed0a2013-03-06 08:57:05815 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
816 blob_protocol_handler,
817 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
818 file_system_protocol_handler,
819 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
820 developer_protocol_handler,
821 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
822 chrome_protocol_handler,
823 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
824 chrome_devtools_protocol_handler) {
[email protected]6bd30072013-02-08 18:17:11825 Profile* profile = Profile::FromBrowserContext(browser_context);
826 return profile->CreateRequestContextForStoragePartition(
[email protected]9c3ed0a2013-03-06 08:57:05827 partition_path,
828 in_memory,
829 blob_protocol_handler.Pass(),
830 file_system_protocol_handler.Pass(),
831 developer_protocol_handler.Pass(),
832 chrome_protocol_handler.Pass(),
833 chrome_devtools_protocol_handler.Pass());
[email protected]6bd30072013-02-08 18:17:11834}
835
[email protected]46fb9442011-12-09 17:57:47836bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
837 return ProfileIOData::IsHandledURL(url);
838}
839
[email protected]2a5221b2011-09-27 23:07:31840bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30841 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31842 const GURL& site_url) {
843 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30844 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52845 // This may be NULL during tests. In that case, just assume any site can
846 // share any host.
847 if (!profile)
848 return true;
849
850 InstantService* instant_service =
851 InstantServiceFactory::GetForProfile(profile);
852 if (instant_service &&
853 instant_service->IsInstantProcess(process_host->GetID()))
[email protected]7c60f5042013-02-14 03:39:32854 return chrome::search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]c5dec6292013-01-25 04:54:52855
[email protected]970c63e2013-03-07 00:25:30856 SigninManager* signin_manager = SigninManagerFactory::GetForProfile(profile);
857 if (signin_manager && signin_manager->IsSigninProcess(process_host->GetID()))
858 return SigninManager::IsWebBasedSigninFlowURL(site_url);
859
[email protected]06bdd2b2012-11-30 18:47:13860 ExtensionService* service =
861 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46862 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31863
[email protected]ffa97602011-11-17 17:55:52864 // Don't allow the Task Manager to share a process with anything else.
865 // Otherwise it can affect the renderers it is observing.
866 // Note: we could create another RenderProcessHostPrivilege bucket for
867 // this to allow multiple chrome://tasks instances to share, but that's
868 // a very unlikely case without serious consequences.
869 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
870 return false;
871
[email protected]8d3132f62011-10-12 07:13:42872 // These may be NULL during tests. In that case, just assume any site can
873 // share any host.
[email protected]6f371442011-11-09 06:45:46874 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31875 return true;
876
[email protected]eec0b33c2011-12-05 22:09:45877 // Otherwise, just make sure the process privilege matches the privilege
878 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57879 RenderProcessHostPrivilege privilege_required =
880 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45881 return GetProcessPrivilege(process_host, process_map, service) ==
882 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31883}
884
[email protected]76411f412012-02-22 18:56:06885// This function is trying to limit the amount of processes used by extensions
886// with background pages. It uses a globally set percentage of processes to
887// run such extensions and if the limit is exceeded, it returns true, to
888// indicate to the content module to group extensions together.
889bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
890 content::BrowserContext* browser_context, const GURL& url) {
891 // It has to be a valid URL for us to check for an extension.
892 if (!url.is_valid())
893 return false;
894
895 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19896 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13897 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06898 if (!service)
899 return false;
900
901 // We have to have a valid extension with background page to proceed.
902 const Extension* extension =
903 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
904 if (!extension)
905 return false;
[email protected]9367eabc2013-03-01 01:29:29906 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06907 return false;
908
909 std::set<int> process_ids;
910 size_t max_process_count =
911 content::RenderProcessHost::GetMaxRendererProcessCount();
912
913 // Go through all profiles to ensure we have total count of extension
914 // processes containing background pages, otherwise one profile can
915 // starve the other.
916 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
917 GetLoadedProfiles();
918 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03919 ExtensionProcessManager* epm =
920 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32921 for (ExtensionProcessManager::const_iterator iter =
922 epm->background_hosts().begin();
923 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13924 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32925 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06926 }
927 }
928
929 if (process_ids.size() >
930 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
931 return true;
932 }
933
934 return false;
935}
936
[email protected]6f371442011-11-09 06:45:46937void ChromeContentBrowserClient::SiteInstanceGotProcess(
938 SiteInstance* site_instance) {
939 CHECK(site_instance->HasProcess());
940
941 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02942 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52943 if (!profile)
944 return;
945
946 // Remember the ID of the Instant process to signal the renderer process
947 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]7c60f5042013-02-14 03:39:32948 if (chrome::search::ShouldAssignURLToInstantRenderer(
949 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:52950 InstantService* instant_service =
951 InstantServiceFactory::GetForProfile(profile);
952 if (instant_service)
953 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
954 }
955
[email protected]970c63e2013-03-07 00:25:30956 // We only expect there to be one signin process as we use process-per-site
957 // for signin URLs. The signin process will be cleared from SigninManager
958 // when the renderer is destroyed.
959 if (SigninManager::IsWebBasedSigninFlowURL(site_instance->GetSiteURL())) {
960 SigninManager* signin_manager =
961 SigninManagerFactory::GetForProfile(profile);
962 if (signin_manager)
963 signin_manager->SetSigninProcess(site_instance->GetProcess()->GetID());
964 }
965
[email protected]06bdd2b2012-11-30 18:47:13966 ExtensionService* service =
967 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46968 if (!service)
969 return;
970
971 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44972 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59973 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46974 if (!extension)
975 return;
976
[email protected]6bc04fd82011-12-04 02:29:35977 service->process_map()->Insert(extension->id(),
978 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33979 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46980 BrowserThread::PostTask(
981 BrowserThread::IO, FROM_HERE,
982 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59983 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46984 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35985 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33986 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46987}
988
989void ChromeContentBrowserClient::SiteInstanceDeleting(
990 SiteInstance* site_instance) {
991 if (!site_instance->HasProcess())
992 return;
993
994 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02995 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13996 ExtensionService* service =
997 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46998 if (!service)
999 return;
1000
1001 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441002 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591003 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461004 if (!extension)
1005 return;
1006
[email protected]6bc04fd82011-12-04 02:29:351007 service->process_map()->Remove(extension->id(),
1008 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331009 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461010 BrowserThread::PostTask(
1011 BrowserThread::IO, FROM_HERE,
1012 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591013 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461014 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351015 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331016 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461017}
1018
[email protected]f05763972012-06-06 18:17:261019bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:141020 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:081021 const GURL& current_url,
1022 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261023 if (current_url.is_empty()) {
1024 // Always choose a new process when navigating to extension URLs. The
1025 // process grouping logic will combine all of a given extension's pages
1026 // into the same process.
[email protected]885c0e92012-11-13 20:27:421027 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261028 return true;
[email protected]e3daf3c2011-10-05 21:17:081029
[email protected]f05763972012-06-06 18:17:261030 return false;
1031 }
1032
1033 // Also, we must switch if one is an extension and the other is not the exact
1034 // same extension.
[email protected]885c0e92012-11-13 20:27:421035 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1036 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261037 if (current_url.GetOrigin() != new_url.GetOrigin())
1038 return true;
1039 }
1040
[email protected]e9841fbd2013-02-22 23:12:141041 // The checks below only matter if we can retrieve which extensions are
1042 // installed.
1043 Profile* profile =
1044 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1045 ExtensionService* service =
1046 extensions::ExtensionSystem::Get(profile)->extension_service();
1047 if (!service)
1048 return false;
1049
1050 // We must swap if the URL is for an extension and we are not using an
1051 // extension process.
1052 const Extension* new_extension =
1053 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1054 // Ignore all hosted apps except the Chrome Web Store, since they do not
1055 // require their own BrowsingInstance (e.g., postMessage is ok).
1056 if (new_extension &&
1057 new_extension->is_hosted_app() &&
1058 new_extension->id() != extension_misc::kWebStoreAppId)
1059 new_extension = NULL;
1060 if (new_extension &&
1061 site_instance->HasProcess() &&
1062 !service->process_map()->Contains(new_extension->id(),
1063 site_instance->GetProcess()->GetID()))
1064 return true;
1065
[email protected]f05763972012-06-06 18:17:261066 return false;
[email protected]e3daf3c2011-10-05 21:17:081067}
1068
[email protected]395045c2012-05-22 15:04:381069bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1070 content::ResourceContext* resource_context, const GURL& current_url,
1071 const GURL& new_url) {
1072 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1073 return extensions::CrossesExtensionProcessBoundary(
1074 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171075 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381076}
1077
[email protected]763ec4ca2011-04-29 15:48:121078std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1079 const std::string& alias_name) {
1080 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1081}
1082
[email protected]b80f68432011-05-02 17:22:301083void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1084 CommandLine* command_line, int child_process_id) {
1085#if defined(USE_LINUX_BREAKPAD)
1086 if (IsCrashReporterEnabled()) {
1087 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1088 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1089 }
1090#elif defined(OS_MACOSX)
1091 if (IsCrashReporterEnabled()) {
1092 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1093 child_process_logging::GetClientId());
1094 }
1095#endif // OS_MACOSX
1096
[email protected]f1933792011-06-14 00:49:341097 if (logging::DialogsAreSuppressed())
1098 command_line->AppendSwitch(switches::kNoErrorDialogs);
1099
[email protected]b80f68432011-05-02 17:22:301100 std::string process_type =
1101 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171102 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:521103 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451104 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301105 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1106 if (!user_data_dir.empty())
1107 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1108#if defined(OS_CHROMEOS)
1109 const std::string& login_profile =
1110 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
1111 if (!login_profile.empty())
1112 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
1113#endif
1114
[email protected]f3b1a082011-11-18 00:34:301115 content::RenderProcessHost* process =
1116 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371117 if (process) {
1118 Profile* profile = Profile::FromBrowserContext(
1119 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131120 ExtensionService* extension_service =
1121 extensions::ExtensionSystem::Get(profile)->extension_service();
1122 if (extension_service) {
1123 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001124 if (process_map && process_map->Contains(process->GetID()))
1125 command_line->AppendSwitch(switches::kExtensionProcess);
1126 }
[email protected]b80f68432011-05-02 17:22:301127
[email protected]a8d851f82011-12-21 00:32:371128 PrefService* prefs = profile->GetPrefs();
1129 // Currently this pref is only registered if applied via a policy.
1130 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1131 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1132 // Turn this policy into a command line switch.
1133 command_line->AppendSwitch(switches::kDisable3DAPIs);
1134 }
[email protected]718eab62011-10-05 21:16:521135
[email protected]a8d851f82011-12-21 00:32:371136 // Disable client-side phishing detection in the renderer if it is
1137 // disabled in the Profile preferences or the browser process.
1138 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1139 !g_browser_process->safe_browsing_detection_service()) {
1140 command_line->AppendSwitch(
1141 switches::kDisableClientSidePhishingDetection);
1142 }
[email protected]0045b0f42012-07-26 11:52:081143
1144 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211145 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521146
1147 InstantService* instant_service =
1148 InstantServiceFactory::GetForProfile(profile);
1149 if (instant_service &&
1150 instant_service->IsInstantProcess(process->GetID()))
1151 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]970c63e2013-03-07 00:25:301152
1153 SigninManager* signin_manager =
1154 SigninManagerFactory::GetForProfile(profile);
1155 if (signin_manager && signin_manager->IsSigninProcess(process->GetID()))
1156 command_line->AppendSwitch(switches::kSigninProcess);
[email protected]47c7ec82012-01-18 03:29:211157 }
[email protected]4287a3d2011-06-13 23:56:511158
[email protected]87552982012-11-02 17:21:401159 if (content::IsThreadedCompositingEnabled())
1160 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1161
[email protected]47c7ec82012-01-18 03:29:211162 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511163 static const char* const kSwitchNames[] = {
1164 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481165 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511166 switches::kAllowScriptingGallery,
1167 switches::kAppsCheckoutURL,
1168 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311169 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511170 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501171 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531172 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111173 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511174 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:211175 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511176 switches::kEnableCrxlessWebApps,
1177 switches::kEnableExperimentalExtensionApis,
[email protected]dcfefa52013-02-15 07:46:561178 switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511179 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511180 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511181 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451182 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481183 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051184 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511185 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511186 switches::kMemoryProfiling,
1187 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371188 switches::kNoJsRandomness,
[email protected]732b1604e2012-10-26 19:59:581189 switches::kPerformCrashAnalysis,
[email protected]f45c5f32012-04-18 19:26:371190 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511191 switches::kPpapiFlashArgs,
1192 switches::kPpapiFlashInProcess,
1193 switches::kPpapiFlashPath,
1194 switches::kPpapiFlashVersion,
1195 switches::kProfilingAtStart,
1196 switches::kProfilingFile,
1197 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371198 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511199 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291200 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381201 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511202 };
1203
1204 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1205 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171206 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381207 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351208 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381209 switches::kEnableExperimentalExtensionApis,
1210 switches::kWhitelistedExtensionID,
1211 };
1212
1213 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1214 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511215 } else if (process_type == switches::kPluginProcess) {
1216 static const char* const kSwitchNames[] = {
1217 #if defined(OS_CHROMEOS)
1218 switches::kLoginProfile,
1219 #endif
1220 switches::kMemoryProfiling,
1221 switches::kSilentDumpOnDCHECK,
1222 switches::kUserDataDir,
1223 };
1224
1225 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1226 arraysize(kSwitchNames));
1227 } else if (process_type == switches::kZygoteProcess) {
1228 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511229 switches::kUserDataDir, // Make logs go to the right file.
1230 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501231 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511232 switches::kPpapiFlashInProcess,
1233 switches::kPpapiFlashPath,
1234 switches::kPpapiFlashVersion,
1235 };
1236
1237 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1238 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111239 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001240 base::FilePath user_data_dir =
1241 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1242 if (!user_data_dir.empty())
1243 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111244 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1245 // because GPU is expected to be unreliable.
1246 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1247 !command_line->HasSwitch(switches::kDisableBreakpad))
1248 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301249 }
[email protected]6f08af82011-09-15 01:19:031250
1251 // The command line switch kEnableBenchmarking needs to be specified along
1252 // with the kEnableStatsTable switch to ensure that the stats table global
1253 // is initialized correctly.
1254 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1255 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301256}
1257
1258std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431259 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1260 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:301261 return g_browser_process->GetApplicationLocale();
1262}
1263
[email protected]597a867b2011-11-18 18:31:201264std::string ChromeContentBrowserClient::GetAcceptLangs(
1265 content::BrowserContext* context) {
1266 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371267 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081268}
1269
[email protected]9ec0f452012-05-31 15:58:531270gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221271 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531272 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081273}
1274
[email protected]a2176792011-05-08 19:30:491275bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091276 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191277 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201278 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201280 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051281 return io_data->GetCookieSettings()->
1282 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491283}
1284
[email protected]ed24fad2011-05-10 22:44:011285bool ChromeContentBrowserClient::AllowGetCookie(
1286 const GURL& url,
1287 const GURL& first_party,
1288 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201289 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011290 int render_process_id,
1291 int render_view_id) {
1292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201293 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051294 bool allow = io_data->GetCookieSettings()->
1295 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011296
[email protected]8093a542011-05-13 07:29:321297 BrowserThread::PostTask(
1298 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031299 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431300 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011301 return allow;
1302}
1303
1304bool ChromeContentBrowserClient::AllowSetCookie(
1305 const GURL& url,
1306 const GURL& first_party,
1307 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201308 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011309 int render_process_id,
1310 int render_view_id,
1311 net::CookieOptions* options) {
1312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201313 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051314 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1315 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1316
[email protected]8093a542011-05-13 07:29:321317 BrowserThread::PostTask(
1318 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031319 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431320 render_view_id, url, first_party, cookie_line, *options,
1321 !allow));
[email protected]ed24fad2011-05-10 22:44:011322 return allow;
1323}
1324
[email protected]d5a19162011-06-30 18:51:541325bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201326 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201328 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431329 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1330 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261331
[email protected]bf510ed2012-06-05 08:31:431332 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1333 // Could we even support per-origin settings?
1334 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541335}
1336
[email protected]5c5a88e2011-11-12 00:45:351337bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351338 const GURL& url,
1339 const string16& name,
1340 const string16& display_name,
1341 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201342 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481343 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201345 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351346 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1347 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1348
[email protected]62151052012-02-01 18:40:481349 // Record access to database for potential display in UI.
1350 std::vector<std::pair<int, int> >::const_iterator i;
1351 for (i = render_views.begin(); i != render_views.end(); ++i) {
1352 BrowserThread::PostTask(
1353 BrowserThread::UI, FROM_HERE,
1354 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1355 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351356 }
1357
1358 return allow;
1359}
1360
1361bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351362 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201363 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481364 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201366 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351367 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1368 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1369
[email protected]62151052012-02-01 18:40:481370 // Record access to file system for potential display in UI.
1371 std::vector<std::pair<int, int> >::const_iterator i;
1372 for (i = render_views.begin(); i != render_views.end(); ++i) {
1373 BrowserThread::PostTask(
1374 BrowserThread::UI, FROM_HERE,
1375 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1376 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351377 }
1378
1379 return allow;
1380}
1381
[email protected]7c5ff9a2012-03-02 07:42:491382bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1383 const GURL& url,
1384 const string16& name,
1385 content::ResourceContext* context,
1386 const std::vector<std::pair<int, int> >& render_views) {
1387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1388 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1389 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1390 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1391
1392 // Record access to IndexedDB for potential display in UI.
1393 std::vector<std::pair<int, int> >::const_iterator i;
1394 for (i = render_views.begin(); i != render_views.end(); ++i) {
1395 BrowserThread::PostTask(
1396 BrowserThread::UI, FROM_HERE,
1397 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1398 i->first, i->second, url, name, !allow));
1399 }
1400
1401 return allow;
1402}
1403
[email protected]6133f922011-07-01 21:34:341404net::URLRequestContext*
1405ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201406 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421408 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201409 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341410 return io_data->extensions_request_context();
1411 }
1412
1413 return NULL;
1414}
1415
[email protected]317f96c92011-05-31 06:53:411416QuotaPermissionContext*
1417ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1418 return new ChromeQuotaPermissionContext();
1419}
1420
[email protected]848dd042011-06-04 18:24:031421void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171422 int render_process_id,
1423 int render_view_id,
1424 int cert_error,
1425 const net::SSLInfo& ssl_info,
1426 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021427 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031428 bool overridable,
[email protected]d9be47702012-05-16 03:41:221429 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171430 const base::Callback<void(bool)>& callback,
1431 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021432 if (resource_type != ResourceType::MAIN_FRAME) {
1433 // A sub-resource has a certificate error. The user doesn't really
1434 // have a context for making the right decision, so block the
1435 // request hard, without an info bar to allow showing the insecure
1436 // content.
1437 *cancel_request = true;
1438 return;
1439 }
1440
[email protected]f9034cf2011-07-21 12:43:411441 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131442 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171443 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411444 if (!tab) {
1445 NOTREACHED();
1446 return;
1447 }
1448 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501449 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301450 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011451 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1452 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411453 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171454 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411455 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171456 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411457 return;
1458 }
1459 }
1460
[email protected]1e87df32012-09-12 04:53:191461#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231462 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1463 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1464 if (captive_portal_tab_helper)
1465 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191466#endif
1467
[email protected]f9034cf2011-07-21 12:43:411468 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221469 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1470 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031471}
1472
[email protected]c99c442e2011-08-24 11:37:301473void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451474 int render_process_id,
1475 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401476 const net::HttpNetworkSession* network_session,
1477 net::SSLCertRequestInfo* cert_request_info,
1478 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131479 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451480 render_process_id, render_view_id);
1481 if (!tab) {
1482 NOTREACHED();
1483 return;
1484 }
1485
[email protected]6786bf402011-12-03 15:19:451486 GURL requesting_url("https://" + cert_request_info->host_and_port);
1487 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1488 << cert_request_info->host_and_port;
1489
[email protected]627e0512011-12-21 22:55:301490 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451491 scoped_ptr<Value> filter(
1492 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1493 requesting_url,
1494 requesting_url,
1495 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1496 std::string(), NULL));
1497
1498 if (filter.get()) {
1499 // Try to automatically select a client certificate.
1500 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1501 DictionaryValue* filter_dict =
1502 static_cast<DictionaryValue*>(filter.get());
1503
1504 const std::vector<scoped_refptr<net::X509Certificate> >&
1505 all_client_certs = cert_request_info->client_certs;
1506 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1507 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1508 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401509 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451510 return;
1511 }
1512 }
1513 } else {
1514 NOTREACHED();
1515 }
1516 }
1517
[email protected]11feec322012-09-18 03:58:521518 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1519 if (!ssl_tab_helper) {
1520 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451521 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141522 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401523 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451524 return;
1525 }
[email protected]11feec322012-09-18 03:58:521526 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401527 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451528}
1529
[email protected]3b455502012-12-11 18:22:581530void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451531 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581532 net::CertificateMimeType cert_type,
1533 const void* cert_data,
1534 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451535 int render_process_id,
1536 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581537 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1538 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451539}
1540
[email protected]dc73a7b2012-03-25 15:27:181541content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561542 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181543}
1544
[email protected]941623e2011-06-07 23:06:041545void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1546 const GURL& source_origin,
1547 int callback_context,
1548 int render_process_id,
1549 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111550#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1552 WebContents* contents =
1553 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1554 if (!contents) {
[email protected]941623e2011-06-07 23:06:041555 NOTREACHED();
1556 return;
1557 }
1558
[email protected]d0d9c3ee2012-06-19 03:07:021559 // Skip showing the infobar if the request comes from an extension, and that
1560 // extension has the 'notify' permission. (If the extension does not have the
1561 // permission, the user will still be prompted.)
1562 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131563 ExtensionService* service =
1564 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]d0d9c3ee2012-06-19 03:07:021565 const Extension* extension = !service ? NULL :
1566 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1567 source_origin));
[email protected]eb4832a2012-12-08 01:57:521568 RenderViewHost* rvh =
1569 RenderViewHost::FromID(render_process_id, render_view_id);
1570 if (IsExtensionWithPermissionOrSuggestInConsole(
1571 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021572 if (rvh)
1573 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1574 return;
1575 }
1576
1577 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371578 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021579 notifications->RequestPermission(source_origin, render_process_id,
1580 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111581#else
1582 NOTIMPLEMENTED();
1583#endif
[email protected]941623e2011-06-07 23:06:041584}
1585
1586WebKit::WebNotificationPresenter::Permission
1587 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021588 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201589 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021590 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111591#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201593 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021594 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1595 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061596 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041597 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041598
1599 // Fall back to the regular notification preferences, which works on an
1600 // origin basis.
1601 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371602 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041603 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111604#else
1605 return WebKit::WebNotificationPresenter::PermissionAllowed;
1606#endif
[email protected]941623e2011-06-07 23:06:041607}
1608
1609void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171610 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041611 int render_process_id,
1612 int render_view_id,
1613 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111614#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041615 RenderViewHost* rvh = RenderViewHost::FromID(
1616 render_process_id, render_view_id);
1617 if (!rvh) {
1618 NOTREACHED();
1619 return;
1620 }
1621
[email protected]9f76c1e2012-03-05 15:15:581622 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301623 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041624 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371625 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041626 service->ShowDesktopNotification(
1627 params, render_process_id, render_view_id,
1628 worker ? DesktopNotificationService::WorkerNotification :
1629 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111630#else
1631 NOTIMPLEMENTED();
1632#endif
[email protected]941623e2011-06-07 23:06:041633}
1634
1635void ChromeContentBrowserClient::CancelDesktopNotification(
1636 int render_process_id,
1637 int render_view_id,
1638 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111639#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041640 RenderViewHost* rvh = RenderViewHost::FromID(
1641 render_process_id, render_view_id);
1642 if (!rvh) {
1643 NOTREACHED();
1644 return;
1645 }
1646
[email protected]9f76c1e2012-03-05 15:15:581647 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301648 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041649 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371650 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041651 service->CancelDesktopNotification(
1652 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111653#else
1654 NOTIMPLEMENTED();
1655#endif
[email protected]941623e2011-06-07 23:06:041656}
1657
[email protected]9f3fba52011-06-08 20:37:191658bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351659 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021660 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191661 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201662 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011663 int render_process_id,
1664 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191665 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011666
1667 *no_javascript_access = false;
1668
[email protected]9f3fba52011-06-08 20:37:191669 // If the opener is trying to create a background window but doesn't have
1670 // the appropriate permission, fail the attempt.
1671 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201672 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531673 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1674
[email protected]03b6d552012-03-29 04:03:011675 if (!map->SecurityOriginHasAPIPermission(
1676 source_origin,
1677 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061678 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011679 return false;
1680 }
1681
[email protected]7b54ca02012-03-02 18:06:531682 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1683 // return a recently installed Extension even if this CanCreateWindow call
1684 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011685 // because the permission check above would have caused an early return
1686 // already. We must use the full URL to find hosted apps, though, and not
1687 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531688 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351689 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291690 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011691 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191692 }
1693 return true;
1694}
1695
1696std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201697 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1699 // Check if it's an extension-created worker, in which case we want to use
1700 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201701 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191702 const Extension* extension =
1703 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1704 return extension ? extension->name() : std::string();
1705}
1706
[email protected]99907362012-01-11 05:41:401707void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1708 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171709}
1710
[email protected]c52b2892012-03-07 11:01:021711content::SpeechRecognitionManagerDelegate*
1712 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321713#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021714 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321715#else
1716 return NULL;
1717#endif
[email protected]66cfec62012-02-24 17:57:511718}
1719
[email protected]ae6e9912011-07-27 01:18:281720net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1721 return g_browser_process->net_log();
1722}
1723
[email protected]32538d92011-08-25 00:09:231724AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1725 return new ChromeAccessTokenStore();
1726}
1727
[email protected]dbae6b02011-06-29 23:51:411728bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011729 return true;
[email protected]dbae6b02011-06-29 23:51:411730}
1731
[email protected]64d69de42012-02-06 00:19:541732void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321733 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061734 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581735 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061736 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061737
[email protected]f3986f82012-01-03 20:00:061738 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541739 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061740 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541741 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061742 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541743 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061744 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541745 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061746 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541747 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061748 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541749 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031750 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1751 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061752
[email protected]64d69de42012-02-06 00:19:541753 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401754 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541755 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401756 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541757 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401758 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541759 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401760 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061761
[email protected]ddf72142012-05-22 04:52:401762 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061763
[email protected]64d69de42012-02-06 00:19:541764 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401765 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541766 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061767 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541768 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061769 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1770 const DictionaryValue* inspector_settings =
1771 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1772 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181773 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1774 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061775 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181776 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541777 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181778 std::make_pair(iter.key(), value));
1779 }
[email protected]f3986f82012-01-03 20:00:061780 }
1781 }
[email protected]64d69de42012-02-06 00:19:541782 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061783
[email protected]ddf72142012-05-22 04:52:401784 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541785 web_prefs->javascript_enabled = false;
1786 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1787 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401788 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541789 web_prefs->plugins_enabled = false;
1790 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1791 web_prefs->java_enabled = false;
1792 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401793 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061794
[email protected]64d69de42012-02-06 00:19:541795 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1796 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061797
[email protected]64d69de42012-02-06 00:19:541798 web_prefs->memory_info_enabled =
1799 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1800 web_prefs->allow_displaying_insecure_content =
1801 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1802 web_prefs->allow_running_insecure_content =
1803 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321804#if defined(OS_ANDROID)
1805 web_prefs->font_scale_factor =
1806 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1807 web_prefs->force_enable_zoom =
1808 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
1809#endif
[email protected]9d06d88d2012-02-23 22:37:081810 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061811
[email protected]64d69de42012-02-06 00:19:541812 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151813 UserStyleSheetWatcher* user_style_sheet_watcher =
1814 UserStyleSheetWatcherFactory::GetForProfile(profile);
1815 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541816 web_prefs->user_style_sheet_enabled = true;
1817 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151818 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541819 } else {
1820 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061821 }
1822
[email protected]b7e44ff2012-02-16 03:37:341823 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101824#if defined(OS_MACOSX)
[email protected]325342e62013-01-09 02:29:031825 // TODO(groby): Bug 107371: Implement asynchronous spellchecking API for
[email protected]37b928e2012-05-30 09:01:101826 // Mac so it uses NSSpellChecker in the background.
1827 false;
1828#else
[email protected]61806872012-12-12 04:15:361829 true;
[email protected]37b928e2012-05-30 09:01:101830#endif
[email protected]b7e44ff2012-02-16 03:37:341831 web_prefs->unified_textchecker_enabled =
[email protected]57890242012-10-23 17:46:521832 web_prefs->asynchronous_spell_checking_enabled;
[email protected]dd5d0fb2012-01-18 03:37:571833
[email protected]64d69de42012-02-06 00:19:541834 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061835 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541836 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061837 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541838 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061839 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1840
1841 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541842 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061843 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541844 web_prefs->default_encoding);
1845 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401846 prefs->ClearPref(prefs::kDefaultCharset);
1847 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061848 }
[email protected]64d69de42012-02-06 00:19:541849 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061850
[email protected]88ecf66d2012-12-11 22:53:471851 if (content::IsForceCompositingModeEnabled())
1852 web_prefs->force_compositing_mode = true;
1853
[email protected]299d7f12012-05-23 05:31:151854 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1855 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131856 ExtensionService* service =
1857 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061858 if (service) {
[email protected]1bc28312012-11-08 08:31:531859 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1860 const Extension* extension = service->extensions()->GetByID(url.host());
1861 // Ensure that we are only granting extension preferences to URLs with
1862 // the correct scheme. Without this check, chrome-guest:// schemes used by
1863 // webview tags as well as hosts that happen to match the id of an
1864 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421865 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531866 extension_webkit_preferences::SetPreferences(
1867 extension, view_type, web_prefs);
1868 }
[email protected]f3986f82012-01-03 20:00:061869 }
1870
[email protected]299d7f12012-05-23 05:31:151871 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541872 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151873 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061874 // Disable all kinds of acceleration for background pages.
1875 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541876 web_prefs->force_compositing_mode = false;
1877 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061878 }
[email protected]2e21fe292012-03-02 22:52:321879
1880#if defined(FILE_MANAGER_EXTENSION)
1881 // Override the default of suppressing HW compositing for WebUI pages for the
1882 // file manager, which is implemented using WebUI but wants HW acceleration
1883 // for video decode & render.
1884 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1885 web_prefs->accelerated_compositing_enabled = true;
1886 web_prefs->accelerated_2d_canvas_enabled = true;
1887 }
1888#endif
[email protected]181a95ee2011-07-12 19:26:361889}
1890
1891void ChromeContentBrowserClient::UpdateInspectorSetting(
1892 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061893 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581894 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061895 DictionaryPrefUpdate update(
1896 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1897 prefs::kWebKitInspectorSettings);
1898 DictionaryValue* inspector_settings = update.Get();
1899 inspector_settings->SetWithoutPathExpansion(key,
1900 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361901}
1902
1903void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061904 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581905 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061906 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1907 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361908}
1909
[email protected]b8148ac2011-07-13 22:03:251910void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1911 BrowserURLHandler* handler) {
1912 // Add the default URL handlers.
1913 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1914 BrowserURLHandler::null_handler());
1915 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1916 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1917
[email protected]b3adbd02011-11-30 22:23:271918 // about: handler. Must come before chrome: handler, since it will
1919 // rewrite about: urls to chrome: URLs and then expect chrome: to
1920 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251921 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1922 BrowserURLHandler::null_handler());
1923 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241924 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251925}
1926
1927void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371928 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581929 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471930 BrowsingDataRemover* remover =
1931 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551932 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1933 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251934 // BrowsingDataRemover takes care of deleting itself when done.
1935}
1936
1937void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371938 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581939 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471940 BrowsingDataRemover* remover =
1941 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231942 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551943 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251944 // BrowsingDataRemover takes care of deleting itself when done.
1945}
1946
[email protected]650b2d52013-02-10 03:41:451947base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:321948 return download_util::GetDefaultDownloadDirectory();
1949}
1950
[email protected]c9b6eb62011-10-18 20:49:391951std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1952 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1953}
1954
[email protected]b7631cc2012-09-15 05:08:381955void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1956 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:541957#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:381958 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1959 scoped_ptr<ppapi::host::HostFactory>(
1960 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:541961#endif
[email protected]b7631cc2012-09-15 05:08:381962}
1963
[email protected]0c7193742012-11-07 19:05:031964content::BrowserPpapiHost*
1965 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
1966 int plugin_process_id) {
1967 BrowserChildProcessHostIterator iter(content::PROCESS_TYPE_NACL_LOADER);
1968 while (!iter.Done()) {
1969 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
1970 if (host->process() &&
1971 host->process()->GetData().id == plugin_process_id) {
1972 // Found the plugin.
1973 return host->browser_ppapi_host();
1974 }
1975 ++iter;
1976 }
1977 return NULL;
1978}
1979
[email protected]38cd8f7f2012-06-15 22:06:071980bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:581981 content::BrowserContext* browser_context,
1982 const GURL& url,
1983 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:291984 if (!url.is_valid())
1985 return false;
1986
1987 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:421988 if (url.SchemeIs(extensions::kExtensionScheme) &&
1989 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:291990 return true;
[email protected]885c0e92012-11-13 20:27:421991 }
[email protected]a658d452012-03-02 12:45:291992
[email protected]9a5940d2012-04-27 19:16:231993 Profile* profile = Profile::FromBrowserContext(browser_context);
1994 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:191995 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131996 extensions::ExtensionSystem::Get(profile)->extension_service();
1997 if (extension_service) {
1998 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:231999 GetExtensionOrAppByURL(ExtensionURLInfo(url));
2000 }
2001
[email protected]f237c0f2012-03-10 07:49:102002 // Need to check this now and not on construction because otherwise it won't
2003 // work with browser_tests.
2004 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2005 std::string allowed_list =
2006 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:232007 if (allowed_list == "*") {
2008 // The wildcard allows socket API only for packaged and platform apps.
2009 return extension &&
[email protected]1d5e58b2013-01-31 08:41:402010 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
2011 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:232012 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:392013 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:102014 while (t.GetNext()) {
2015 if (t.token() == host)
2016 return true;
2017 }
2018 }
2019
[email protected]a658d452012-03-02 12:45:292020 if (!extension)
2021 return false;
2022
[email protected]157cc902012-11-02 06:31:582023 extensions::SocketPermission::CheckParam extension_params(
2024 params.type, params.host, params.port);
2025 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
2026 &extension_params))
[email protected]a658d452012-03-02 12:45:292027 return true;
2028
2029 return false;
[email protected]e461da2f2012-02-16 19:06:402030}
2031
[email protected]650b2d52013-02-10 03:41:452032base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
2033 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:142034 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
2035 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
2036}
2037
[email protected]a28e3302013-02-03 03:50:432038ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
2039 WebContents* web_contents) {
2040 return new ChromeSelectFilePolicy(web_contents);
2041}
2042
[email protected]e60c0232011-11-11 19:56:352043#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182044void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2045 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382046 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082047 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392048#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452049 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392050 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2051 DCHECK(!data_path.empty());
2052
2053 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452054 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392055 base::PlatformFile f =
2056 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2057 DCHECK(f != base::kInvalidPlatformFileValue);
2058 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2059 FileDescriptor(f, true)));
2060
[email protected]650b2d52013-02-10 03:41:452061 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392062 data_path.AppendASCII("chrome_100_percent.pak");
2063 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2064 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372065 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392066 FileDescriptor(f, true)));
2067
2068 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452069 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392070 GetLocaleFilePath(locale, false);
2071 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2072 DCHECK(f != base::kInvalidPlatformFileValue);
2073 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2074 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382075
[email protected]650b2d52013-02-10 03:41:452076 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372077 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2078 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2079 DCHECK(f != base::kInvalidPlatformFileValue);
2080 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2081 FileDescriptor(f, true)));
2082
[email protected]40da3e0c2012-10-24 22:03:382083#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432084 if (IsCrashReporterEnabled()) {
2085 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2086 if (f == base::kInvalidPlatformFileValue) {
2087 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2088 "be disabled for this process.";
2089 } else {
2090 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2091 FileDescriptor(f, true)));
2092 }
[email protected]40da3e0c2012-10-24 22:03:382093 }
2094#endif // defined(USE_LINUX_BREAKPAD)
2095
2096#else
2097 int crash_signal_fd = GetCrashSignalFD(command_line);
2098 if (crash_signal_fd >= 0) {
2099 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2100 FileDescriptor(crash_signal_fd,
2101 false)));
2102 }
[email protected]29699c22012-10-03 23:57:392103#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302104}
[email protected]e60c0232011-11-11 19:56:352105#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302106
[email protected]4a65826d2011-08-25 16:04:012107#if defined(OS_WIN)
2108const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2109 return chrome::kBrowserResourcesDll;
2110}
2111#endif
2112
[email protected]37a72af2011-06-13 05:42:012113#if defined(USE_NSS)
2114crypto::CryptoModuleBlockingPasswordDelegate*
2115 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2116 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292117 return chrome::NewCryptoModuleBlockingDialogDelegate(
2118 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012119}
2120#endif
2121
[email protected]e9a32a52012-06-14 23:32:432122void ChromeContentBrowserClient::SetApplicationLocale(
2123 const std::string& locale) {
2124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2125
2126 // This object is guaranteed to outlive all threads so we don't have to
2127 // worry about the lack of refcounting and can just post as Unretained.
2128 //
2129 // The common case is that this function is called early in Chrome startup
2130 // before any threads are created (it will also be called later if the user
2131 // changes the pref). In this case, there will be no threads created and
2132 // posting will fail. When there are no threads, we can just set the string
2133 // without worrying about threadsafety.
2134 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
2135 base::Bind(
2136 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
2137 base::Unretained(this), locale)))
2138 io_thread_application_locale_ = locale;
2139}
2140
2141void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
2142 const std::string& locale) {
2143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2144 io_thread_application_locale_ = locale;
2145}
2146
[email protected]d977f9c2011-03-14 16:10:262147} // namespace chrome