blob: 1a47b406d80c72c66491c8ae0043b31e5ffb4396 [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]c52b2892012-03-07 11:01:0266#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4667#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5868#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0369#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5270#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4571#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5472#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4373#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]7c60f5042013-02-14 03:39:3274#include "chrome/browser/ui/search/search.h"
[email protected]b5d73422012-06-02 23:46:4475#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5076#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0677#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1578#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5379#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3080#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0181#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1482#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3083#include "chrome/common/chrome_switches.h"
[email protected]9367eabc2013-03-01 01:29:2984#include "chrome/common/extensions/background_info.h"
[email protected]941623e2011-06-07 23:06:0485#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3886#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4487#include "chrome/common/extensions/extension_set.h"
[email protected]157cc902012-11-02 06:31:5888#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3489#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1290#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3891#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0992#include "chrome/common/url_constants.h"
[email protected]75fee372013-03-06 00:42:4493#include "components/user_prefs/pref_registry_syncable.h"
[email protected]e0ada9c2012-03-20 03:54:4394#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3095#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:3896#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:3197#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:0398#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:5999#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:36100#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30101#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33102#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05103#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33104#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19105#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10106#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43107#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18108#include "content/public/common/content_descriptors.h"
[email protected]885c0e92012-11-13 20:27:42109#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39110#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23111#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53112#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58113#include "net/base/mime_util.h"
[email protected]7a593db2012-02-13 21:19:40114#include "net/base/ssl_cert_request_info.h"
[email protected]5b9bc352012-07-18 13:13:34115#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06116#include "net/cookies/cookie_options.h"
[email protected]b7631cc2012-09-15 05:08:38117#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39118#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08119#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36120#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04121#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26122
[email protected]b48c9182011-10-26 18:03:30123#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38124#include "chrome/browser/chrome_browser_main_win.h"
125#elif defined(OS_MACOSX)
126#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56127#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30128#elif defined(OS_CHROMEOS)
129#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49130#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26131#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30132#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09133#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38134#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09135#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39136#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30137#elif defined(OS_POSIX)
138#include "chrome/browser/chrome_browser_main_posix.h"
139#endif
140
[email protected]6653c192012-04-10 22:52:44141#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30142#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12143#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43144#endif
[email protected]b80f68432011-05-02 17:22:30145
[email protected]1e87df32012-09-12 04:53:19146#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
147#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
148#endif
149
[email protected]29699c22012-10-03 23:57:39150#if defined(OS_ANDROID)
151#include "ui/base/ui_base_paths.h"
152#endif
153
[email protected]37a72af2011-06-13 05:42:01154#if defined(USE_NSS)
155#include "chrome/browser/ui/crypto_module_password_dialog.h"
156#endif
157
[email protected]c7abd422012-09-25 00:20:08158using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47159using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03160using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39161using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31162using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59163using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08164using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00165using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11166using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33167using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13168using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06169using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34170using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40171using extensions::Manifest;
[email protected]6717bf272012-05-11 23:31:25172using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39173
[email protected]c5dbef02011-05-13 05:06:09174namespace {
175
[email protected]e461da2f2012-02-16 19:06:40176const char* kPredefinedAllowedSocketOrigins[] = {
177 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18178 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45179 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
180 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
181 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
182 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35183 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54184 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
185 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
186 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
187 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
188 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
189 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38190 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58191 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
192 "iabmpiboiopbgfabjmgeedhcmjenhbla" // see crbug.com/165080
[email protected]e461da2f2012-02-16 19:06:40193};
194
[email protected]f8f93eb2012-09-25 03:06:24195// Returns a copy of the given url with its host set to given host and path set
196// to given path. Other parts of the url will be the same.
197GURL ReplaceURLHostAndPath(const GURL& url,
198 const std::string& host,
199 const std::string& path) {
200 url_canon::Replacements<char> replacements;
201 replacements.SetHost(host.c_str(),
202 url_parse::Component(0, host.length()));
203 replacements.SetPath(path.c_str(),
204 url_parse::Component(0, path.length()));
205 return url.ReplaceComponents(replacements);
206}
207
208// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
209GURL AddUberHost(const GURL& url) {
210 const std::string uber_host = chrome::kChromeUIUberHost;
211 const std::string new_path = url.host() + url.path();
212
213 return ReplaceURLHostAndPath(url, uber_host, new_path);
214}
215
[email protected]045bf7c2012-09-28 20:27:36216// If url->host() is "chrome" and url->path() has characters other than the
217// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
218// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24219bool RemoveUberHost(GURL* url) {
220 if (url->host() != chrome::kChromeUIUberHost)
221 return false;
222
[email protected]045bf7c2012-09-28 20:27:36223 if (url->path().empty() || url->path() == "/")
224 return false;
225
[email protected]f8f93eb2012-09-25 03:06:24226 const std::string old_path = url->path();
227
228 const std::string::size_type separator = old_path.find('/', 1);
229 std::string new_host;
230 std::string new_path;
231 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36232 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24233 } else {
234 new_host = old_path.substr(1, separator - 1);
235 new_path = old_path.substr(separator);
236 }
237
238 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
239
240 return true;
241}
242
[email protected]b8148ac2011-07-13 22:03:25243// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42244bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24245 // Do not handle special URLs such as "about:foo"
246 if (!url->host().empty()) {
247 const GURL chrome_url = AddUberHost(*url);
248
249 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
250 // be called.
251 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
252 browser_context, chrome_url))
253 return true;
254 }
255
[email protected]863f70a2012-01-27 02:05:50256 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
257 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25258 return false;
259
[email protected]fe69558d2012-03-12 11:34:49260#if defined(OS_CHROMEOS)
261 // Special case : in ChromeOS in Guest mode bookmarks and history are
262 // disabled for security reasons. New tab page explains the reasons, so
263 // we redirect user to new tab page.
264 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
265 if (url->SchemeIs(chrome::kChromeUIScheme) &&
266 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
267 url->DomainIs(chrome::kChromeUIHistoryHost))) {
268 // Rewrite with new tab URL
269 *url = GURL(chrome::kChromeUINewTabURL);
270 }
271 }
272#endif
273
[email protected]b8148ac2011-07-13 22:03:25274 // Special case the new tab page. In older versions of Chrome, the new tab
275 // page was hosted at chrome-internal:<blah>. This might be in people's saved
276 // sessions or bookmarks, so we say any URL with that scheme triggers the new
277 // tab page.
278 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
279 // Rewrite it with the proper new tab URL.
280 *url = GURL(chrome::kChromeUINewTabURL);
281 }
282
283 return true;
284}
285
[email protected]f8f93eb2012-09-25 03:06:24286// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
287// "chrome://foo/".
288bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
289 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
290 return false;
291
292 return RemoveUberHost(url);
293}
294
[email protected]8d3132f62011-10-12 07:13:42295// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
296// below. Extension, and isolated apps require different privileges to be
297// granted to their RenderProcessHosts. This classification allows us to make
298// sure URLs are served by hosts with the right set of privileges.
299enum RenderProcessHostPrivilege {
300 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45301 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42302 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45303 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42304};
305
306RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
307 const GURL& url,
308 ExtensionService* service) {
309 // Default to a normal renderer cause it is lower privileged. This should only
310 // occur if the URL on a site instance is either malformed, or uninitialized.
311 // If it is malformed, then there is no need for better privileges anyways.
312 // If it is uninitialized, but eventually settles on being an a scheme other
313 // than normal webrenderer, the navigation logic will correct us out of band
314 // anyways.
315 if (!url.is_valid())
316 return PRIV_NORMAL;
317
[email protected]885c0e92012-11-13 20:27:42318 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44319 const Extension* extension =
320 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45321 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42322 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45323 if (extension && extension->is_hosted_app())
324 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42325
326 return PRIV_EXTENSION;
327 }
328
329 return PRIV_NORMAL;
330}
331
332RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30333 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46334 extensions::ProcessMap* process_map,
335 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46336 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30337 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46338 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21339 return PRIV_NORMAL;
340
[email protected]6f371442011-11-09 06:45:46341 for (std::set<std::string>::iterator iter = extension_ids.begin();
342 iter != extension_ids.end(); ++iter) {
343 const Extension* extension = service->GetExtensionById(*iter, false);
344 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42345 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45346 if (extension && extension->is_hosted_app())
347 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42348 }
349
[email protected]676f6ab2011-10-19 20:23:21350 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42351}
352
[email protected]6786bf402011-12-03 15:19:45353bool CertMatchesFilter(const net::X509Certificate& cert,
354 const base::DictionaryValue& filter) {
355 // TODO(markusheintz): This is the minimal required filter implementation.
356 // Implement a better matcher.
357
358 // An empty filter matches any client certificate since no requirements are
359 // specified at all.
360 if (filter.empty())
361 return true;
362
363 std::string common_name;
364 if (filter.GetString("ISSUER.CN", &common_name) &&
365 (cert.issuer().common_name == common_name)) {
366 return true;
367 }
368 return false;
369}
370
[email protected]f3986f82012-01-03 20:00:06371// Fills |map| with the per-script font prefs under path |map_name|.
372void FillFontFamilyMap(const PrefService* prefs,
373 const char* map_name,
374 WebPreferences::ScriptFontFamilyMap* map) {
375 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
376 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
377 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
378 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23379 if (!font_family.empty())
380 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06381 }
382}
383
[email protected]a1733df2012-06-22 11:24:18384#if defined(OS_POSIX) && !defined(OS_MACOSX)
385int GetCrashSignalFD(const CommandLine& command_line) {
386 if (command_line.HasSwitch(switches::kExtensionProcess)) {
387 ExtensionCrashHandlerHostLinux* crash_handler =
388 ExtensionCrashHandlerHostLinux::GetInstance();
389 return crash_handler->GetDeathSignalSocket();
390 }
391
392 std::string process_type =
393 command_line.GetSwitchValueASCII(switches::kProcessType);
394
395 if (process_type == switches::kRendererProcess)
396 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
397
398 if (process_type == switches::kPluginProcess)
399 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
400
401 if (process_type == switches::kPpapiPluginProcess)
402 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
403
404 if (process_type == switches::kGpuProcess)
405 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
406
407 return -1;
408}
409#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
410
[email protected]7c60f5042013-02-14 03:39:32411// Transforms the input |url| into its "effective URL". The returned URL
[email protected]c5dec6292013-01-25 04:54:52412// facilitates grouping process-per-site. The |url| is transformed, for
413// example, from
414//
415// https://www.google.com/search?espv=1&q=tractors
416//
[email protected]7c60f5042013-02-14 03:39:32417// to the effective URL
[email protected]c5dec6292013-01-25 04:54:52418//
419// chrome-search://www.google.com/search?espv=1&q=tractors
420//
421// Notice the scheme change.
[email protected]7c60f5042013-02-14 03:39:32422//
423// If the input is already an effective URL then that same URL is returned.
424GURL GetEffectiveURLForInstant(const GURL& url, Profile* profile) {
425 CHECK(chrome::search::ShouldAssignURLToInstantRenderer(url, profile))
426 << "Error granting Instant access.";
[email protected]c5dec6292013-01-25 04:54:52427
428 if (url.SchemeIs(chrome::kChromeSearchScheme))
429 return url;
430
431 GURL effective_url(url);
432
433 // Replace the scheme with "chrome-search:".
434 url_canon::Replacements<char> replacements;
435 std::string search_scheme(chrome::kChromeSearchScheme);
436 replacements.SetScheme(search_scheme.data(),
437 url_parse::Component(0, search_scheme.length()));
438 effective_url = effective_url.ReplaceComponents(replacements);
439 return effective_url;
440}
441
[email protected]9dbfff12011-07-01 19:37:07442} // namespace
[email protected]c5dbef02011-05-13 05:06:09443
[email protected]d977f9c2011-03-14 16:10:26444namespace chrome {
445
[email protected]e461da2f2012-02-16 19:06:40446ChromeContentBrowserClient::ChromeContentBrowserClient() {
447 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
448 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40449}
450
451ChromeContentBrowserClient::~ChromeContentBrowserClient() {
452}
453
[email protected]bca18382012-06-25 19:15:23454// static
[email protected]c753f142013-02-10 13:14:04455void ChromeContentBrowserClient::RegisterUserPrefs(
456 PrefRegistrySyncable* registry) {
457 registry->RegisterBooleanPref(prefs::kDisable3DAPIs,
458 false,
459 PrefRegistrySyncable::UNSYNCABLE_PREF);
460 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
461 true,
462 PrefRegistrySyncable::UNSYNCABLE_PREF);
463 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo,
464 false,
465 PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23466}
467
[email protected]50462bf02011-11-21 19:13:31468content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
469 const content::MainFunctionParams& parameters) {
470 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30471 // Construct the Main browser parts based on the OS type.
472#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31473 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04474#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31475 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30476#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22477 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26478#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31479 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14480#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09481 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30482#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31483 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04484#else
[email protected]b48c9182011-10-26 18:03:30485 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31486 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30487#endif
488
[email protected]c7480942011-11-08 19:18:27489 // Construct additional browser parts. Stages are called in the order in
490 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22491#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41492 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04493#endif
[email protected]c7480942011-11-08 19:18:27494
495#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41496 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27497#endif
498
[email protected]dc04be7c2012-03-15 23:57:49499#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41500 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49501#endif
502
[email protected]e050ef142012-03-21 01:04:24503#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41504 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24505#endif
506
[email protected]50462bf02011-11-21 19:13:31507 return main_parts;
[email protected]f967b722011-09-07 00:58:04508}
509
[email protected]e94bbcb2012-09-07 05:33:57510std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19511 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57512 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53513 std::string partition_id;
514
515 // The partition ID for webview guest processes is the string value of its
516 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
517 if (site.SchemeIs(chrome::kGuestScheme))
518 partition_id = site.spec();
519
520 DCHECK(IsValidStoragePartitionId(browser_context,partition_id));
521 return partition_id;
522}
523
524bool ChromeContentBrowserClient::IsValidStoragePartitionId(
525 content::BrowserContext* browser_context,
526 const std::string& partition_id) {
527 // The default ID is empty and is always valid.
528 if (partition_id.empty())
529 return true;
530
531 return GURL(partition_id).is_valid();
532}
533
534void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
535 content::BrowserContext* browser_context,
536 const GURL& site,
[email protected]14acc642012-11-17 12:20:10537 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53538 std::string* partition_domain,
539 std::string* partition_name,
540 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10541 // Default to the browser-wide storage partition and override based on |site|
542 // below.
543 partition_domain->clear();
544 partition_name->clear();
545 *in_memory = false;
546
[email protected]1bc28312012-11-08 08:31:53547 // For the webview tag, we create special guest processes, which host the
548 // tag content separately from the main application that embeds the tag.
549 // A webview tag can specify both the partition name and whether the storage
550 // for that partition should be persisted. Each tag gets a SiteInstance with
551 // a specially formatted URL, based on the application it is hosted by and
552 // the partition requested by it. The format for that URL is:
553 // chrome-guest://partition_domain/persist?partition_name
554 if (site.SchemeIs(chrome::kGuestScheme)) {
555 // Since guest URLs are only used for packaged apps, there must be an app
556 // id in the URL.
557 CHECK(site.has_host());
558 *partition_domain = site.host();
559 // Since persistence is optional, the path must either be empty or the
560 // literal string.
561 *in_memory = (site.path() != "/persist");
562 // The partition name is user supplied value, which we have encoded when the
563 // URL was created, so it needs to be decoded.
564 *partition_name = net::UnescapeURLComponent(site.query(),
565 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10566 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
567 // If |can_be_default| is false, the caller is stating that the |site|
568 // should be parsed as if it had isolated storage. In particular it is
569 // important to NOT check ExtensionService for the is_storage_isolated()
570 // attribute because this code path is run during Extension uninstall
571 // to do cleanup after the Extension has already been unloaded from the
572 // ExtensionService.
573 bool is_isolated = !can_be_default;
574 if (can_be_default) {
575 const Extension* extension = NULL;
576 Profile* profile = Profile::FromBrowserContext(browser_context);
577 ExtensionService* extension_service =
578 extensions::ExtensionSystem::Get(profile)->extension_service();
579 if (extension_service) {
580 extension = extension_service->extensions()->
581 GetExtensionOrAppByURL(ExtensionURLInfo(site));
582 if (extension && extension->is_storage_isolated()) {
583 is_isolated = true;
584 }
585 }
586 }
[email protected]1bc28312012-11-08 08:31:53587
[email protected]14acc642012-11-17 12:20:10588 if (is_isolated) {
589 CHECK(site.has_host());
590 // For extensions with isolated storage, the the host of the |site| is
591 // the |partition_domain|. The |in_memory| and |partition_name| are only
592 // used in guest schemes so they are cleared here.
593 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53594 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10595 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53596 }
[email protected]d1198fd2012-08-13 22:50:19597 }
598
[email protected]14acc642012-11-17 12:20:10599 // Assert that if |can_be_default| is false, the code above must have found a
600 // non-default partition. If this fails, the caller has a serious logic
601 // error about which StoragePartition they expect to be in and it is not
602 // safe to continue.
603 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44604}
605
[email protected]38b098f2012-03-14 21:11:57606content::WebContentsViewDelegate*
607 ChromeContentBrowserClient::GetWebContentsViewDelegate(
608 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27609 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32610}
611
[email protected]f364d1392011-04-08 21:03:10612void ChromeContentBrowserClient::RenderViewHostCreated(
613 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46614
[email protected]9f76c1e2012-03-05 15:15:58615 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46616 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02617 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46618
619 new ChromeRenderViewHostObserver(render_view_host,
620 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49621 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26622}
623
[email protected]24665682013-02-25 20:59:38624// Check if the extension activity log is enabled for the profile.
625static bool IsExtensionActivityLogEnabledForProfile(Profile* profile) {
626 extensions::ActivityLog* activity_log =
627 extensions::ActivityLog::GetInstance(profile);
628 return activity_log->IsLogEnabled();
629}
630
[email protected]44703cc72013-01-24 04:56:06631void ChromeContentBrowserClient::GuestWebContentsCreated(
632 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
633 Profile* profile = Profile::FromBrowserContext(
634 embedder_web_contents->GetBrowserContext());
635 ExtensionService* service =
636 extensions::ExtensionSystem::Get(profile)->extension_service();
637 if (!service)
638 return;
639 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
640 const Extension* extension = service->extensions()->
641 GetExtensionOrAppByURL(ExtensionURLInfo(url));
642 if (!extension)
643 return;
644 std::vector<ExtensionMsg_Loaded_Params> extensions;
645 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
646 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
647}
648
[email protected]f3b1a082011-11-18 00:34:30649void ChromeContentBrowserClient::RenderProcessHostCreated(
650 content::RenderProcessHost* host) {
651 int id = host->GetID();
652 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
[email protected]43535512013-02-20 20:41:41653 net::URLRequestContextGetter* context =
654 profile->GetRequestContextForRenderProcess(id);
655
[email protected]f3b1a082011-11-18 00:34:30656 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]43535512013-02-20 20:41:41657 id, profile, context));
[email protected]ebd71962012-12-20 02:56:55658#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30659 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55660#endif
[email protected]658677f2012-06-09 06:04:02661#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08662 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03663#endif
[email protected]f3b1a082011-11-18 00:34:30664 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02665 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30666 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56667#if defined(OS_MACOSX)
668 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
669#endif
[email protected]43535512013-02-20 20:41:41670 host->GetChannel()->AddFilter(new ChromeNetBenchmarkingMessageFilter(
671 id, profile, context));
[email protected]2736c032012-05-11 18:06:07672 host->GetChannel()->AddFilter(
673 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38674
[email protected]2ccf45c2011-08-19 23:35:50675 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
676 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07677
[email protected]24665682013-02-25 20:59:38678 host->Send(new ChromeViewMsg_SetExtensionActivityLogEnabled(
679 IsExtensionActivityLogEnabledForProfile(profile)));
680
[email protected]39a5b532011-10-22 01:47:07681 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56682
683 RendererContentSettingRules rules;
684 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
685 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14686}
687
[email protected]3d7474ff2011-07-27 17:47:37688GURL ChromeContentBrowserClient::GetEffectiveURL(
689 content::BrowserContext* browser_context, const GURL& url) {
690 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52691 if (!profile)
692 return url;
693
[email protected]7c60f5042013-02-14 03:39:32694 // If the input |url| should be assigned to the Instant renderer, make its
695 // effective URL distinct from other URLs on the search provider's domain.
696 if (chrome::search::ShouldAssignURLToInstantRenderer(url, profile))
697 return GetEffectiveURLForInstant(url, profile);
[email protected]c5dec6292013-01-25 04:54:52698
699 // If the input |url| is part of an installed app, the effective URL is an
700 // extension URL with the ID of that extension as the host. This has the
701 // effect of grouping apps together in a common SiteInstance.
702 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13703 extensions::ExtensionSystem::Get(profile)->extension_service();
704 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08705 return url;
706
[email protected]06bdd2b2012-11-30 18:47:13707 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44708 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08709 if (!extension)
710 return url;
711
[email protected]15877ca2011-11-18 22:40:52712 // Bookmark apps do not use the hosted app process model, and should be
713 // treated as normal URLs.
714 if (extension->from_bookmark())
715 return url;
716
[email protected]36fb2c7c2011-04-04 15:49:08717 // If the URL is part of an extension's web extent, convert it to an
718 // extension URL.
719 return extension->GetResourceURL(url.path());
720}
721
[email protected]056ad2a2011-07-12 02:13:55722bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37723 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52724 // Non-extension, non-Instant URLs should generally use
725 // process-per-site-instance. Because we expect to use the effective URL,
726 // URLs for hosted apps (apart from bookmark apps) should have an extension
727 // scheme by now.
728
729 Profile* profile = Profile::FromBrowserContext(browser_context);
730 if (!profile)
731 return false;
732
[email protected]7c60f5042013-02-14 03:39:32733 if (chrome::search::ShouldAssignURLToInstantRenderer(effective_url, profile))
[email protected]c5dec6292013-01-25 04:54:52734 return true;
735
[email protected]885c0e92012-11-13 20:27:42736 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55737 return false;
738
[email protected]c5dec6292013-01-25 04:54:52739 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13740 extensions::ExtensionSystem::Get(profile)->extension_service();
741 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55742 return false;
743
[email protected]06bdd2b2012-11-30 18:47:13744 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44745 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55746 if (!extension)
747 return false;
748
749 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53750 // permission, or that does not allow JavaScript access to the background
751 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55752 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40753 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06754 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]9367eabc2013-03-01 01:29:29755 !extensions::BackgroundInfo::AllowJSAccess(extension)) {
[email protected]7b54ca02012-03-02 18:06:53756 return false;
757 }
758 }
[email protected]056ad2a2011-07-12 02:13:55759
[email protected]7b54ca02012-03-02 18:06:53760 // Hosted apps that have script access to their background page must use
761 // process per site, since all instances can make synchronous calls to the
762 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55763 return true;
764}
765
[email protected]6bd30072013-02-08 18:17:11766net::URLRequestContextGetter*
767ChromeContentBrowserClient::CreateRequestContext(
768 content::BrowserContext* browser_context,
[email protected]9c3ed0a2013-03-06 08:57:05769 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
770 blob_protocol_handler,
771 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
772 file_system_protocol_handler,
773 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
774 developer_protocol_handler,
775 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
776 chrome_protocol_handler,
777 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
778 chrome_devtools_protocol_handler) {
[email protected]6bd30072013-02-08 18:17:11779 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]9c3ed0a2013-03-06 08:57:05780 return profile->CreateRequestContext(blob_protocol_handler.Pass(),
781 file_system_protocol_handler.Pass(),
782 developer_protocol_handler.Pass(),
783 chrome_protocol_handler.Pass(),
784 chrome_devtools_protocol_handler.Pass());
[email protected]6bd30072013-02-08 18:17:11785}
786
787net::URLRequestContextGetter*
788ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
789 content::BrowserContext* browser_context,
[email protected]152ea302013-02-11 04:08:40790 const base::FilePath& partition_path,
[email protected]6bd30072013-02-08 18:17:11791 bool in_memory,
[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);
803 return profile->CreateRequestContextForStoragePartition(
[email protected]9c3ed0a2013-03-06 08:57:05804 partition_path,
805 in_memory,
806 blob_protocol_handler.Pass(),
807 file_system_protocol_handler.Pass(),
808 developer_protocol_handler.Pass(),
809 chrome_protocol_handler.Pass(),
810 chrome_devtools_protocol_handler.Pass());
[email protected]6bd30072013-02-08 18:17:11811}
812
[email protected]46fb9442011-12-09 17:57:47813bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
814 return ProfileIOData::IsHandledURL(url);
815}
816
[email protected]2a5221b2011-09-27 23:07:31817bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30818 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31819 const GURL& site_url) {
820 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30821 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52822 // This may be NULL during tests. In that case, just assume any site can
823 // share any host.
824 if (!profile)
825 return true;
826
827 InstantService* instant_service =
828 InstantServiceFactory::GetForProfile(profile);
829 if (instant_service &&
830 instant_service->IsInstantProcess(process_host->GetID()))
[email protected]7c60f5042013-02-14 03:39:32831 return chrome::search::ShouldAssignURLToInstantRenderer(site_url, profile);
[email protected]c5dec6292013-01-25 04:54:52832
[email protected]06bdd2b2012-11-30 18:47:13833 ExtensionService* service =
834 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46835 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31836
[email protected]ffa97602011-11-17 17:55:52837 // Don't allow the Task Manager to share a process with anything else.
838 // Otherwise it can affect the renderers it is observing.
839 // Note: we could create another RenderProcessHostPrivilege bucket for
840 // this to allow multiple chrome://tasks instances to share, but that's
841 // a very unlikely case without serious consequences.
842 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
843 return false;
844
[email protected]8d3132f62011-10-12 07:13:42845 // These may be NULL during tests. In that case, just assume any site can
846 // share any host.
[email protected]6f371442011-11-09 06:45:46847 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31848 return true;
849
[email protected]eec0b33c2011-12-05 22:09:45850 // Otherwise, just make sure the process privilege matches the privilege
851 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57852 RenderProcessHostPrivilege privilege_required =
853 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45854 return GetProcessPrivilege(process_host, process_map, service) ==
855 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31856}
857
[email protected]76411f412012-02-22 18:56:06858// This function is trying to limit the amount of processes used by extensions
859// with background pages. It uses a globally set percentage of processes to
860// run such extensions and if the limit is exceeded, it returns true, to
861// indicate to the content module to group extensions together.
862bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
863 content::BrowserContext* browser_context, const GURL& url) {
864 // It has to be a valid URL for us to check for an extension.
865 if (!url.is_valid())
866 return false;
867
868 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19869 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13870 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06871 if (!service)
872 return false;
873
874 // We have to have a valid extension with background page to proceed.
875 const Extension* extension =
876 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
877 if (!extension)
878 return false;
[email protected]9367eabc2013-03-01 01:29:29879 if (!extensions::BackgroundInfo::HasBackgroundPage(extension))
[email protected]76411f412012-02-22 18:56:06880 return false;
881
882 std::set<int> process_ids;
883 size_t max_process_count =
884 content::RenderProcessHost::GetMaxRendererProcessCount();
885
886 // Go through all profiles to ensure we have total count of extension
887 // processes containing background pages, otherwise one profile can
888 // starve the other.
889 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
890 GetLoadedProfiles();
891 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03892 ExtensionProcessManager* epm =
893 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32894 for (ExtensionProcessManager::const_iterator iter =
895 epm->background_hosts().begin();
896 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13897 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32898 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06899 }
900 }
901
902 if (process_ids.size() >
903 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
904 return true;
905 }
906
907 return false;
908}
909
[email protected]6f371442011-11-09 06:45:46910void ChromeContentBrowserClient::SiteInstanceGotProcess(
911 SiteInstance* site_instance) {
912 CHECK(site_instance->HasProcess());
913
914 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02915 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52916 if (!profile)
917 return;
918
919 // Remember the ID of the Instant process to signal the renderer process
920 // on startup in |AppendExtraCommandLineSwitches| below.
[email protected]7c60f5042013-02-14 03:39:32921 if (chrome::search::ShouldAssignURLToInstantRenderer(
922 site_instance->GetSiteURL(), profile)) {
[email protected]c5dec6292013-01-25 04:54:52923 InstantService* instant_service =
924 InstantServiceFactory::GetForProfile(profile);
925 if (instant_service)
926 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
927 }
928
[email protected]06bdd2b2012-11-30 18:47:13929 ExtensionService* service =
930 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46931 if (!service)
932 return;
933
934 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44935 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59936 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46937 if (!extension)
938 return;
939
[email protected]6bc04fd82011-12-04 02:29:35940 service->process_map()->Insert(extension->id(),
941 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33942 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46943 BrowserThread::PostTask(
944 BrowserThread::IO, FROM_HERE,
945 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59946 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46947 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35948 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33949 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46950}
951
952void ChromeContentBrowserClient::SiteInstanceDeleting(
953 SiteInstance* site_instance) {
954 if (!site_instance->HasProcess())
955 return;
956
957 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02958 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13959 ExtensionService* service =
960 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46961 if (!service)
962 return;
963
964 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44965 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:59966 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46967 if (!extension)
968 return;
969
[email protected]6bc04fd82011-12-04 02:29:35970 service->process_map()->Remove(extension->id(),
971 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33972 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46973 BrowserThread::PostTask(
974 BrowserThread::IO, FROM_HERE,
975 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59976 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46977 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35978 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33979 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46980}
981
[email protected]f05763972012-06-06 18:17:26982bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e9841fbd2013-02-22 23:12:14983 SiteInstance* site_instance,
[email protected]e3daf3c2011-10-05 21:17:08984 const GURL& current_url,
985 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26986 if (current_url.is_empty()) {
987 // Always choose a new process when navigating to extension URLs. The
988 // process grouping logic will combine all of a given extension's pages
989 // into the same process.
[email protected]885c0e92012-11-13 20:27:42990 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:26991 return true;
[email protected]e3daf3c2011-10-05 21:17:08992
[email protected]f05763972012-06-06 18:17:26993 return false;
994 }
995
996 // Also, we must switch if one is an extension and the other is not the exact
997 // same extension.
[email protected]885c0e92012-11-13 20:27:42998 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
999 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261000 if (current_url.GetOrigin() != new_url.GetOrigin())
1001 return true;
1002 }
1003
[email protected]e9841fbd2013-02-22 23:12:141004 // The checks below only matter if we can retrieve which extensions are
1005 // installed.
1006 Profile* profile =
1007 Profile::FromBrowserContext(site_instance->GetBrowserContext());
1008 ExtensionService* service =
1009 extensions::ExtensionSystem::Get(profile)->extension_service();
1010 if (!service)
1011 return false;
1012
1013 // We must swap if the URL is for an extension and we are not using an
1014 // extension process.
1015 const Extension* new_extension =
1016 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(new_url));
1017 // Ignore all hosted apps except the Chrome Web Store, since they do not
1018 // require their own BrowsingInstance (e.g., postMessage is ok).
1019 if (new_extension &&
1020 new_extension->is_hosted_app() &&
1021 new_extension->id() != extension_misc::kWebStoreAppId)
1022 new_extension = NULL;
1023 if (new_extension &&
1024 site_instance->HasProcess() &&
1025 !service->process_map()->Contains(new_extension->id(),
1026 site_instance->GetProcess()->GetID()))
1027 return true;
1028
[email protected]f05763972012-06-06 18:17:261029 return false;
[email protected]e3daf3c2011-10-05 21:17:081030}
1031
[email protected]395045c2012-05-22 15:04:381032bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1033 content::ResourceContext* resource_context, const GURL& current_url,
1034 const GURL& new_url) {
1035 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1036 return extensions::CrossesExtensionProcessBoundary(
1037 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171038 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381039}
1040
[email protected]763ec4ca2011-04-29 15:48:121041std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1042 const std::string& alias_name) {
1043 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1044}
1045
[email protected]b80f68432011-05-02 17:22:301046void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1047 CommandLine* command_line, int child_process_id) {
1048#if defined(USE_LINUX_BREAKPAD)
1049 if (IsCrashReporterEnabled()) {
1050 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1051 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1052 }
1053#elif defined(OS_MACOSX)
1054 if (IsCrashReporterEnabled()) {
1055 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1056 child_process_logging::GetClientId());
1057 }
1058#endif // OS_MACOSX
1059
[email protected]f1933792011-06-14 00:49:341060 if (logging::DialogsAreSuppressed())
1061 command_line->AppendSwitch(switches::kNoErrorDialogs);
1062
[email protected]b80f68432011-05-02 17:22:301063 std::string process_type =
1064 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171065 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:521066 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451067 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301068 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1069 if (!user_data_dir.empty())
1070 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1071#if defined(OS_CHROMEOS)
1072 const std::string& login_profile =
1073 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
1074 if (!login_profile.empty())
1075 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
1076#endif
1077
[email protected]f3b1a082011-11-18 00:34:301078 content::RenderProcessHost* process =
1079 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371080 if (process) {
1081 Profile* profile = Profile::FromBrowserContext(
1082 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131083 ExtensionService* extension_service =
1084 extensions::ExtensionSystem::Get(profile)->extension_service();
1085 if (extension_service) {
1086 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001087 if (process_map && process_map->Contains(process->GetID()))
1088 command_line->AppendSwitch(switches::kExtensionProcess);
1089 }
[email protected]b80f68432011-05-02 17:22:301090
[email protected]a8d851f82011-12-21 00:32:371091 PrefService* prefs = profile->GetPrefs();
1092 // Currently this pref is only registered if applied via a policy.
1093 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1094 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1095 // Turn this policy into a command line switch.
1096 command_line->AppendSwitch(switches::kDisable3DAPIs);
1097 }
[email protected]718eab62011-10-05 21:16:521098
[email protected]a8d851f82011-12-21 00:32:371099 // Disable client-side phishing detection in the renderer if it is
1100 // disabled in the Profile preferences or the browser process.
1101 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1102 !g_browser_process->safe_browsing_detection_service()) {
1103 command_line->AppendSwitch(
1104 switches::kDisableClientSidePhishingDetection);
1105 }
[email protected]0045b0f42012-07-26 11:52:081106
1107 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211108 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521109
1110 InstantService* instant_service =
1111 InstantServiceFactory::GetForProfile(profile);
1112 if (instant_service &&
1113 instant_service->IsInstantProcess(process->GetID()))
1114 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]47c7ec82012-01-18 03:29:211115 }
[email protected]4287a3d2011-06-13 23:56:511116
[email protected]87552982012-11-02 17:21:401117 if (content::IsThreadedCompositingEnabled())
1118 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1119
[email protected]47c7ec82012-01-18 03:29:211120 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511121 static const char* const kSwitchNames[] = {
1122 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481123 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511124 switches::kAllowScriptingGallery,
1125 switches::kAppsCheckoutURL,
1126 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311127 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511128 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501129 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531130 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111131 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511132 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:211133 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511134 switches::kEnableCrxlessWebApps,
1135 switches::kEnableExperimentalExtensionApis,
[email protected]dcfefa52013-02-15 07:46:561136 switches::kEnableExperimentalFormFilling,
[email protected]4287a3d2011-06-13 23:56:511137 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511138 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511139 switches::kEnableNaCl,
[email protected]ce304ce2013-02-22 21:54:451140 switches::kEnableNetBenchmarking,
[email protected]bcbe7652012-02-22 00:08:481141 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051142 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511143 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511144 switches::kMemoryProfiling,
1145 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371146 switches::kNoJsRandomness,
[email protected]732b1604e2012-10-26 19:59:581147 switches::kPerformCrashAnalysis,
[email protected]f45c5f32012-04-18 19:26:371148 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511149 switches::kPpapiFlashArgs,
1150 switches::kPpapiFlashInProcess,
1151 switches::kPpapiFlashPath,
1152 switches::kPpapiFlashVersion,
1153 switches::kProfilingAtStart,
1154 switches::kProfilingFile,
1155 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371156 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511157 switches::kSilentDumpOnDCHECK,
[email protected]199def22013-02-21 17:52:291158 switches::kSpdyProxyAuthOrigin,
[email protected]a446534d2012-02-09 00:07:381159 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511160 };
1161
1162 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1163 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171164 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381165 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351166 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381167 switches::kEnableExperimentalExtensionApis,
1168 switches::kWhitelistedExtensionID,
1169 };
1170
1171 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1172 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511173 } else if (process_type == switches::kPluginProcess) {
1174 static const char* const kSwitchNames[] = {
1175 #if defined(OS_CHROMEOS)
1176 switches::kLoginProfile,
1177 #endif
1178 switches::kMemoryProfiling,
1179 switches::kSilentDumpOnDCHECK,
1180 switches::kUserDataDir,
1181 };
1182
1183 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1184 arraysize(kSwitchNames));
1185 } else if (process_type == switches::kZygoteProcess) {
1186 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511187 switches::kUserDataDir, // Make logs go to the right file.
1188 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501189 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511190 switches::kPpapiFlashInProcess,
1191 switches::kPpapiFlashPath,
1192 switches::kPpapiFlashVersion,
1193 };
1194
1195 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1196 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111197 } else if (process_type == switches::kGpuProcess) {
[email protected]f01b88a2013-02-27 22:04:001198 base::FilePath user_data_dir =
1199 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1200 if (!user_data_dir.empty())
1201 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
[email protected]d56ecf922012-02-15 16:03:111202 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1203 // because GPU is expected to be unreliable.
1204 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1205 !command_line->HasSwitch(switches::kDisableBreakpad))
1206 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301207 }
[email protected]6f08af82011-09-15 01:19:031208
1209 // The command line switch kEnableBenchmarking needs to be specified along
1210 // with the kEnableStatsTable switch to ensure that the stats table global
1211 // is initialized correctly.
1212 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1213 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301214}
1215
1216std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431217 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1218 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:301219 return g_browser_process->GetApplicationLocale();
1220}
1221
[email protected]597a867b2011-11-18 18:31:201222std::string ChromeContentBrowserClient::GetAcceptLangs(
1223 content::BrowserContext* context) {
1224 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371225 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081226}
1227
[email protected]9ec0f452012-05-31 15:58:531228gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221229 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531230 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081231}
1232
[email protected]a2176792011-05-08 19:30:491233bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091234 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191235 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201236 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201238 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051239 return io_data->GetCookieSettings()->
1240 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491241}
1242
[email protected]ed24fad2011-05-10 22:44:011243bool ChromeContentBrowserClient::AllowGetCookie(
1244 const GURL& url,
1245 const GURL& first_party,
1246 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201247 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011248 int render_process_id,
1249 int render_view_id) {
1250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201251 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051252 bool allow = io_data->GetCookieSettings()->
1253 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011254
[email protected]8093a542011-05-13 07:29:321255 BrowserThread::PostTask(
1256 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031257 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431258 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011259 return allow;
1260}
1261
1262bool ChromeContentBrowserClient::AllowSetCookie(
1263 const GURL& url,
1264 const GURL& first_party,
1265 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201266 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011267 int render_process_id,
1268 int render_view_id,
1269 net::CookieOptions* options) {
1270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201271 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051272 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1273 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1274
[email protected]8093a542011-05-13 07:29:321275 BrowserThread::PostTask(
1276 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031277 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431278 render_view_id, url, first_party, cookie_line, *options,
1279 !allow));
[email protected]ed24fad2011-05-10 22:44:011280 return allow;
1281}
1282
[email protected]d5a19162011-06-30 18:51:541283bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201284 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201286 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431287 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1288 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261289
[email protected]bf510ed2012-06-05 08:31:431290 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1291 // Could we even support per-origin settings?
1292 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541293}
1294
[email protected]5c5a88e2011-11-12 00:45:351295bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351296 const GURL& url,
1297 const string16& name,
1298 const string16& display_name,
1299 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201300 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481301 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201303 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351304 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1305 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1306
[email protected]62151052012-02-01 18:40:481307 // Record access to database for potential display in UI.
1308 std::vector<std::pair<int, int> >::const_iterator i;
1309 for (i = render_views.begin(); i != render_views.end(); ++i) {
1310 BrowserThread::PostTask(
1311 BrowserThread::UI, FROM_HERE,
1312 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1313 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351314 }
1315
1316 return allow;
1317}
1318
1319bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351320 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201321 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481322 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201324 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351325 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1326 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1327
[email protected]62151052012-02-01 18:40:481328 // Record access to file system for potential display in UI.
1329 std::vector<std::pair<int, int> >::const_iterator i;
1330 for (i = render_views.begin(); i != render_views.end(); ++i) {
1331 BrowserThread::PostTask(
1332 BrowserThread::UI, FROM_HERE,
1333 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1334 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351335 }
1336
1337 return allow;
1338}
1339
[email protected]7c5ff9a2012-03-02 07:42:491340bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1341 const GURL& url,
1342 const string16& name,
1343 content::ResourceContext* context,
1344 const std::vector<std::pair<int, int> >& render_views) {
1345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1346 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1347 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1348 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1349
1350 // Record access to IndexedDB for potential display in UI.
1351 std::vector<std::pair<int, int> >::const_iterator i;
1352 for (i = render_views.begin(); i != render_views.end(); ++i) {
1353 BrowserThread::PostTask(
1354 BrowserThread::UI, FROM_HERE,
1355 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1356 i->first, i->second, url, name, !allow));
1357 }
1358
1359 return allow;
1360}
1361
[email protected]6133f922011-07-01 21:34:341362net::URLRequestContext*
1363ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201364 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421366 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201367 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341368 return io_data->extensions_request_context();
1369 }
1370
1371 return NULL;
1372}
1373
[email protected]317f96c92011-05-31 06:53:411374QuotaPermissionContext*
1375ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1376 return new ChromeQuotaPermissionContext();
1377}
1378
[email protected]848dd042011-06-04 18:24:031379void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171380 int render_process_id,
1381 int render_view_id,
1382 int cert_error,
1383 const net::SSLInfo& ssl_info,
1384 const GURL& request_url,
[email protected]a2f76882013-02-25 21:36:021385 ResourceType::Type resource_type,
[email protected]848dd042011-06-04 18:24:031386 bool overridable,
[email protected]d9be47702012-05-16 03:41:221387 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171388 const base::Callback<void(bool)>& callback,
1389 bool* cancel_request) {
[email protected]a2f76882013-02-25 21:36:021390 if (resource_type != ResourceType::MAIN_FRAME) {
1391 // A sub-resource has a certificate error. The user doesn't really
1392 // have a context for making the right decision, so block the
1393 // request hard, without an info bar to allow showing the insecure
1394 // content.
1395 *cancel_request = true;
1396 return;
1397 }
1398
[email protected]f9034cf2011-07-21 12:43:411399 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131400 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171401 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411402 if (!tab) {
1403 NOTREACHED();
1404 return;
1405 }
1406 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501407 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301408 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011409 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1410 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411411 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171412 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411413 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171414 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411415 return;
1416 }
1417 }
1418
[email protected]1e87df32012-09-12 04:53:191419#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231420 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1421 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1422 if (captive_portal_tab_helper)
1423 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191424#endif
1425
[email protected]f9034cf2011-07-21 12:43:411426 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221427 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1428 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031429}
1430
[email protected]c99c442e2011-08-24 11:37:301431void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451432 int render_process_id,
1433 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401434 const net::HttpNetworkSession* network_session,
1435 net::SSLCertRequestInfo* cert_request_info,
1436 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131437 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451438 render_process_id, render_view_id);
1439 if (!tab) {
1440 NOTREACHED();
1441 return;
1442 }
1443
[email protected]6786bf402011-12-03 15:19:451444 GURL requesting_url("https://" + cert_request_info->host_and_port);
1445 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1446 << cert_request_info->host_and_port;
1447
[email protected]627e0512011-12-21 22:55:301448 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451449 scoped_ptr<Value> filter(
1450 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1451 requesting_url,
1452 requesting_url,
1453 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1454 std::string(), NULL));
1455
1456 if (filter.get()) {
1457 // Try to automatically select a client certificate.
1458 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1459 DictionaryValue* filter_dict =
1460 static_cast<DictionaryValue*>(filter.get());
1461
1462 const std::vector<scoped_refptr<net::X509Certificate> >&
1463 all_client_certs = cert_request_info->client_certs;
1464 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1465 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1466 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401467 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451468 return;
1469 }
1470 }
1471 } else {
1472 NOTREACHED();
1473 }
1474 }
1475
[email protected]11feec322012-09-18 03:58:521476 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1477 if (!ssl_tab_helper) {
1478 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451479 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141480 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401481 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451482 return;
1483 }
[email protected]11feec322012-09-18 03:58:521484 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401485 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451486}
1487
[email protected]3b455502012-12-11 18:22:581488void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451489 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581490 net::CertificateMimeType cert_type,
1491 const void* cert_data,
1492 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451493 int render_process_id,
1494 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581495 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1496 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451497}
1498
[email protected]dc73a7b2012-03-25 15:27:181499content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561500 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181501}
1502
[email protected]941623e2011-06-07 23:06:041503void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1504 const GURL& source_origin,
1505 int callback_context,
1506 int render_process_id,
1507 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111508#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1510 WebContents* contents =
1511 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1512 if (!contents) {
[email protected]941623e2011-06-07 23:06:041513 NOTREACHED();
1514 return;
1515 }
1516
[email protected]d0d9c3ee2012-06-19 03:07:021517 // Skip showing the infobar if the request comes from an extension, and that
1518 // extension has the 'notify' permission. (If the extension does not have the
1519 // permission, the user will still be prompted.)
1520 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131521 ExtensionService* service =
1522 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]d0d9c3ee2012-06-19 03:07:021523 const Extension* extension = !service ? NULL :
1524 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1525 source_origin));
[email protected]eb4832a2012-12-08 01:57:521526 RenderViewHost* rvh =
1527 RenderViewHost::FromID(render_process_id, render_view_id);
1528 if (IsExtensionWithPermissionOrSuggestInConsole(
1529 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021530 if (rvh)
1531 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1532 return;
1533 }
1534
1535 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371536 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021537 notifications->RequestPermission(source_origin, render_process_id,
1538 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111539#else
1540 NOTIMPLEMENTED();
1541#endif
[email protected]941623e2011-06-07 23:06:041542}
1543
1544WebKit::WebNotificationPresenter::Permission
1545 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021546 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201547 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021548 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111549#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201551 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021552 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1553 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061554 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041555 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041556
1557 // Fall back to the regular notification preferences, which works on an
1558 // origin basis.
1559 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371560 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041561 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111562#else
1563 return WebKit::WebNotificationPresenter::PermissionAllowed;
1564#endif
[email protected]941623e2011-06-07 23:06:041565}
1566
1567void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171568 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041569 int render_process_id,
1570 int render_view_id,
1571 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111572#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041573 RenderViewHost* rvh = RenderViewHost::FromID(
1574 render_process_id, render_view_id);
1575 if (!rvh) {
1576 NOTREACHED();
1577 return;
1578 }
1579
[email protected]9f76c1e2012-03-05 15:15:581580 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301581 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041582 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371583 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041584 service->ShowDesktopNotification(
1585 params, render_process_id, render_view_id,
1586 worker ? DesktopNotificationService::WorkerNotification :
1587 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111588#else
1589 NOTIMPLEMENTED();
1590#endif
[email protected]941623e2011-06-07 23:06:041591}
1592
1593void ChromeContentBrowserClient::CancelDesktopNotification(
1594 int render_process_id,
1595 int render_view_id,
1596 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111597#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041598 RenderViewHost* rvh = RenderViewHost::FromID(
1599 render_process_id, render_view_id);
1600 if (!rvh) {
1601 NOTREACHED();
1602 return;
1603 }
1604
[email protected]9f76c1e2012-03-05 15:15:581605 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301606 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041607 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371608 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041609 service->CancelDesktopNotification(
1610 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111611#else
1612 NOTIMPLEMENTED();
1613#endif
[email protected]941623e2011-06-07 23:06:041614}
1615
[email protected]9f3fba52011-06-08 20:37:191616bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351617 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021618 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191619 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201620 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011621 int render_process_id,
1622 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191623 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011624
1625 *no_javascript_access = false;
1626
[email protected]9f3fba52011-06-08 20:37:191627 // If the opener is trying to create a background window but doesn't have
1628 // the appropriate permission, fail the attempt.
1629 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201630 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531631 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1632
[email protected]03b6d552012-03-29 04:03:011633 if (!map->SecurityOriginHasAPIPermission(
1634 source_origin,
1635 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061636 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011637 return false;
1638 }
1639
[email protected]7b54ca02012-03-02 18:06:531640 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1641 // return a recently installed Extension even if this CanCreateWindow call
1642 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011643 // because the permission check above would have caused an early return
1644 // already. We must use the full URL to find hosted apps, though, and not
1645 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531646 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351647 ExtensionURLInfo(opener_url));
[email protected]9367eabc2013-03-01 01:29:291648 if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension))
[email protected]03b6d552012-03-29 04:03:011649 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191650 }
1651 return true;
1652}
1653
1654std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201655 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1657 // Check if it's an extension-created worker, in which case we want to use
1658 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201659 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191660 const Extension* extension =
1661 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1662 return extension ? extension->name() : std::string();
1663}
1664
[email protected]99907362012-01-11 05:41:401665void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1666 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171667}
1668
[email protected]c52b2892012-03-07 11:01:021669content::SpeechRecognitionManagerDelegate*
1670 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321671#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021672 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321673#else
1674 return NULL;
1675#endif
[email protected]66cfec62012-02-24 17:57:511676}
1677
[email protected]ae6e9912011-07-27 01:18:281678net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1679 return g_browser_process->net_log();
1680}
1681
[email protected]32538d92011-08-25 00:09:231682AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1683 return new ChromeAccessTokenStore();
1684}
1685
[email protected]dbae6b02011-06-29 23:51:411686bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011687 return true;
[email protected]dbae6b02011-06-29 23:51:411688}
1689
[email protected]64d69de42012-02-06 00:19:541690void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321691 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061692 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581693 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061694 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061695
[email protected]f3986f82012-01-03 20:00:061696 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541697 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061698 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541699 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061700 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541701 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061702 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541703 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061704 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541705 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061706 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541707 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031708 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1709 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061710
[email protected]64d69de42012-02-06 00:19:541711 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401712 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541713 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401714 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541715 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401716 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541717 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401718 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061719
[email protected]ddf72142012-05-22 04:52:401720 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061721
[email protected]64d69de42012-02-06 00:19:541722 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401723 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541724 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061725 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541726 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061727 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1728 const DictionaryValue* inspector_settings =
1729 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1730 if (inspector_settings) {
[email protected]c40ef1c2013-02-25 18:42:181731 for (DictionaryValue::Iterator iter(*inspector_settings); !iter.IsAtEnd();
1732 iter.Advance()) {
[email protected]f3986f82012-01-03 20:00:061733 std::string value;
[email protected]c40ef1c2013-02-25 18:42:181734 if (iter.value().GetAsString(&value)) {
[email protected]64d69de42012-02-06 00:19:541735 web_prefs->inspector_settings.push_back(
[email protected]c40ef1c2013-02-25 18:42:181736 std::make_pair(iter.key(), value));
1737 }
[email protected]f3986f82012-01-03 20:00:061738 }
1739 }
[email protected]64d69de42012-02-06 00:19:541740 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061741
[email protected]ddf72142012-05-22 04:52:401742 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541743 web_prefs->javascript_enabled = false;
1744 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1745 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401746 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541747 web_prefs->plugins_enabled = false;
1748 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1749 web_prefs->java_enabled = false;
1750 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401751 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061752
[email protected]64d69de42012-02-06 00:19:541753 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1754 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061755
[email protected]64d69de42012-02-06 00:19:541756 web_prefs->memory_info_enabled =
1757 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1758 web_prefs->allow_displaying_insecure_content =
1759 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1760 web_prefs->allow_running_insecure_content =
1761 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321762#if defined(OS_ANDROID)
1763 web_prefs->font_scale_factor =
1764 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1765 web_prefs->force_enable_zoom =
1766 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
1767#endif
[email protected]9d06d88d2012-02-23 22:37:081768 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061769
[email protected]64d69de42012-02-06 00:19:541770 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151771 UserStyleSheetWatcher* user_style_sheet_watcher =
1772 UserStyleSheetWatcherFactory::GetForProfile(profile);
1773 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541774 web_prefs->user_style_sheet_enabled = true;
1775 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151776 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541777 } else {
1778 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061779 }
1780
[email protected]b7e44ff2012-02-16 03:37:341781 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101782#if defined(OS_MACOSX)
[email protected]325342e62013-01-09 02:29:031783 // TODO(groby): Bug 107371: Implement asynchronous spellchecking API for
[email protected]37b928e2012-05-30 09:01:101784 // Mac so it uses NSSpellChecker in the background.
1785 false;
1786#else
[email protected]61806872012-12-12 04:15:361787 true;
[email protected]37b928e2012-05-30 09:01:101788#endif
[email protected]b7e44ff2012-02-16 03:37:341789 web_prefs->unified_textchecker_enabled =
[email protected]57890242012-10-23 17:46:521790 web_prefs->asynchronous_spell_checking_enabled;
[email protected]dd5d0fb2012-01-18 03:37:571791
[email protected]64d69de42012-02-06 00:19:541792 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061793 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541794 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061795 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541796 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061797 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1798
1799 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541800 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061801 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541802 web_prefs->default_encoding);
1803 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401804 prefs->ClearPref(prefs::kDefaultCharset);
1805 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061806 }
[email protected]64d69de42012-02-06 00:19:541807 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061808
[email protected]88ecf66d2012-12-11 22:53:471809 if (content::IsForceCompositingModeEnabled())
1810 web_prefs->force_compositing_mode = true;
1811
[email protected]299d7f12012-05-23 05:31:151812 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1813 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131814 ExtensionService* service =
1815 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061816 if (service) {
[email protected]1bc28312012-11-08 08:31:531817 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1818 const Extension* extension = service->extensions()->GetByID(url.host());
1819 // Ensure that we are only granting extension preferences to URLs with
1820 // the correct scheme. Without this check, chrome-guest:// schemes used by
1821 // webview tags as well as hosts that happen to match the id of an
1822 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421823 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531824 extension_webkit_preferences::SetPreferences(
1825 extension, view_type, web_prefs);
1826 }
[email protected]f3986f82012-01-03 20:00:061827 }
1828
[email protected]299d7f12012-05-23 05:31:151829 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541830 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151831 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061832 // Disable all kinds of acceleration for background pages.
1833 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541834 web_prefs->force_compositing_mode = false;
1835 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061836 }
[email protected]2e21fe292012-03-02 22:52:321837
1838#if defined(FILE_MANAGER_EXTENSION)
1839 // Override the default of suppressing HW compositing for WebUI pages for the
1840 // file manager, which is implemented using WebUI but wants HW acceleration
1841 // for video decode & render.
1842 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1843 web_prefs->accelerated_compositing_enabled = true;
1844 web_prefs->accelerated_2d_canvas_enabled = true;
1845 }
1846#endif
[email protected]181a95ee2011-07-12 19:26:361847}
1848
1849void ChromeContentBrowserClient::UpdateInspectorSetting(
1850 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061851 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581852 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061853 DictionaryPrefUpdate update(
1854 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1855 prefs::kWebKitInspectorSettings);
1856 DictionaryValue* inspector_settings = update.Get();
1857 inspector_settings->SetWithoutPathExpansion(key,
1858 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361859}
1860
1861void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061862 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581863 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061864 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1865 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361866}
1867
[email protected]b8148ac2011-07-13 22:03:251868void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1869 BrowserURLHandler* handler) {
1870 // Add the default URL handlers.
1871 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1872 BrowserURLHandler::null_handler());
1873 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1874 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1875
[email protected]b3adbd02011-11-30 22:23:271876 // about: handler. Must come before chrome: handler, since it will
1877 // rewrite about: urls to chrome: URLs and then expect chrome: to
1878 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251879 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1880 BrowserURLHandler::null_handler());
1881 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241882 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251883}
1884
1885void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371886 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581887 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471888 BrowsingDataRemover* remover =
1889 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551890 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1891 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251892 // BrowsingDataRemover takes care of deleting itself when done.
1893}
1894
1895void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371896 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581897 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471898 BrowsingDataRemover* remover =
1899 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231900 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551901 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251902 // BrowsingDataRemover takes care of deleting itself when done.
1903}
1904
[email protected]650b2d52013-02-10 03:41:451905base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:321906 return download_util::GetDefaultDownloadDirectory();
1907}
1908
[email protected]c9b6eb62011-10-18 20:49:391909std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1910 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1911}
1912
[email protected]b7631cc2012-09-15 05:08:381913void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1914 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:541915#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:381916 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1917 scoped_ptr<ppapi::host::HostFactory>(
1918 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:541919#endif
[email protected]b7631cc2012-09-15 05:08:381920}
1921
[email protected]0c7193742012-11-07 19:05:031922content::BrowserPpapiHost*
1923 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
1924 int plugin_process_id) {
1925 BrowserChildProcessHostIterator iter(content::PROCESS_TYPE_NACL_LOADER);
1926 while (!iter.Done()) {
1927 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
1928 if (host->process() &&
1929 host->process()->GetData().id == plugin_process_id) {
1930 // Found the plugin.
1931 return host->browser_ppapi_host();
1932 }
1933 ++iter;
1934 }
1935 return NULL;
1936}
1937
[email protected]38cd8f7f2012-06-15 22:06:071938bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:581939 content::BrowserContext* browser_context,
1940 const GURL& url,
1941 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:291942 if (!url.is_valid())
1943 return false;
1944
1945 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:421946 if (url.SchemeIs(extensions::kExtensionScheme) &&
1947 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:291948 return true;
[email protected]885c0e92012-11-13 20:27:421949 }
[email protected]a658d452012-03-02 12:45:291950
[email protected]9a5940d2012-04-27 19:16:231951 Profile* profile = Profile::FromBrowserContext(browser_context);
1952 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:191953 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131954 extensions::ExtensionSystem::Get(profile)->extension_service();
1955 if (extension_service) {
1956 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:231957 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1958 }
1959
[email protected]f237c0f2012-03-10 07:49:101960 // Need to check this now and not on construction because otherwise it won't
1961 // work with browser_tests.
1962 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1963 std::string allowed_list =
1964 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231965 if (allowed_list == "*") {
1966 // The wildcard allows socket API only for packaged and platform apps.
1967 return extension &&
[email protected]1d5e58b2013-01-31 08:41:401968 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
1969 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:231970 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:391971 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:101972 while (t.GetNext()) {
1973 if (t.token() == host)
1974 return true;
1975 }
1976 }
1977
[email protected]a658d452012-03-02 12:45:291978 if (!extension)
1979 return false;
1980
[email protected]157cc902012-11-02 06:31:581981 extensions::SocketPermission::CheckParam extension_params(
1982 params.type, params.host, params.port);
1983 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
1984 &extension_params))
[email protected]a658d452012-03-02 12:45:291985 return true;
1986
1987 return false;
[email protected]e461da2f2012-02-16 19:06:401988}
1989
[email protected]650b2d52013-02-10 03:41:451990base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
1991 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:141992 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
1993 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
1994}
1995
[email protected]a28e3302013-02-03 03:50:431996ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
1997 WebContents* web_contents) {
1998 return new ChromeSelectFilePolicy(web_contents);
1999}
2000
[email protected]e60c0232011-11-11 19:56:352001#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:182002void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
2003 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:382004 int child_process_id,
[email protected]c7abd422012-09-25 00:20:082005 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:392006#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452007 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392008 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2009 DCHECK(!data_path.empty());
2010
2011 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452012 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392013 base::PlatformFile f =
2014 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2015 DCHECK(f != base::kInvalidPlatformFileValue);
2016 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2017 FileDescriptor(f, true)));
2018
[email protected]650b2d52013-02-10 03:41:452019 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392020 data_path.AppendASCII("chrome_100_percent.pak");
2021 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2022 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372023 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392024 FileDescriptor(f, true)));
2025
2026 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452027 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392028 GetLocaleFilePath(locale, false);
2029 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2030 DCHECK(f != base::kInvalidPlatformFileValue);
2031 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2032 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382033
[email protected]650b2d52013-02-10 03:41:452034 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372035 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2036 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2037 DCHECK(f != base::kInvalidPlatformFileValue);
2038 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2039 FileDescriptor(f, true)));
2040
[email protected]40da3e0c2012-10-24 22:03:382041#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432042 if (IsCrashReporterEnabled()) {
2043 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2044 if (f == base::kInvalidPlatformFileValue) {
2045 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2046 "be disabled for this process.";
2047 } else {
2048 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2049 FileDescriptor(f, true)));
2050 }
[email protected]40da3e0c2012-10-24 22:03:382051 }
2052#endif // defined(USE_LINUX_BREAKPAD)
2053
2054#else
2055 int crash_signal_fd = GetCrashSignalFD(command_line);
2056 if (crash_signal_fd >= 0) {
2057 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2058 FileDescriptor(crash_signal_fd,
2059 false)));
2060 }
[email protected]29699c22012-10-03 23:57:392061#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302062}
[email protected]e60c0232011-11-11 19:56:352063#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302064
[email protected]4a65826d2011-08-25 16:04:012065#if defined(OS_WIN)
2066const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2067 return chrome::kBrowserResourcesDll;
2068}
2069#endif
2070
[email protected]37a72af2011-06-13 05:42:012071#if defined(USE_NSS)
2072crypto::CryptoModuleBlockingPasswordDelegate*
2073 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2074 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292075 return chrome::NewCryptoModuleBlockingDialogDelegate(
2076 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012077}
2078#endif
2079
[email protected]e9a32a52012-06-14 23:32:432080void ChromeContentBrowserClient::SetApplicationLocale(
2081 const std::string& locale) {
2082 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2083
2084 // This object is guaranteed to outlive all threads so we don't have to
2085 // worry about the lack of refcounting and can just post as Unretained.
2086 //
2087 // The common case is that this function is called early in Chrome startup
2088 // before any threads are created (it will also be called later if the user
2089 // changes the pref). In this case, there will be no threads created and
2090 // posting will fail. When there are no threads, we can just set the string
2091 // without worrying about threadsafety.
2092 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
2093 base::Bind(
2094 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
2095 base::Unretained(this), locale)))
2096 io_thread_application_locale_ = locale;
2097}
2098
2099void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
2100 const std::string& locale) {
2101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2102 io_thread_application_locale_ = locale;
2103}
2104
[email protected]d977f9c2011-03-14 16:10:262105} // namespace chrome