blob: 5697eea6425fe6e235c825529c324bdb3d511c91 [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]f4ebe772013-02-02 00:21:3914#include "base/strings/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0615#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3016#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2517#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3018#include "chrome/browser/browser_process.h"
[email protected]b0cb5e82012-07-19 19:22:4719#include "chrome/browser/browsing_data/browsing_data_helper.h"
20#include "chrome/browser/browsing_data/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1221#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0322#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4123#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5624#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0525#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4526#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3227#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0828#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3229#include "chrome/browser/download/download_util.h"
[email protected]2b33dcd02012-03-18 01:34:1630#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0631#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0432#include "chrome/browser/extensions/extension_info_map.h"
[email protected]9c1662b2012-03-06 15:44:3333#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2634#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0835#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2536#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0637#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]40404bc2012-07-25 17:40:4938#include "chrome/browser/extensions/message_handler.h"
[email protected]eb4832a2012-12-08 01:57:5239#include "chrome/browser/extensions/suggest_permission_util.h"
[email protected]32538d92011-08-25 00:09:2340#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1241#include "chrome/browser/google/google_util.h"
[email protected]c5dec6292013-01-25 04:54:5242#include "chrome/browser/instant/instant_service.h"
43#include "chrome/browser/instant/instant_service_factory.h"
[email protected]11158e2d2013-02-01 02:31:5644#include "chrome/browser/media/media_capture_devices_dispatcher.h"
[email protected]0c7193742012-11-07 19:05:0345#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2846#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0447#include "chrome/browser/notifications/desktop_notification_service.h"
48#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4249#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5650#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]c753f142013-02-10 13:14:0451#include "chrome/browser/prefs/pref_registry_syncable.h"
[email protected]763ec4ca2011-04-29 15:48:1252#include "chrome/browser/prefs/pref_service.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]c5dec6292013-01-25 04:54:5266#include "chrome/browser/search_engines/template_url_service.h"
67#include "chrome/browser/search_engines/template_url_service_factory.h"
[email protected]c52b2892012-03-07 11:01:0268#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4669#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5870#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0371#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5272#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4573#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5474#include "chrome/browser/toolkit_extra_parts.h"
[email protected]a28e3302013-02-03 03:50:4375#include "chrome/browser/ui/chrome_select_file_policy.h"
[email protected]b5d73422012-06-02 23:46:4476#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5077#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0678#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1579#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5380#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3081#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0182#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1483#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3084#include "chrome/common/chrome_switches.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]e0ada9c2012-03-20 03:54:4393#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3094#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:3895#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:3196#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:0397#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:5998#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:3699#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:30100#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:33101#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:05102#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:33103#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19104#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10105#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43106#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18107#include "content/public/common/content_descriptors.h"
[email protected]885c0e92012-11-13 20:27:42108#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39109#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23110#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53111#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58112#include "net/base/mime_util.h"
[email protected]7a593db2012-02-13 21:19:40113#include "net/base/ssl_cert_request_info.h"
[email protected]5b9bc352012-07-18 13:13:34114#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06115#include "net/cookies/cookie_options.h"
[email protected]b7631cc2012-09-15 05:08:38116#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39117#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08118#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36119#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04120#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26121
[email protected]b48c9182011-10-26 18:03:30122#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38123#include "chrome/browser/chrome_browser_main_win.h"
124#elif defined(OS_MACOSX)
125#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56126#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30127#elif defined(OS_CHROMEOS)
128#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49129#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26130#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30131#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09132#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38133#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09134#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39135#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30136#elif defined(OS_POSIX)
137#include "chrome/browser/chrome_browser_main_posix.h"
138#endif
139
[email protected]6653c192012-04-10 22:52:44140#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30141#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12142#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43143#endif
[email protected]b80f68432011-05-02 17:22:30144
[email protected]1e87df32012-09-12 04:53:19145#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
146#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
147#endif
148
[email protected]29699c22012-10-03 23:57:39149#if defined(OS_ANDROID)
150#include "ui/base/ui_base_paths.h"
151#endif
152
[email protected]37a72af2011-06-13 05:42:01153#if defined(USE_NSS)
154#include "chrome/browser/ui/crypto_module_password_dialog.h"
155#endif
156
[email protected]c7abd422012-09-25 00:20:08157using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47158using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03159using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39160using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31161using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59162using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08163using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00164using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11165using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33166using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13167using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06168using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34169using extensions::Extension;
[email protected]1d5e58b2013-01-31 08:41:40170using extensions::Manifest;
[email protected]6717bf272012-05-11 23:31:25171using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39172
[email protected]c5dbef02011-05-13 05:06:09173namespace {
174
[email protected]e461da2f2012-02-16 19:06:40175const char* kPredefinedAllowedSocketOrigins[] = {
176 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18177 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45178 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
179 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
180 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
181 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35182 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54183 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
184 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
185 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
186 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
187 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
188 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38189 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58190 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
191 "iabmpiboiopbgfabjmgeedhcmjenhbla" // see crbug.com/165080
[email protected]e461da2f2012-02-16 19:06:40192};
193
[email protected]f8f93eb2012-09-25 03:06:24194// Returns a copy of the given url with its host set to given host and path set
195// to given path. Other parts of the url will be the same.
196GURL ReplaceURLHostAndPath(const GURL& url,
197 const std::string& host,
198 const std::string& path) {
199 url_canon::Replacements<char> replacements;
200 replacements.SetHost(host.c_str(),
201 url_parse::Component(0, host.length()));
202 replacements.SetPath(path.c_str(),
203 url_parse::Component(0, path.length()));
204 return url.ReplaceComponents(replacements);
205}
206
207// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
208GURL AddUberHost(const GURL& url) {
209 const std::string uber_host = chrome::kChromeUIUberHost;
210 const std::string new_path = url.host() + url.path();
211
212 return ReplaceURLHostAndPath(url, uber_host, new_path);
213}
214
[email protected]045bf7c2012-09-28 20:27:36215// If url->host() is "chrome" and url->path() has characters other than the
216// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
217// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24218bool RemoveUberHost(GURL* url) {
219 if (url->host() != chrome::kChromeUIUberHost)
220 return false;
221
[email protected]045bf7c2012-09-28 20:27:36222 if (url->path().empty() || url->path() == "/")
223 return false;
224
[email protected]f8f93eb2012-09-25 03:06:24225 const std::string old_path = url->path();
226
227 const std::string::size_type separator = old_path.find('/', 1);
228 std::string new_host;
229 std::string new_path;
230 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36231 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24232 } else {
233 new_host = old_path.substr(1, separator - 1);
234 new_path = old_path.substr(separator);
235 }
236
237 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
238
239 return true;
240}
241
[email protected]b8148ac2011-07-13 22:03:25242// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42243bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24244 // Do not handle special URLs such as "about:foo"
245 if (!url->host().empty()) {
246 const GURL chrome_url = AddUberHost(*url);
247
248 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
249 // be called.
250 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
251 browser_context, chrome_url))
252 return true;
253 }
254
[email protected]863f70a2012-01-27 02:05:50255 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
256 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25257 return false;
258
[email protected]fe69558d2012-03-12 11:34:49259#if defined(OS_CHROMEOS)
260 // Special case : in ChromeOS in Guest mode bookmarks and history are
261 // disabled for security reasons. New tab page explains the reasons, so
262 // we redirect user to new tab page.
263 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
264 if (url->SchemeIs(chrome::kChromeUIScheme) &&
265 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
266 url->DomainIs(chrome::kChromeUIHistoryHost))) {
267 // Rewrite with new tab URL
268 *url = GURL(chrome::kChromeUINewTabURL);
269 }
270 }
271#endif
272
[email protected]b8148ac2011-07-13 22:03:25273 // Special case the new tab page. In older versions of Chrome, the new tab
274 // page was hosted at chrome-internal:<blah>. This might be in people's saved
275 // sessions or bookmarks, so we say any URL with that scheme triggers the new
276 // tab page.
277 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
278 // Rewrite it with the proper new tab URL.
279 *url = GURL(chrome::kChromeUINewTabURL);
280 }
281
282 return true;
283}
284
[email protected]f8f93eb2012-09-25 03:06:24285// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
286// "chrome://foo/".
287bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
288 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
289 return false;
290
291 return RemoveUberHost(url);
292}
293
[email protected]8d3132f62011-10-12 07:13:42294// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
295// below. Extension, and isolated apps require different privileges to be
296// granted to their RenderProcessHosts. This classification allows us to make
297// sure URLs are served by hosts with the right set of privileges.
298enum RenderProcessHostPrivilege {
299 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45300 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42301 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45302 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42303};
304
305RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
306 const GURL& url,
307 ExtensionService* service) {
308 // Default to a normal renderer cause it is lower privileged. This should only
309 // occur if the URL on a site instance is either malformed, or uninitialized.
310 // If it is malformed, then there is no need for better privileges anyways.
311 // If it is uninitialized, but eventually settles on being an a scheme other
312 // than normal webrenderer, the navigation logic will correct us out of band
313 // anyways.
314 if (!url.is_valid())
315 return PRIV_NORMAL;
316
[email protected]885c0e92012-11-13 20:27:42317 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44318 const Extension* extension =
319 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45320 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42321 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45322 if (extension && extension->is_hosted_app())
323 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42324
325 return PRIV_EXTENSION;
326 }
327
328 return PRIV_NORMAL;
329}
330
331RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30332 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46333 extensions::ProcessMap* process_map,
334 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46335 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30336 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46337 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21338 return PRIV_NORMAL;
339
[email protected]6f371442011-11-09 06:45:46340 for (std::set<std::string>::iterator iter = extension_ids.begin();
341 iter != extension_ids.end(); ++iter) {
342 const Extension* extension = service->GetExtensionById(*iter, false);
343 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42344 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45345 if (extension && extension->is_hosted_app())
346 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42347 }
348
[email protected]676f6ab2011-10-19 20:23:21349 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42350}
351
[email protected]6786bf402011-12-03 15:19:45352bool CertMatchesFilter(const net::X509Certificate& cert,
353 const base::DictionaryValue& filter) {
354 // TODO(markusheintz): This is the minimal required filter implementation.
355 // Implement a better matcher.
356
357 // An empty filter matches any client certificate since no requirements are
358 // specified at all.
359 if (filter.empty())
360 return true;
361
362 std::string common_name;
363 if (filter.GetString("ISSUER.CN", &common_name) &&
364 (cert.issuer().common_name == common_name)) {
365 return true;
366 }
367 return false;
368}
369
[email protected]f3986f82012-01-03 20:00:06370// Fills |map| with the per-script font prefs under path |map_name|.
371void FillFontFamilyMap(const PrefService* prefs,
372 const char* map_name,
373 WebPreferences::ScriptFontFamilyMap* map) {
374 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
375 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
376 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
377 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23378 if (!font_family.empty())
379 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06380 }
381}
382
[email protected]a1733df2012-06-22 11:24:18383#if defined(OS_POSIX) && !defined(OS_MACOSX)
384int GetCrashSignalFD(const CommandLine& command_line) {
385 if (command_line.HasSwitch(switches::kExtensionProcess)) {
386 ExtensionCrashHandlerHostLinux* crash_handler =
387 ExtensionCrashHandlerHostLinux::GetInstance();
388 return crash_handler->GetDeathSignalSocket();
389 }
390
391 std::string process_type =
392 command_line.GetSwitchValueASCII(switches::kProcessType);
393
394 if (process_type == switches::kRendererProcess)
395 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
396
397 if (process_type == switches::kPluginProcess)
398 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
399
400 if (process_type == switches::kPpapiPluginProcess)
401 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
402
403 if (process_type == switches::kGpuProcess)
404 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
405
406 return -1;
407}
408#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
409
[email protected]c5dec6292013-01-25 04:54:52410// TODO(dhollowa): http://crbug.com/170390 This test exists in different places
411// in Chrome. Follow-up to consolidate these various Instant URL checks.
412// Returns true if |url| has the same scheme, host, and path as the instant URL
413// set via --instant-url.
414bool IsForcedInstantURL(const GURL& url) {
415 CommandLine* command_line = CommandLine::ForCurrentProcess();
416 if (command_line->HasSwitch(switches::kInstantURL)) {
417 GURL instant_url(command_line->GetSwitchValueASCII(switches::kInstantURL));
418 if (url.scheme() == instant_url.scheme() &&
419 url.host() == instant_url.host() &&
420 url.path() == instant_url.path()) {
421 return true;
422 }
423 }
424 return false;
425}
426
427// Determines whether the |url| is an Instant url for the default search
428// provider (set for the |profile|).
429// Also returns true if an Instant "effective url" (see below) is passed in.
430bool IsInstantURL(const GURL& url, Profile* profile) {
431 // Handle the command-line URL.
432 if (IsForcedInstantURL(url))
433 return true;
434
435 // A URL of this form has already be determined to be an Instant url,
436 // this is its "effective url". So trivially return true.
437 if (url.SchemeIs(chrome::kChromeSearchScheme))
438 return true;
439
440 TemplateURLService* template_url_service =
441 TemplateURLServiceFactory::GetForProfile(profile);
442 if (!template_url_service)
443 return false;
444
445 TemplateURL* template_url = template_url_service->GetDefaultSearchProvider();
446 if (!template_url)
447 return false;
448
449 if (template_url->instant_url().empty())
450 return false;
451
452 return template_url->IsInstantURL(url);
453}
454
455// Transforms the input |url| into its "effective url". The returned url
456// facilitates grouping process-per-site. The |url| is transformed, for
457// example, from
458//
459// https://www.google.com/search?espv=1&q=tractors
460//
461// to the effective url
462//
463// chrome-search://www.google.com/search?espv=1&q=tractors
464//
465// Notice the scheme change.
466// If the input is already an effective url then that same url is
467// returned.
468GURL GetEffectiveInstantURL(const GURL& url, Profile* profile) {
469 CHECK(IsInstantURL(url, profile)) << "Error granting Instant access.";
470
471 if (url.SchemeIs(chrome::kChromeSearchScheme))
472 return url;
473
474 GURL effective_url(url);
475
476 // Replace the scheme with "chrome-search:".
477 url_canon::Replacements<char> replacements;
478 std::string search_scheme(chrome::kChromeSearchScheme);
479 replacements.SetScheme(search_scheme.data(),
480 url_parse::Component(0, search_scheme.length()));
481 effective_url = effective_url.ReplaceComponents(replacements);
482 return effective_url;
483}
484
[email protected]9dbfff12011-07-01 19:37:07485} // namespace
[email protected]c5dbef02011-05-13 05:06:09486
[email protected]d977f9c2011-03-14 16:10:26487namespace chrome {
488
[email protected]e461da2f2012-02-16 19:06:40489ChromeContentBrowserClient::ChromeContentBrowserClient() {
490 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
491 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40492}
493
494ChromeContentBrowserClient::~ChromeContentBrowserClient() {
495}
496
[email protected]bca18382012-06-25 19:15:23497// static
[email protected]c753f142013-02-10 13:14:04498void ChromeContentBrowserClient::RegisterUserPrefs(
499 PrefRegistrySyncable* registry) {
500 registry->RegisterBooleanPref(prefs::kDisable3DAPIs,
501 false,
502 PrefRegistrySyncable::UNSYNCABLE_PREF);
503 registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
504 true,
505 PrefRegistrySyncable::UNSYNCABLE_PREF);
506 registry->RegisterBooleanPref(prefs::kEnableMemoryInfo,
507 false,
508 PrefRegistrySyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23509}
510
[email protected]50462bf02011-11-21 19:13:31511content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
512 const content::MainFunctionParams& parameters) {
513 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30514 // Construct the Main browser parts based on the OS type.
515#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31516 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04517#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31518 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30519#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22520 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26521#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31522 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14523#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09524 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30525#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31526 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04527#else
[email protected]b48c9182011-10-26 18:03:30528 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31529 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30530#endif
531
[email protected]c7480942011-11-08 19:18:27532 // Construct additional browser parts. Stages are called in the order in
533 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22534#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41535 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04536#endif
[email protected]c7480942011-11-08 19:18:27537
538#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41539 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27540#endif
541
[email protected]dc04be7c2012-03-15 23:57:49542#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41543 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49544#endif
545
[email protected]e050ef142012-03-21 01:04:24546#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41547 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24548#endif
549
[email protected]50462bf02011-11-21 19:13:31550 return main_parts;
[email protected]f967b722011-09-07 00:58:04551}
552
[email protected]38b098f2012-03-14 21:11:57553content::WebContentsView*
554 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57555 WebContents* web_contents,
556 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57557 return NULL;
558}
559
[email protected]e94bbcb2012-09-07 05:33:57560std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19561 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57562 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53563 std::string partition_id;
564
565 // The partition ID for webview guest processes is the string value of its
566 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
567 if (site.SchemeIs(chrome::kGuestScheme))
568 partition_id = site.spec();
569
570 DCHECK(IsValidStoragePartitionId(browser_context,partition_id));
571 return partition_id;
572}
573
574bool ChromeContentBrowserClient::IsValidStoragePartitionId(
575 content::BrowserContext* browser_context,
576 const std::string& partition_id) {
577 // The default ID is empty and is always valid.
578 if (partition_id.empty())
579 return true;
580
581 return GURL(partition_id).is_valid();
582}
583
584void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
585 content::BrowserContext* browser_context,
586 const GURL& site,
[email protected]14acc642012-11-17 12:20:10587 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53588 std::string* partition_domain,
589 std::string* partition_name,
590 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10591 // Default to the browser-wide storage partition and override based on |site|
592 // below.
593 partition_domain->clear();
594 partition_name->clear();
595 *in_memory = false;
596
[email protected]1bc28312012-11-08 08:31:53597 // For the webview tag, we create special guest processes, which host the
598 // tag content separately from the main application that embeds the tag.
599 // A webview tag can specify both the partition name and whether the storage
600 // for that partition should be persisted. Each tag gets a SiteInstance with
601 // a specially formatted URL, based on the application it is hosted by and
602 // the partition requested by it. The format for that URL is:
603 // chrome-guest://partition_domain/persist?partition_name
604 if (site.SchemeIs(chrome::kGuestScheme)) {
605 // Since guest URLs are only used for packaged apps, there must be an app
606 // id in the URL.
607 CHECK(site.has_host());
608 *partition_domain = site.host();
609 // Since persistence is optional, the path must either be empty or the
610 // literal string.
611 *in_memory = (site.path() != "/persist");
612 // The partition name is user supplied value, which we have encoded when the
613 // URL was created, so it needs to be decoded.
614 *partition_name = net::UnescapeURLComponent(site.query(),
615 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10616 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
617 // If |can_be_default| is false, the caller is stating that the |site|
618 // should be parsed as if it had isolated storage. In particular it is
619 // important to NOT check ExtensionService for the is_storage_isolated()
620 // attribute because this code path is run during Extension uninstall
621 // to do cleanup after the Extension has already been unloaded from the
622 // ExtensionService.
623 bool is_isolated = !can_be_default;
624 if (can_be_default) {
625 const Extension* extension = NULL;
626 Profile* profile = Profile::FromBrowserContext(browser_context);
627 ExtensionService* extension_service =
628 extensions::ExtensionSystem::Get(profile)->extension_service();
629 if (extension_service) {
630 extension = extension_service->extensions()->
631 GetExtensionOrAppByURL(ExtensionURLInfo(site));
632 if (extension && extension->is_storage_isolated()) {
633 is_isolated = true;
634 }
635 }
636 }
[email protected]1bc28312012-11-08 08:31:53637
[email protected]14acc642012-11-17 12:20:10638 if (is_isolated) {
639 CHECK(site.has_host());
640 // For extensions with isolated storage, the the host of the |site| is
641 // the |partition_domain|. The |in_memory| and |partition_name| are only
642 // used in guest schemes so they are cleared here.
643 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53644 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10645 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53646 }
[email protected]d1198fd2012-08-13 22:50:19647 }
648
[email protected]14acc642012-11-17 12:20:10649 // Assert that if |can_be_default| is false, the code above must have found a
650 // non-default partition. If this fails, the caller has a serious logic
651 // error about which StoragePartition they expect to be in and it is not
652 // safe to continue.
653 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44654}
655
[email protected]38b098f2012-03-14 21:11:57656content::WebContentsViewDelegate*
657 ChromeContentBrowserClient::GetWebContentsViewDelegate(
658 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27659 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32660}
661
[email protected]f364d1392011-04-08 21:03:10662void ChromeContentBrowserClient::RenderViewHostCreated(
663 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46664
[email protected]9f76c1e2012-03-05 15:15:58665 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46666 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02667 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46668
669 new ChromeRenderViewHostObserver(render_view_host,
670 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49671 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26672}
673
[email protected]44703cc72013-01-24 04:56:06674void ChromeContentBrowserClient::GuestWebContentsCreated(
675 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
676 Profile* profile = Profile::FromBrowserContext(
677 embedder_web_contents->GetBrowserContext());
678 ExtensionService* service =
679 extensions::ExtensionSystem::Get(profile)->extension_service();
680 if (!service)
681 return;
682 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
683 const Extension* extension = service->extensions()->
684 GetExtensionOrAppByURL(ExtensionURLInfo(url));
685 if (!extension)
686 return;
687 std::vector<ExtensionMsg_Loaded_Params> extensions;
688 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
689 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
690}
691
[email protected]f3b1a082011-11-18 00:34:30692void ChromeContentBrowserClient::RenderProcessHostCreated(
693 content::RenderProcessHost* host) {
694 int id = host->GetID();
695 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
696 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02697 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]ebd71962012-12-20 02:56:55698#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30699 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55700#endif
[email protected]658677f2012-06-09 06:04:02701#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08702 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03703#endif
[email protected]f3b1a082011-11-18 00:34:30704 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02705 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30706 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56707#if defined(OS_MACOSX)
708 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
709#endif
[email protected]f3b1a082011-11-18 00:34:30710 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03711 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07712 host->GetChannel()->AddFilter(
713 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38714
[email protected]2ccf45c2011-08-19 23:35:50715 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
716 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07717
718 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56719
720 RendererContentSettingRules rules;
721 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
722 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14723}
724
[email protected]3d7474ff2011-07-27 17:47:37725GURL ChromeContentBrowserClient::GetEffectiveURL(
726 content::BrowserContext* browser_context, const GURL& url) {
727 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]c5dec6292013-01-25 04:54:52728 if (!profile)
729 return url;
730
731 // If the input |url| is an Instant url, make its effective url distinct from
732 // other urls on the search provider's domain.
733 if (IsInstantURL(url, profile))
734 return GetEffectiveInstantURL(url, profile);
735
736 // If the input |url| is part of an installed app, the effective URL is an
737 // extension URL with the ID of that extension as the host. This has the
738 // effect of grouping apps together in a common SiteInstance.
739 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13740 extensions::ExtensionSystem::Get(profile)->extension_service();
741 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08742 return url;
743
[email protected]06bdd2b2012-11-30 18:47:13744 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44745 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08746 if (!extension)
747 return url;
748
[email protected]15877ca2011-11-18 22:40:52749 // Bookmark apps do not use the hosted app process model, and should be
750 // treated as normal URLs.
751 if (extension->from_bookmark())
752 return url;
753
[email protected]36fb2c7c2011-04-04 15:49:08754 // If the URL is part of an extension's web extent, convert it to an
755 // extension URL.
756 return extension->GetResourceURL(url.path());
757}
758
[email protected]056ad2a2011-07-12 02:13:55759bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37760 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]c5dec6292013-01-25 04:54:52761 // Non-extension, non-Instant URLs should generally use
762 // process-per-site-instance. Because we expect to use the effective URL,
763 // URLs for hosted apps (apart from bookmark apps) should have an extension
764 // scheme by now.
765
766 Profile* profile = Profile::FromBrowserContext(browser_context);
767 if (!profile)
768 return false;
769
770 if (IsInstantURL(effective_url, profile))
771 return true;
772
[email protected]885c0e92012-11-13 20:27:42773 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55774 return false;
775
[email protected]c5dec6292013-01-25 04:54:52776 ExtensionService* extension_service =
[email protected]06bdd2b2012-11-30 18:47:13777 extensions::ExtensionSystem::Get(profile)->extension_service();
778 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55779 return false;
780
[email protected]06bdd2b2012-11-30 18:47:13781 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44782 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55783 if (!extension)
784 return false;
785
786 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53787 // permission, or that does not allow JavaScript access to the background
788 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55789 // responsiveness.
[email protected]1d5e58b2013-01-31 08:41:40790 if (extension->GetType() == Manifest::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06791 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]7b54ca02012-03-02 18:06:53792 !extension->allow_background_js_access()) {
793 return false;
794 }
795 }
[email protected]056ad2a2011-07-12 02:13:55796
[email protected]7b54ca02012-03-02 18:06:53797 // Hosted apps that have script access to their background page must use
798 // process per site, since all instances can make synchronous calls to the
799 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55800 return true;
801}
802
[email protected]6bd30072013-02-08 18:17:11803net::URLRequestContextGetter*
804ChromeContentBrowserClient::CreateRequestContext(
805 content::BrowserContext* browser_context,
806 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
807 blob_protocol_handler,
808 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
809 file_system_protocol_handler,
810 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
811 developer_protocol_handler,
812 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
813 chrome_protocol_handler,
814 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
815 chrome_devtools_protocol_handler) {
816 Profile* profile = Profile::FromBrowserContext(browser_context);
817 return profile->CreateRequestContext(blob_protocol_handler.Pass(),
818 file_system_protocol_handler.Pass(),
819 developer_protocol_handler.Pass(),
820 chrome_protocol_handler.Pass(),
821 chrome_devtools_protocol_handler.Pass());
822}
823
824net::URLRequestContextGetter*
825ChromeContentBrowserClient::CreateRequestContextForStoragePartition(
826 content::BrowserContext* browser_context,
827 const FilePath& partition_path,
828 bool in_memory,
829 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
830 blob_protocol_handler,
831 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
832 file_system_protocol_handler,
833 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
834 developer_protocol_handler,
835 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
836 chrome_protocol_handler,
837 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
838 chrome_devtools_protocol_handler) {
839 Profile* profile = Profile::FromBrowserContext(browser_context);
840 return profile->CreateRequestContextForStoragePartition(
841 partition_path,
842 in_memory,
843 blob_protocol_handler.Pass(),
844 file_system_protocol_handler.Pass(),
845 developer_protocol_handler.Pass(),
846 chrome_protocol_handler.Pass(),
847 chrome_devtools_protocol_handler.Pass());
848}
849
[email protected]46fb9442011-12-09 17:57:47850bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
851 return ProfileIOData::IsHandledURL(url);
852}
853
[email protected]2a5221b2011-09-27 23:07:31854bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30855 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31856 const GURL& site_url) {
857 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30858 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52859 // This may be NULL during tests. In that case, just assume any site can
860 // share any host.
861 if (!profile)
862 return true;
863
864 InstantService* instant_service =
865 InstantServiceFactory::GetForProfile(profile);
866 if (instant_service &&
867 instant_service->IsInstantProcess(process_host->GetID()))
868 return IsInstantURL(site_url, profile);
869
[email protected]06bdd2b2012-11-30 18:47:13870 ExtensionService* service =
871 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46872 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31873
[email protected]ffa97602011-11-17 17:55:52874 // Don't allow the Task Manager to share a process with anything else.
875 // Otherwise it can affect the renderers it is observing.
876 // Note: we could create another RenderProcessHostPrivilege bucket for
877 // this to allow multiple chrome://tasks instances to share, but that's
878 // a very unlikely case without serious consequences.
879 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
880 return false;
881
[email protected]8d3132f62011-10-12 07:13:42882 // These may be NULL during tests. In that case, just assume any site can
883 // share any host.
[email protected]6f371442011-11-09 06:45:46884 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31885 return true;
886
[email protected]eec0b33c2011-12-05 22:09:45887 // Otherwise, just make sure the process privilege matches the privilege
888 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57889 RenderProcessHostPrivilege privilege_required =
890 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45891 return GetProcessPrivilege(process_host, process_map, service) ==
892 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31893}
894
[email protected]76411f412012-02-22 18:56:06895// This function is trying to limit the amount of processes used by extensions
896// with background pages. It uses a globally set percentage of processes to
897// run such extensions and if the limit is exceeded, it returns true, to
898// indicate to the content module to group extensions together.
899bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
900 content::BrowserContext* browser_context, const GURL& url) {
901 // It has to be a valid URL for us to check for an extension.
902 if (!url.is_valid())
903 return false;
904
905 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19906 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13907 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06908 if (!service)
909 return false;
910
911 // We have to have a valid extension with background page to proceed.
912 const Extension* extension =
913 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
914 if (!extension)
915 return false;
916 if (!extension->has_background_page())
917 return false;
918
919 std::set<int> process_ids;
920 size_t max_process_count =
921 content::RenderProcessHost::GetMaxRendererProcessCount();
922
923 // Go through all profiles to ensure we have total count of extension
924 // processes containing background pages, otherwise one profile can
925 // starve the other.
926 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
927 GetLoadedProfiles();
928 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03929 ExtensionProcessManager* epm =
930 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32931 for (ExtensionProcessManager::const_iterator iter =
932 epm->background_hosts().begin();
933 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13934 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32935 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06936 }
937 }
938
939 if (process_ids.size() >
940 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
941 return true;
942 }
943
944 return false;
945}
946
[email protected]6f371442011-11-09 06:45:46947void ChromeContentBrowserClient::SiteInstanceGotProcess(
948 SiteInstance* site_instance) {
949 CHECK(site_instance->HasProcess());
950
951 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02952 site_instance->GetBrowserContext());
[email protected]c5dec6292013-01-25 04:54:52953 if (!profile)
954 return;
955
956 // Remember the ID of the Instant process to signal the renderer process
957 // on startup in |AppendExtraCommandLineSwitches| below.
958 if (IsInstantURL(site_instance->GetSiteURL(), profile)) {
959 InstantService* instant_service =
960 InstantServiceFactory::GetForProfile(profile);
961 if (instant_service)
962 instant_service->AddInstantProcess(site_instance->GetProcess()->GetID());
963 }
964
[email protected]06bdd2b2012-11-30 18:47:13965 ExtensionService* service =
966 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46967 if (!service)
968 return;
969
970 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44971 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59972 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46973 if (!extension)
974 return;
975
[email protected]6bc04fd82011-12-04 02:29:35976 service->process_map()->Insert(extension->id(),
977 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33978 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46979 BrowserThread::PostTask(
980 BrowserThread::IO, FROM_HERE,
981 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59982 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46983 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35984 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33985 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46986}
987
988void ChromeContentBrowserClient::SiteInstanceDeleting(
989 SiteInstance* site_instance) {
990 if (!site_instance->HasProcess())
991 return;
992
993 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02994 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13995 ExtensionService* service =
996 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46997 if (!service)
998 return;
999
1000 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:441001 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:591002 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:461003 if (!extension)
1004 return;
1005
[email protected]6bc04fd82011-12-04 02:29:351006 service->process_map()->Remove(extension->id(),
1007 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331008 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:461009 BrowserThread::PostTask(
1010 BrowserThread::IO, FROM_HERE,
1011 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:591012 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:461013 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:351014 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:331015 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:461016}
1017
[email protected]f05763972012-06-06 18:17:261018bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:081019 const GURL& current_url,
1020 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:261021 if (current_url.is_empty()) {
1022 // Always choose a new process when navigating to extension URLs. The
1023 // process grouping logic will combine all of a given extension's pages
1024 // into the same process.
[email protected]885c0e92012-11-13 20:27:421025 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:261026 return true;
[email protected]e3daf3c2011-10-05 21:17:081027
[email protected]f05763972012-06-06 18:17:261028 return false;
1029 }
1030
1031 // Also, we must switch if one is an extension and the other is not the exact
1032 // same extension.
[email protected]885c0e92012-11-13 20:27:421033 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
1034 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:261035 if (current_url.GetOrigin() != new_url.GetOrigin())
1036 return true;
1037 }
1038
1039 return false;
[email protected]e3daf3c2011-10-05 21:17:081040}
1041
[email protected]395045c2012-05-22 15:04:381042bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
1043 content::ResourceContext* resource_context, const GURL& current_url,
1044 const GURL& new_url) {
1045 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
1046 return extensions::CrossesExtensionProcessBoundary(
1047 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:171048 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:381049}
1050
[email protected]763ec4ca2011-04-29 15:48:121051std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
1052 const std::string& alias_name) {
1053 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
1054}
1055
[email protected]b80f68432011-05-02 17:22:301056void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
1057 CommandLine* command_line, int child_process_id) {
1058#if defined(USE_LINUX_BREAKPAD)
1059 if (IsCrashReporterEnabled()) {
1060 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1061 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
1062 }
1063#elif defined(OS_MACOSX)
1064 if (IsCrashReporterEnabled()) {
1065 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
1066 child_process_logging::GetClientId());
1067 }
1068#endif // OS_MACOSX
1069
[email protected]f1933792011-06-14 00:49:341070 if (logging::DialogsAreSuppressed())
1071 command_line->AppendSwitch(switches::kNoErrorDialogs);
1072
[email protected]b80f68432011-05-02 17:22:301073 std::string process_type =
1074 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:171075 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:521076 if (process_type == switches::kRendererProcess) {
[email protected]650b2d52013-02-10 03:41:451077 base::FilePath user_data_dir =
[email protected]b80f68432011-05-02 17:22:301078 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
1079 if (!user_data_dir.empty())
1080 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
1081#if defined(OS_CHROMEOS)
1082 const std::string& login_profile =
1083 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
1084 if (!login_profile.empty())
1085 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
1086#endif
1087
[email protected]f3b1a082011-11-18 00:34:301088 content::RenderProcessHost* process =
1089 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:371090 if (process) {
1091 Profile* profile = Profile::FromBrowserContext(
1092 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131093 ExtensionService* extension_service =
1094 extensions::ExtensionSystem::Get(profile)->extension_service();
1095 if (extension_service) {
1096 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:001097 if (process_map && process_map->Contains(process->GetID()))
1098 command_line->AppendSwitch(switches::kExtensionProcess);
1099 }
[email protected]b80f68432011-05-02 17:22:301100
[email protected]a8d851f82011-12-21 00:32:371101 PrefService* prefs = profile->GetPrefs();
1102 // Currently this pref is only registered if applied via a policy.
1103 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
1104 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
1105 // Turn this policy into a command line switch.
1106 command_line->AppendSwitch(switches::kDisable3DAPIs);
1107 }
[email protected]718eab62011-10-05 21:16:521108
[email protected]a8d851f82011-12-21 00:32:371109 // Disable client-side phishing detection in the renderer if it is
1110 // disabled in the Profile preferences or the browser process.
1111 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
1112 !g_browser_process->safe_browsing_detection_service()) {
1113 command_line->AppendSwitch(
1114 switches::kDisableClientSidePhishingDetection);
1115 }
[email protected]0045b0f42012-07-26 11:52:081116
1117 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:211118 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]c5dec6292013-01-25 04:54:521119
1120 InstantService* instant_service =
1121 InstantServiceFactory::GetForProfile(profile);
1122 if (instant_service &&
1123 instant_service->IsInstantProcess(process->GetID()))
1124 command_line->AppendSwitch(switches::kInstantProcess);
[email protected]47c7ec82012-01-18 03:29:211125 }
[email protected]4287a3d2011-06-13 23:56:511126
[email protected]87552982012-11-02 17:21:401127 if (content::IsThreadedCompositingEnabled())
1128 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
1129
[email protected]47c7ec82012-01-18 03:29:211130 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:511131 static const char* const kSwitchNames[] = {
1132 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:481133 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:511134 switches::kAllowScriptingGallery,
1135 switches::kAppsCheckoutURL,
1136 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:311137 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:511138 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:501139 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:531140 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:111141 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:511142 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:211143 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:511144 switches::kEnableCrxlessWebApps,
1145 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:511146 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:511147 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:511148 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:481149 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:051150 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:511151 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:511152 switches::kMemoryProfiling,
1153 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:371154 switches::kNoJsRandomness,
[email protected]732b1604e2012-10-26 19:59:581155 switches::kPerformCrashAnalysis,
[email protected]f45c5f32012-04-18 19:26:371156 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:511157 switches::kPpapiFlashArgs,
1158 switches::kPpapiFlashInProcess,
1159 switches::kPpapiFlashPath,
1160 switches::kPpapiFlashVersion,
1161 switches::kProfilingAtStart,
1162 switches::kProfilingFile,
1163 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:371164 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:511165 switches::kSilentDumpOnDCHECK,
[email protected]c79d9492012-10-04 19:56:301166 switches::kSpdyProxyOrigin,
[email protected]a446534d2012-02-09 00:07:381167 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511168 };
1169
1170 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1171 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171172 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381173 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351174 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381175 switches::kEnableExperimentalExtensionApis,
1176 switches::kWhitelistedExtensionID,
1177 };
1178
1179 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1180 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511181 } else if (process_type == switches::kPluginProcess) {
1182 static const char* const kSwitchNames[] = {
1183 #if defined(OS_CHROMEOS)
1184 switches::kLoginProfile,
1185 #endif
1186 switches::kMemoryProfiling,
1187 switches::kSilentDumpOnDCHECK,
1188 switches::kUserDataDir,
1189 };
1190
1191 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1192 arraysize(kSwitchNames));
1193 } else if (process_type == switches::kZygoteProcess) {
1194 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511195 switches::kUserDataDir, // Make logs go to the right file.
1196 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501197 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511198 switches::kPpapiFlashInProcess,
1199 switches::kPpapiFlashPath,
1200 switches::kPpapiFlashVersion,
1201 };
1202
1203 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1204 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111205 } else if (process_type == switches::kGpuProcess) {
1206 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1207 // because GPU is expected to be unreliable.
1208 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1209 !command_line->HasSwitch(switches::kDisableBreakpad))
1210 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301211 }
[email protected]6f08af82011-09-15 01:19:031212
1213 // The command line switch kEnableBenchmarking needs to be specified along
1214 // with the kEnableStatsTable switch to ensure that the stats table global
1215 // is initialized correctly.
1216 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1217 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301218}
1219
1220std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431221 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1222 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:301223 return g_browser_process->GetApplicationLocale();
1224}
1225
[email protected]597a867b2011-11-18 18:31:201226std::string ChromeContentBrowserClient::GetAcceptLangs(
1227 content::BrowserContext* context) {
1228 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371229 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081230}
1231
[email protected]9ec0f452012-05-31 15:58:531232gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221233 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531234 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081235}
1236
[email protected]a2176792011-05-08 19:30:491237bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091238 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191239 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201240 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201242 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051243 return io_data->GetCookieSettings()->
1244 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491245}
1246
[email protected]ed24fad2011-05-10 22:44:011247bool ChromeContentBrowserClient::AllowGetCookie(
1248 const GURL& url,
1249 const GURL& first_party,
1250 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201251 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011252 int render_process_id,
1253 int render_view_id) {
1254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201255 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051256 bool allow = io_data->GetCookieSettings()->
1257 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011258
[email protected]8093a542011-05-13 07:29:321259 BrowserThread::PostTask(
1260 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031261 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431262 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011263 return allow;
1264}
1265
1266bool ChromeContentBrowserClient::AllowSetCookie(
1267 const GURL& url,
1268 const GURL& first_party,
1269 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201270 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011271 int render_process_id,
1272 int render_view_id,
1273 net::CookieOptions* options) {
1274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201275 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051276 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1277 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1278
[email protected]8093a542011-05-13 07:29:321279 BrowserThread::PostTask(
1280 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031281 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431282 render_view_id, url, first_party, cookie_line, *options,
1283 !allow));
[email protected]ed24fad2011-05-10 22:44:011284 return allow;
1285}
1286
[email protected]d5a19162011-06-30 18:51:541287bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201288 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201290 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431291 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1292 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261293
[email protected]bf510ed2012-06-05 08:31:431294 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1295 // Could we even support per-origin settings?
1296 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541297}
1298
[email protected]5c5a88e2011-11-12 00:45:351299bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351300 const GURL& url,
1301 const string16& name,
1302 const string16& display_name,
1303 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201304 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481305 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201307 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351308 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1309 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1310
[email protected]62151052012-02-01 18:40:481311 // Record access to database for potential display in UI.
1312 std::vector<std::pair<int, int> >::const_iterator i;
1313 for (i = render_views.begin(); i != render_views.end(); ++i) {
1314 BrowserThread::PostTask(
1315 BrowserThread::UI, FROM_HERE,
1316 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1317 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351318 }
1319
1320 return allow;
1321}
1322
1323bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351324 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201325 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481326 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201328 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351329 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1330 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1331
[email protected]62151052012-02-01 18:40:481332 // Record access to file system for potential display in UI.
1333 std::vector<std::pair<int, int> >::const_iterator i;
1334 for (i = render_views.begin(); i != render_views.end(); ++i) {
1335 BrowserThread::PostTask(
1336 BrowserThread::UI, FROM_HERE,
1337 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1338 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351339 }
1340
1341 return allow;
1342}
1343
[email protected]7c5ff9a2012-03-02 07:42:491344bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1345 const GURL& url,
1346 const string16& name,
1347 content::ResourceContext* context,
1348 const std::vector<std::pair<int, int> >& render_views) {
1349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1350 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1351 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1352 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1353
1354 // Record access to IndexedDB for potential display in UI.
1355 std::vector<std::pair<int, int> >::const_iterator i;
1356 for (i = render_views.begin(); i != render_views.end(); ++i) {
1357 BrowserThread::PostTask(
1358 BrowserThread::UI, FROM_HERE,
1359 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1360 i->first, i->second, url, name, !allow));
1361 }
1362
1363 return allow;
1364}
1365
[email protected]6133f922011-07-01 21:34:341366net::URLRequestContext*
1367ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201368 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341369 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421370 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201371 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341372 return io_data->extensions_request_context();
1373 }
1374
1375 return NULL;
1376}
1377
[email protected]317f96c92011-05-31 06:53:411378QuotaPermissionContext*
1379ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1380 return new ChromeQuotaPermissionContext();
1381}
1382
[email protected]848dd042011-06-04 18:24:031383void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171384 int render_process_id,
1385 int render_view_id,
1386 int cert_error,
1387 const net::SSLInfo& ssl_info,
1388 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031389 bool overridable,
[email protected]d9be47702012-05-16 03:41:221390 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171391 const base::Callback<void(bool)>& callback,
1392 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411393 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131394 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171395 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411396 if (!tab) {
1397 NOTREACHED();
1398 return;
1399 }
1400 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501401 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301402 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011403 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1404 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411405 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171406 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411407 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171408 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411409 return;
1410 }
1411 }
1412
[email protected]1e87df32012-09-12 04:53:191413#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231414 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1415 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1416 if (captive_portal_tab_helper)
1417 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191418#endif
1419
[email protected]f9034cf2011-07-21 12:43:411420 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221421 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1422 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031423}
1424
[email protected]c99c442e2011-08-24 11:37:301425void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451426 int render_process_id,
1427 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401428 const net::HttpNetworkSession* network_session,
1429 net::SSLCertRequestInfo* cert_request_info,
1430 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131431 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451432 render_process_id, render_view_id);
1433 if (!tab) {
1434 NOTREACHED();
1435 return;
1436 }
1437
[email protected]6786bf402011-12-03 15:19:451438 GURL requesting_url("https://" + cert_request_info->host_and_port);
1439 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1440 << cert_request_info->host_and_port;
1441
[email protected]627e0512011-12-21 22:55:301442 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451443 scoped_ptr<Value> filter(
1444 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1445 requesting_url,
1446 requesting_url,
1447 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1448 std::string(), NULL));
1449
1450 if (filter.get()) {
1451 // Try to automatically select a client certificate.
1452 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1453 DictionaryValue* filter_dict =
1454 static_cast<DictionaryValue*>(filter.get());
1455
1456 const std::vector<scoped_refptr<net::X509Certificate> >&
1457 all_client_certs = cert_request_info->client_certs;
1458 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1459 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1460 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401461 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451462 return;
1463 }
1464 }
1465 } else {
1466 NOTREACHED();
1467 }
1468 }
1469
[email protected]11feec322012-09-18 03:58:521470 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1471 if (!ssl_tab_helper) {
1472 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451473 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141474 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401475 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451476 return;
1477 }
[email protected]11feec322012-09-18 03:58:521478 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401479 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451480}
1481
[email protected]3b455502012-12-11 18:22:581482void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451483 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581484 net::CertificateMimeType cert_type,
1485 const void* cert_data,
1486 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451487 int render_process_id,
1488 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581489 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1490 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451491}
1492
[email protected]dc73a7b2012-03-25 15:27:181493content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
[email protected]11158e2d2013-02-01 02:31:561494 return MediaCaptureDevicesDispatcher::GetInstance();
[email protected]dc73a7b2012-03-25 15:27:181495}
1496
[email protected]941623e2011-06-07 23:06:041497void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1498 const GURL& source_origin,
1499 int callback_context,
1500 int render_process_id,
1501 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111502#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021503 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1504 WebContents* contents =
1505 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1506 if (!contents) {
[email protected]941623e2011-06-07 23:06:041507 NOTREACHED();
1508 return;
1509 }
1510
[email protected]d0d9c3ee2012-06-19 03:07:021511 // Skip showing the infobar if the request comes from an extension, and that
1512 // extension has the 'notify' permission. (If the extension does not have the
1513 // permission, the user will still be prompted.)
1514 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131515 ExtensionService* service =
1516 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]d0d9c3ee2012-06-19 03:07:021517 const Extension* extension = !service ? NULL :
1518 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1519 source_origin));
[email protected]eb4832a2012-12-08 01:57:521520 RenderViewHost* rvh =
1521 RenderViewHost::FromID(render_process_id, render_view_id);
1522 if (IsExtensionWithPermissionOrSuggestInConsole(
1523 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021524 if (rvh)
1525 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1526 return;
1527 }
1528
1529 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371530 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021531 notifications->RequestPermission(source_origin, render_process_id,
1532 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111533#else
1534 NOTIMPLEMENTED();
1535#endif
[email protected]941623e2011-06-07 23:06:041536}
1537
1538WebKit::WebNotificationPresenter::Permission
1539 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021540 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201541 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021542 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111543#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041544 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201545 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021546 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1547 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061548 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041549 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041550
1551 // Fall back to the regular notification preferences, which works on an
1552 // origin basis.
1553 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371554 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041555 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111556#else
1557 return WebKit::WebNotificationPresenter::PermissionAllowed;
1558#endif
[email protected]941623e2011-06-07 23:06:041559}
1560
1561void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171562 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041563 int render_process_id,
1564 int render_view_id,
1565 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111566#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041567 RenderViewHost* rvh = RenderViewHost::FromID(
1568 render_process_id, render_view_id);
1569 if (!rvh) {
1570 NOTREACHED();
1571 return;
1572 }
1573
[email protected]9f76c1e2012-03-05 15:15:581574 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301575 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041576 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371577 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041578 service->ShowDesktopNotification(
1579 params, render_process_id, render_view_id,
1580 worker ? DesktopNotificationService::WorkerNotification :
1581 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111582#else
1583 NOTIMPLEMENTED();
1584#endif
[email protected]941623e2011-06-07 23:06:041585}
1586
1587void ChromeContentBrowserClient::CancelDesktopNotification(
1588 int render_process_id,
1589 int render_view_id,
1590 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111591#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041592 RenderViewHost* rvh = RenderViewHost::FromID(
1593 render_process_id, render_view_id);
1594 if (!rvh) {
1595 NOTREACHED();
1596 return;
1597 }
1598
[email protected]9f76c1e2012-03-05 15:15:581599 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301600 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041601 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371602 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041603 service->CancelDesktopNotification(
1604 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111605#else
1606 NOTIMPLEMENTED();
1607#endif
[email protected]941623e2011-06-07 23:06:041608}
1609
[email protected]9f3fba52011-06-08 20:37:191610bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351611 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021612 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191613 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201614 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011615 int render_process_id,
1616 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191617 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011618
1619 *no_javascript_access = false;
1620
[email protected]9f3fba52011-06-08 20:37:191621 // If the opener is trying to create a background window but doesn't have
1622 // the appropriate permission, fail the attempt.
1623 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201624 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531625 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1626
[email protected]03b6d552012-03-29 04:03:011627 if (!map->SecurityOriginHasAPIPermission(
1628 source_origin,
1629 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061630 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011631 return false;
1632 }
1633
[email protected]7b54ca02012-03-02 18:06:531634 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1635 // return a recently installed Extension even if this CanCreateWindow call
1636 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011637 // because the permission check above would have caused an early return
1638 // already. We must use the full URL to find hosted apps, though, and not
1639 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531640 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351641 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531642 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011643 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191644 }
1645 return true;
1646}
1647
1648std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201649 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1651 // Check if it's an extension-created worker, in which case we want to use
1652 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201653 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191654 const Extension* extension =
1655 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1656 return extension ? extension->name() : std::string();
1657}
1658
[email protected]99907362012-01-11 05:41:401659void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1660 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171661}
1662
[email protected]c52b2892012-03-07 11:01:021663content::SpeechRecognitionManagerDelegate*
1664 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321665#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021666 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321667#else
1668 return NULL;
1669#endif
[email protected]66cfec62012-02-24 17:57:511670}
1671
[email protected]ae6e9912011-07-27 01:18:281672net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1673 return g_browser_process->net_log();
1674}
1675
[email protected]32538d92011-08-25 00:09:231676AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1677 return new ChromeAccessTokenStore();
1678}
1679
[email protected]dbae6b02011-06-29 23:51:411680bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011681 return true;
[email protected]dbae6b02011-06-29 23:51:411682}
1683
[email protected]64d69de42012-02-06 00:19:541684void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321685 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061686 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581687 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061688 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061689
[email protected]f3986f82012-01-03 20:00:061690 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541691 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061692 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541693 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061694 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541695 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061696 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541697 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061698 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541699 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061700 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541701 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031702 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1703 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061704
[email protected]64d69de42012-02-06 00:19:541705 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401706 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541707 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401708 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541709 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401710 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541711 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401712 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061713
[email protected]ddf72142012-05-22 04:52:401714 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061715
[email protected]64d69de42012-02-06 00:19:541716 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401717 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541718 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061719 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541720 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061721 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1722 const DictionaryValue* inspector_settings =
1723 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1724 if (inspector_settings) {
1725 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1726 iter != inspector_settings->end_keys(); ++iter) {
1727 std::string value;
1728 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541729 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061730 std::make_pair(*iter, value));
1731 }
1732 }
[email protected]64d69de42012-02-06 00:19:541733 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061734
[email protected]ddf72142012-05-22 04:52:401735 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541736 web_prefs->javascript_enabled = false;
1737 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1738 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401739 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541740 web_prefs->plugins_enabled = false;
1741 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1742 web_prefs->java_enabled = false;
1743 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401744 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061745
[email protected]64d69de42012-02-06 00:19:541746 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1747 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061748
[email protected]64d69de42012-02-06 00:19:541749 web_prefs->memory_info_enabled =
1750 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1751 web_prefs->allow_displaying_insecure_content =
1752 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1753 web_prefs->allow_running_insecure_content =
1754 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321755#if defined(OS_ANDROID)
1756 web_prefs->font_scale_factor =
1757 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1758 web_prefs->force_enable_zoom =
1759 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
1760#endif
[email protected]9d06d88d2012-02-23 22:37:081761 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061762
[email protected]64d69de42012-02-06 00:19:541763 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151764 UserStyleSheetWatcher* user_style_sheet_watcher =
1765 UserStyleSheetWatcherFactory::GetForProfile(profile);
1766 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541767 web_prefs->user_style_sheet_enabled = true;
1768 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151769 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541770 } else {
1771 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061772 }
1773
[email protected]b7e44ff2012-02-16 03:37:341774 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101775#if defined(OS_MACOSX)
[email protected]325342e62013-01-09 02:29:031776 // TODO(groby): Bug 107371: Implement asynchronous spellchecking API for
[email protected]37b928e2012-05-30 09:01:101777 // Mac so it uses NSSpellChecker in the background.
1778 false;
1779#else
[email protected]61806872012-12-12 04:15:361780 true;
[email protected]37b928e2012-05-30 09:01:101781#endif
[email protected]b7e44ff2012-02-16 03:37:341782 web_prefs->unified_textchecker_enabled =
[email protected]57890242012-10-23 17:46:521783 web_prefs->asynchronous_spell_checking_enabled;
[email protected]dd5d0fb2012-01-18 03:37:571784
[email protected]64d69de42012-02-06 00:19:541785 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061786 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541787 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061788 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541789 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061790 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1791
1792 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541793 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061794 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541795 web_prefs->default_encoding);
1796 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401797 prefs->ClearPref(prefs::kDefaultCharset);
1798 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061799 }
[email protected]64d69de42012-02-06 00:19:541800 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061801
[email protected]88ecf66d2012-12-11 22:53:471802 if (content::IsForceCompositingModeEnabled())
1803 web_prefs->force_compositing_mode = true;
1804
[email protected]299d7f12012-05-23 05:31:151805 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1806 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131807 ExtensionService* service =
1808 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061809 if (service) {
[email protected]1bc28312012-11-08 08:31:531810 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1811 const Extension* extension = service->extensions()->GetByID(url.host());
1812 // Ensure that we are only granting extension preferences to URLs with
1813 // the correct scheme. Without this check, chrome-guest:// schemes used by
1814 // webview tags as well as hosts that happen to match the id of an
1815 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421816 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531817 extension_webkit_preferences::SetPreferences(
1818 extension, view_type, web_prefs);
1819 }
[email protected]f3986f82012-01-03 20:00:061820 }
1821
[email protected]299d7f12012-05-23 05:31:151822 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541823 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151824 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061825 // Disable all kinds of acceleration for background pages.
1826 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541827 web_prefs->force_compositing_mode = false;
1828 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061829 }
[email protected]2e21fe292012-03-02 22:52:321830
1831#if defined(FILE_MANAGER_EXTENSION)
1832 // Override the default of suppressing HW compositing for WebUI pages for the
1833 // file manager, which is implemented using WebUI but wants HW acceleration
1834 // for video decode & render.
1835 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1836 web_prefs->accelerated_compositing_enabled = true;
1837 web_prefs->accelerated_2d_canvas_enabled = true;
1838 }
1839#endif
[email protected]181a95ee2011-07-12 19:26:361840}
1841
1842void ChromeContentBrowserClient::UpdateInspectorSetting(
1843 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061844 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581845 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061846 DictionaryPrefUpdate update(
1847 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1848 prefs::kWebKitInspectorSettings);
1849 DictionaryValue* inspector_settings = update.Get();
1850 inspector_settings->SetWithoutPathExpansion(key,
1851 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361852}
1853
1854void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061855 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581856 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061857 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1858 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361859}
1860
[email protected]b8148ac2011-07-13 22:03:251861void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1862 BrowserURLHandler* handler) {
1863 // Add the default URL handlers.
1864 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1865 BrowserURLHandler::null_handler());
1866 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1867 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1868
[email protected]b3adbd02011-11-30 22:23:271869 // about: handler. Must come before chrome: handler, since it will
1870 // rewrite about: urls to chrome: URLs and then expect chrome: to
1871 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251872 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1873 BrowserURLHandler::null_handler());
1874 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241875 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251876}
1877
1878void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371879 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581880 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471881 BrowsingDataRemover* remover =
1882 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551883 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1884 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251885 // BrowsingDataRemover takes care of deleting itself when done.
1886}
1887
1888void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371889 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581890 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471891 BrowsingDataRemover* remover =
1892 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231893 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551894 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251895 // BrowsingDataRemover takes care of deleting itself when done.
1896}
1897
[email protected]650b2d52013-02-10 03:41:451898base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
[email protected]e1d16eb92011-08-18 23:19:321899 return download_util::GetDefaultDownloadDirectory();
1900}
1901
[email protected]c9b6eb62011-10-18 20:49:391902std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1903 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1904}
1905
[email protected]b7631cc2012-09-15 05:08:381906void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1907 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:541908#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:381909 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1910 scoped_ptr<ppapi::host::HostFactory>(
1911 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:541912#endif
[email protected]b7631cc2012-09-15 05:08:381913}
1914
[email protected]0c7193742012-11-07 19:05:031915content::BrowserPpapiHost*
1916 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
1917 int plugin_process_id) {
1918 BrowserChildProcessHostIterator iter(content::PROCESS_TYPE_NACL_LOADER);
1919 while (!iter.Done()) {
1920 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
1921 if (host->process() &&
1922 host->process()->GetData().id == plugin_process_id) {
1923 // Found the plugin.
1924 return host->browser_ppapi_host();
1925 }
1926 ++iter;
1927 }
1928 return NULL;
1929}
1930
[email protected]38cd8f7f2012-06-15 22:06:071931bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:581932 content::BrowserContext* browser_context,
1933 const GURL& url,
1934 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:291935 if (!url.is_valid())
1936 return false;
1937
1938 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:421939 if (url.SchemeIs(extensions::kExtensionScheme) &&
1940 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:291941 return true;
[email protected]885c0e92012-11-13 20:27:421942 }
[email protected]a658d452012-03-02 12:45:291943
[email protected]9a5940d2012-04-27 19:16:231944 Profile* profile = Profile::FromBrowserContext(browser_context);
1945 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:191946 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131947 extensions::ExtensionSystem::Get(profile)->extension_service();
1948 if (extension_service) {
1949 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:231950 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1951 }
1952
[email protected]f237c0f2012-03-10 07:49:101953 // Need to check this now and not on construction because otherwise it won't
1954 // work with browser_tests.
1955 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1956 std::string allowed_list =
1957 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231958 if (allowed_list == "*") {
1959 // The wildcard allows socket API only for packaged and platform apps.
1960 return extension &&
[email protected]1d5e58b2013-01-31 08:41:401961 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
1962 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
[email protected]9a5940d2012-04-27 19:16:231963 } else if (!allowed_list.empty()) {
[email protected]f4ebe772013-02-02 00:21:391964 base::StringTokenizer t(allowed_list, ",");
[email protected]f237c0f2012-03-10 07:49:101965 while (t.GetNext()) {
1966 if (t.token() == host)
1967 return true;
1968 }
1969 }
1970
[email protected]a658d452012-03-02 12:45:291971 if (!extension)
1972 return false;
1973
[email protected]157cc902012-11-02 06:31:581974 extensions::SocketPermission::CheckParam extension_params(
1975 params.type, params.host, params.port);
1976 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
1977 &extension_params))
[email protected]a658d452012-03-02 12:45:291978 return true;
1979
1980 return false;
[email protected]e461da2f2012-02-16 19:06:401981}
1982
[email protected]650b2d52013-02-10 03:41:451983base::FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
1984 base::FilePath directory;
[email protected]a7944aa2012-10-15 10:12:141985 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
1986 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
1987}
1988
[email protected]a28e3302013-02-03 03:50:431989ui::SelectFilePolicy* ChromeContentBrowserClient::CreateSelectFilePolicy(
1990 WebContents* web_contents) {
1991 return new ChromeSelectFilePolicy(web_contents);
1992}
1993
[email protected]e60c0232011-11-11 19:56:351994#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:181995void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
1996 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:381997 int child_process_id,
[email protected]c7abd422012-09-25 00:20:081998 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:391999#if defined(OS_ANDROID)
[email protected]650b2d52013-02-10 03:41:452000 base::FilePath data_path;
[email protected]29699c22012-10-03 23:57:392001 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
2002 DCHECK(!data_path.empty());
2003
2004 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
[email protected]650b2d52013-02-10 03:41:452005 base::FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
[email protected]29699c22012-10-03 23:57:392006 base::PlatformFile f =
2007 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
2008 DCHECK(f != base::kInvalidPlatformFileValue);
2009 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
2010 FileDescriptor(f, true)));
2011
[email protected]650b2d52013-02-10 03:41:452012 base::FilePath chrome_resources_pak =
[email protected]29699c22012-10-03 23:57:392013 data_path.AppendASCII("chrome_100_percent.pak");
2014 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
2015 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:372016 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:392017 FileDescriptor(f, true)));
2018
2019 const std::string locale = GetApplicationLocale();
[email protected]650b2d52013-02-10 03:41:452020 base::FilePath locale_pak = ResourceBundle::GetSharedInstance().
[email protected]29699c22012-10-03 23:57:392021 GetLocaleFilePath(locale, false);
2022 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
2023 DCHECK(f != base::kInvalidPlatformFileValue);
2024 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
2025 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:382026
[email protected]650b2d52013-02-10 03:41:452027 base::FilePath resources_pack_path;
[email protected]73592382013-01-18 19:22:372028 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
2029 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
2030 DCHECK(f != base::kInvalidPlatformFileValue);
2031 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
2032 FileDescriptor(f, true)));
2033
[email protected]40da3e0c2012-10-24 22:03:382034#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:432035 if (IsCrashReporterEnabled()) {
2036 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
2037 if (f == base::kInvalidPlatformFileValue) {
2038 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
2039 "be disabled for this process.";
2040 } else {
2041 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
2042 FileDescriptor(f, true)));
2043 }
[email protected]40da3e0c2012-10-24 22:03:382044 }
2045#endif // defined(USE_LINUX_BREAKPAD)
2046
2047#else
2048 int crash_signal_fd = GetCrashSignalFD(command_line);
2049 if (crash_signal_fd >= 0) {
2050 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
2051 FileDescriptor(crash_signal_fd,
2052 false)));
2053 }
[email protected]29699c22012-10-03 23:57:392054#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:302055}
[email protected]e60c0232011-11-11 19:56:352056#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:302057
[email protected]4a65826d2011-08-25 16:04:012058#if defined(OS_WIN)
2059const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
2060 return chrome::kBrowserResourcesDll;
2061}
2062#endif
2063
[email protected]37a72af2011-06-13 05:42:012064#if defined(USE_NSS)
2065crypto::CryptoModuleBlockingPasswordDelegate*
2066 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
2067 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:292068 return chrome::NewCryptoModuleBlockingDialogDelegate(
2069 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:012070}
2071#endif
2072
[email protected]e9a32a52012-06-14 23:32:432073void ChromeContentBrowserClient::SetApplicationLocale(
2074 const std::string& locale) {
2075 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2076
2077 // This object is guaranteed to outlive all threads so we don't have to
2078 // worry about the lack of refcounting and can just post as Unretained.
2079 //
2080 // The common case is that this function is called early in Chrome startup
2081 // before any threads are created (it will also be called later if the user
2082 // changes the pref). In this case, there will be no threads created and
2083 // posting will fail. When there are no threads, we can just set the string
2084 // without worrying about threadsafety.
2085 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
2086 base::Bind(
2087 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
2088 base::Unretained(this), locale)))
2089 io_thread_application_locale_ = locale;
2090}
2091
2092void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
2093 const std::string& locale) {
2094 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2095 io_thread_application_locale_ = locale;
2096}
2097
[email protected]d977f9c2011-03-14 16:10:262098} // namespace chrome