blob: f892bd46fb1ef9c8d1b864eddbb726ac4a00c265 [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]e461da2f2012-02-16 19:06:4014#include "base/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]94fb5102013-01-23 09:00:4742#include "chrome/browser/media/chrome_webrtc_internals.h"
[email protected]dc73a7b2012-03-25 15:27:1843#include "chrome/browser/media/media_internals.h"
[email protected]0c7193742012-11-07 19:05:0344#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2845#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0446#include "chrome/browser/notifications/desktop_notification_service.h"
47#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4248#include "chrome/browser/platform_util.h"
[email protected]c2295f72013-01-03 22:18:5649#include "chrome/browser/plugins/plugin_info_message_filter.h"
[email protected]763ec4ca2011-04-29 15:48:1250#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0651#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4152#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5053#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0754#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4155#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1456#include "chrome/browser/printing/printing_message_filter.h"
57#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3258#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0659#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1460#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3361#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]b7631cc2012-09-15 05:08:3862#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]05fcf982011-04-19 00:44:1463#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0264#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4665#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]3b455502012-12-11 18:22:5866#include "chrome/browser/ssl/ssl_add_certificate.h"
[email protected]848dd042011-06-04 18:24:0367#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]11feec322012-09-18 03:58:5268#include "chrome/browser/ssl/ssl_tab_helper.h"
[email protected]8ec26472011-06-06 16:52:4569#include "chrome/browser/tab_contents/tab_util.h"
[email protected]c27541f2012-05-24 19:25:5470#include "chrome/browser/toolkit_extra_parts.h"
[email protected]b5d73422012-06-02 23:46:4471#include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h"
[email protected]863f70a2012-01-27 02:05:5072#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0673#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1574#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5375#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3076#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0177#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1478#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3079#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0480#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3881#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4482#include "chrome/common/extensions/extension_set.h"
[email protected]157cc902012-11-02 06:31:5883#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3484#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1285#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3886#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0987#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4388#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3089#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:3890#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:3191#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:0392#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:5993#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:3694#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:3095#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3396#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0597#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3398#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1999#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10100#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43101#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18102#include "content/public/common/content_descriptors.h"
[email protected]885c0e92012-11-13 20:27:42103#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39104#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23105#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53106#include "net/base/escape.h"
[email protected]3b455502012-12-11 18:22:58107#include "net/base/mime_util.h"
[email protected]7a593db2012-02-13 21:19:40108#include "net/base/ssl_cert_request_info.h"
[email protected]5b9bc352012-07-18 13:13:34109#include "net/cookies/canonical_cookie.h"
[email protected]aa84a7e2012-03-15 21:29:06110#include "net/cookies/cookie_options.h"
[email protected]b7631cc2012-09-15 05:08:38111#include "ppapi/host/ppapi_host.h"
[email protected]c9b6eb62011-10-18 20:49:39112#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:08113#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:36114#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:04115#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:26116
[email protected]b48c9182011-10-26 18:03:30117#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38118#include "chrome/browser/chrome_browser_main_win.h"
119#elif defined(OS_MACOSX)
120#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56121#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30122#elif defined(OS_CHROMEOS)
123#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49124#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26125#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30126#include "chrome/browser/chrome_browser_main_linux.h"
[email protected]81054f812012-08-30 00:47:09127#elif defined(OS_ANDROID)
[email protected]40da3e0c2012-10-24 22:03:38128#include "chrome/browser/android/crash_dump_manager.h"
[email protected]81054f812012-08-30 00:47:09129#include "chrome/browser/chrome_browser_main_android.h"
[email protected]29699c22012-10-03 23:57:39130#include "chrome/common/descriptors_android.h"
[email protected]b48c9182011-10-26 18:03:30131#elif defined(OS_POSIX)
132#include "chrome/browser/chrome_browser_main_posix.h"
133#endif
134
[email protected]6653c192012-04-10 22:52:44135#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30136#include "base/linux_util.h"
[email protected]1602cde2012-06-26 15:09:12137#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43138#endif
[email protected]b80f68432011-05-02 17:22:30139
[email protected]1e87df32012-09-12 04:53:19140#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
141#include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
142#endif
143
[email protected]29699c22012-10-03 23:57:39144#if defined(OS_ANDROID)
145#include "ui/base/ui_base_paths.h"
146#endif
147
[email protected]37a72af2011-06-13 05:42:01148#if defined(USE_NSS)
149#include "chrome/browser/ui/crypto_module_password_dialog.h"
150#endif
151
[email protected]c7abd422012-09-25 00:20:08152using base::FileDescriptor;
[email protected]c8c77182011-12-21 15:04:47153using content::AccessTokenStore;
[email protected]0c7193742012-11-07 19:05:03154using content::BrowserChildProcessHostIterator;
[email protected]631bb742011-11-02 11:29:39155using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31156using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59157using content::ChildProcessSecurityPolicy;
[email protected]c7abd422012-09-25 00:20:08158using content::FileDescriptorInfo;
[email protected]9f9749a2012-03-02 19:37:00159using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11160using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33161using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13162using content::WebContents;
[email protected]c2e66e12012-06-27 06:27:06163using extensions::APIPermission;
[email protected]1c321ee2012-05-21 03:02:34164using extensions::Extension;
[email protected]6717bf272012-05-11 23:31:25165using webkit_glue::WebPreferences;
[email protected]631bb742011-11-02 11:29:39166
[email protected]c5dbef02011-05-13 05:06:09167namespace {
168
[email protected]e461da2f2012-02-16 19:06:40169const char* kPredefinedAllowedSocketOrigins[] = {
170 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18171 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45172 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
173 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
174 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
175 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
[email protected]a450b6be2012-05-22 19:30:35176 "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary
[email protected]9040a0c22012-06-22 19:06:54177 "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089
178 "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099
179 "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099
180 "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099
181 "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099
182 "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099
[email protected]4dc30b82012-08-15 00:24:38183 "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099
[email protected]45db05f2012-12-10 21:52:58184 "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514
185 "iabmpiboiopbgfabjmgeedhcmjenhbla" // see crbug.com/165080
[email protected]e461da2f2012-02-16 19:06:40186};
187
[email protected]f8f93eb2012-09-25 03:06:24188// Returns a copy of the given url with its host set to given host and path set
189// to given path. Other parts of the url will be the same.
190GURL ReplaceURLHostAndPath(const GURL& url,
191 const std::string& host,
192 const std::string& path) {
193 url_canon::Replacements<char> replacements;
194 replacements.SetHost(host.c_str(),
195 url_parse::Component(0, host.length()));
196 replacements.SetPath(path.c_str(),
197 url_parse::Component(0, path.length()));
198 return url.ReplaceComponents(replacements);
199}
200
201// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
202GURL AddUberHost(const GURL& url) {
203 const std::string uber_host = chrome::kChromeUIUberHost;
204 const std::string new_path = url.host() + url.path();
205
206 return ReplaceURLHostAndPath(url, uber_host, new_path);
207}
208
[email protected]045bf7c2012-09-28 20:27:36209// If url->host() is "chrome" and url->path() has characters other than the
210// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
211// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24212bool RemoveUberHost(GURL* url) {
213 if (url->host() != chrome::kChromeUIUberHost)
214 return false;
215
[email protected]045bf7c2012-09-28 20:27:36216 if (url->path().empty() || url->path() == "/")
217 return false;
218
[email protected]f8f93eb2012-09-25 03:06:24219 const std::string old_path = url->path();
220
221 const std::string::size_type separator = old_path.find('/', 1);
222 std::string new_host;
223 std::string new_path;
224 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36225 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24226 } else {
227 new_host = old_path.substr(1, separator - 1);
228 new_path = old_path.substr(separator);
229 }
230
231 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
232
233 return true;
234}
235
[email protected]b8148ac2011-07-13 22:03:25236// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42237bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24238 // Do not handle special URLs such as "about:foo"
239 if (!url->host().empty()) {
240 const GURL chrome_url = AddUberHost(*url);
241
242 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
243 // be called.
244 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
245 browser_context, chrome_url))
246 return true;
247 }
248
[email protected]863f70a2012-01-27 02:05:50249 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
250 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25251 return false;
252
[email protected]fe69558d2012-03-12 11:34:49253#if defined(OS_CHROMEOS)
254 // Special case : in ChromeOS in Guest mode bookmarks and history are
255 // disabled for security reasons. New tab page explains the reasons, so
256 // we redirect user to new tab page.
257 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
258 if (url->SchemeIs(chrome::kChromeUIScheme) &&
259 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
260 url->DomainIs(chrome::kChromeUIHistoryHost))) {
261 // Rewrite with new tab URL
262 *url = GURL(chrome::kChromeUINewTabURL);
263 }
264 }
265#endif
266
[email protected]b8148ac2011-07-13 22:03:25267 // Special case the new tab page. In older versions of Chrome, the new tab
268 // page was hosted at chrome-internal:<blah>. This might be in people's saved
269 // sessions or bookmarks, so we say any URL with that scheme triggers the new
270 // tab page.
271 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
272 // Rewrite it with the proper new tab URL.
273 *url = GURL(chrome::kChromeUINewTabURL);
274 }
275
276 return true;
277}
278
[email protected]f8f93eb2012-09-25 03:06:24279// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
280// "chrome://foo/".
281bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
282 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
283 return false;
284
285 return RemoveUberHost(url);
286}
287
[email protected]8d3132f62011-10-12 07:13:42288// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
289// below. Extension, and isolated apps require different privileges to be
290// granted to their RenderProcessHosts. This classification allows us to make
291// sure URLs are served by hosts with the right set of privileges.
292enum RenderProcessHostPrivilege {
293 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45294 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42295 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45296 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42297};
298
299RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
300 const GURL& url,
301 ExtensionService* service) {
302 // Default to a normal renderer cause it is lower privileged. This should only
303 // occur if the URL on a site instance is either malformed, or uninitialized.
304 // If it is malformed, then there is no need for better privileges anyways.
305 // If it is uninitialized, but eventually settles on being an a scheme other
306 // than normal webrenderer, the navigation logic will correct us out of band
307 // anyways.
308 if (!url.is_valid())
309 return PRIV_NORMAL;
310
[email protected]885c0e92012-11-13 20:27:42311 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44312 const Extension* extension =
313 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45314 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42315 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45316 if (extension && extension->is_hosted_app())
317 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42318
319 return PRIV_EXTENSION;
320 }
321
322 return PRIV_NORMAL;
323}
324
325RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30326 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46327 extensions::ProcessMap* process_map,
328 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46329 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30330 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46331 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21332 return PRIV_NORMAL;
333
[email protected]6f371442011-11-09 06:45:46334 for (std::set<std::string>::iterator iter = extension_ids.begin();
335 iter != extension_ids.end(); ++iter) {
336 const Extension* extension = service->GetExtensionById(*iter, false);
337 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42338 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45339 if (extension && extension->is_hosted_app())
340 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42341 }
342
[email protected]676f6ab2011-10-19 20:23:21343 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42344}
345
[email protected]6786bf402011-12-03 15:19:45346bool CertMatchesFilter(const net::X509Certificate& cert,
347 const base::DictionaryValue& filter) {
348 // TODO(markusheintz): This is the minimal required filter implementation.
349 // Implement a better matcher.
350
351 // An empty filter matches any client certificate since no requirements are
352 // specified at all.
353 if (filter.empty())
354 return true;
355
356 std::string common_name;
357 if (filter.GetString("ISSUER.CN", &common_name) &&
358 (cert.issuer().common_name == common_name)) {
359 return true;
360 }
361 return false;
362}
363
[email protected]f3986f82012-01-03 20:00:06364// Fills |map| with the per-script font prefs under path |map_name|.
365void FillFontFamilyMap(const PrefService* prefs,
366 const char* map_name,
367 WebPreferences::ScriptFontFamilyMap* map) {
368 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
369 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
370 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
371 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23372 if (!font_family.empty())
373 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06374 }
375}
376
[email protected]a1733df2012-06-22 11:24:18377#if defined(OS_POSIX) && !defined(OS_MACOSX)
378int GetCrashSignalFD(const CommandLine& command_line) {
379 if (command_line.HasSwitch(switches::kExtensionProcess)) {
380 ExtensionCrashHandlerHostLinux* crash_handler =
381 ExtensionCrashHandlerHostLinux::GetInstance();
382 return crash_handler->GetDeathSignalSocket();
383 }
384
385 std::string process_type =
386 command_line.GetSwitchValueASCII(switches::kProcessType);
387
388 if (process_type == switches::kRendererProcess)
389 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
390
391 if (process_type == switches::kPluginProcess)
392 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
393
394 if (process_type == switches::kPpapiPluginProcess)
395 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
396
397 if (process_type == switches::kGpuProcess)
398 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
399
400 return -1;
401}
402#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
403
[email protected]9dbfff12011-07-01 19:37:07404} // namespace
[email protected]c5dbef02011-05-13 05:06:09405
[email protected]d977f9c2011-03-14 16:10:26406namespace chrome {
407
[email protected]e461da2f2012-02-16 19:06:40408ChromeContentBrowserClient::ChromeContentBrowserClient() {
409 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
410 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40411}
412
413ChromeContentBrowserClient::~ChromeContentBrowserClient() {
414}
415
[email protected]bca18382012-06-25 19:15:23416// static
[email protected]5b199522012-12-22 17:24:44417void ChromeContentBrowserClient::RegisterUserPrefs(PrefServiceSyncable* prefs) {
[email protected]bca18382012-06-25 19:15:23418 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs,
419 false,
[email protected]5b199522012-12-22 17:24:44420 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23421 prefs->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
422 true,
[email protected]5b199522012-12-22 17:24:44423 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23424 prefs->RegisterBooleanPref(prefs::kEnableMemoryInfo,
425 false,
[email protected]5b199522012-12-22 17:24:44426 PrefServiceSyncable::UNSYNCABLE_PREF);
[email protected]bca18382012-06-25 19:15:23427}
428
[email protected]50462bf02011-11-21 19:13:31429content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
430 const content::MainFunctionParams& parameters) {
431 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30432 // Construct the Main browser parts based on the OS type.
433#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31434 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04435#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31436 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30437#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22438 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26439#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31440 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14441#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09442 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30443#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31444 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04445#else
[email protected]b48c9182011-10-26 18:03:30446 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31447 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30448#endif
449
[email protected]c7480942011-11-08 19:18:27450 // Construct additional browser parts. Stages are called in the order in
451 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22452#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41453 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04454#endif
[email protected]c7480942011-11-08 19:18:27455
456#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41457 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27458#endif
459
[email protected]dc04be7c2012-03-15 23:57:49460#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41461 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49462#endif
463
[email protected]e050ef142012-03-21 01:04:24464#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41465 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24466#endif
467
[email protected]50462bf02011-11-21 19:13:31468 return main_parts;
[email protected]f967b722011-09-07 00:58:04469}
470
[email protected]38b098f2012-03-14 21:11:57471content::WebContentsView*
472 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57473 WebContents* web_contents,
474 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57475 return NULL;
476}
477
[email protected]e94bbcb2012-09-07 05:33:57478std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19479 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57480 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53481 std::string partition_id;
482
483 // The partition ID for webview guest processes is the string value of its
484 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
485 if (site.SchemeIs(chrome::kGuestScheme))
486 partition_id = site.spec();
487
488 DCHECK(IsValidStoragePartitionId(browser_context,partition_id));
489 return partition_id;
490}
491
492bool ChromeContentBrowserClient::IsValidStoragePartitionId(
493 content::BrowserContext* browser_context,
494 const std::string& partition_id) {
495 // The default ID is empty and is always valid.
496 if (partition_id.empty())
497 return true;
498
499 return GURL(partition_id).is_valid();
500}
501
502void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
503 content::BrowserContext* browser_context,
504 const GURL& site,
[email protected]14acc642012-11-17 12:20:10505 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53506 std::string* partition_domain,
507 std::string* partition_name,
508 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10509 // Default to the browser-wide storage partition and override based on |site|
510 // below.
511 partition_domain->clear();
512 partition_name->clear();
513 *in_memory = false;
514
[email protected]1bc28312012-11-08 08:31:53515 // For the webview tag, we create special guest processes, which host the
516 // tag content separately from the main application that embeds the tag.
517 // A webview tag can specify both the partition name and whether the storage
518 // for that partition should be persisted. Each tag gets a SiteInstance with
519 // a specially formatted URL, based on the application it is hosted by and
520 // the partition requested by it. The format for that URL is:
521 // chrome-guest://partition_domain/persist?partition_name
522 if (site.SchemeIs(chrome::kGuestScheme)) {
523 // Since guest URLs are only used for packaged apps, there must be an app
524 // id in the URL.
525 CHECK(site.has_host());
526 *partition_domain = site.host();
527 // Since persistence is optional, the path must either be empty or the
528 // literal string.
529 *in_memory = (site.path() != "/persist");
530 // The partition name is user supplied value, which we have encoded when the
531 // URL was created, so it needs to be decoded.
532 *partition_name = net::UnescapeURLComponent(site.query(),
533 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10534 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
535 // If |can_be_default| is false, the caller is stating that the |site|
536 // should be parsed as if it had isolated storage. In particular it is
537 // important to NOT check ExtensionService for the is_storage_isolated()
538 // attribute because this code path is run during Extension uninstall
539 // to do cleanup after the Extension has already been unloaded from the
540 // ExtensionService.
541 bool is_isolated = !can_be_default;
542 if (can_be_default) {
543 const Extension* extension = NULL;
544 Profile* profile = Profile::FromBrowserContext(browser_context);
545 ExtensionService* extension_service =
546 extensions::ExtensionSystem::Get(profile)->extension_service();
547 if (extension_service) {
548 extension = extension_service->extensions()->
549 GetExtensionOrAppByURL(ExtensionURLInfo(site));
550 if (extension && extension->is_storage_isolated()) {
551 is_isolated = true;
552 }
553 }
554 }
[email protected]1bc28312012-11-08 08:31:53555
[email protected]14acc642012-11-17 12:20:10556 if (is_isolated) {
557 CHECK(site.has_host());
558 // For extensions with isolated storage, the the host of the |site| is
559 // the |partition_domain|. The |in_memory| and |partition_name| are only
560 // used in guest schemes so they are cleared here.
561 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53562 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10563 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53564 }
[email protected]d1198fd2012-08-13 22:50:19565 }
566
[email protected]14acc642012-11-17 12:20:10567 // Assert that if |can_be_default| is false, the code above must have found a
568 // non-default partition. If this fails, the caller has a serious logic
569 // error about which StoragePartition they expect to be in and it is not
570 // safe to continue.
571 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44572}
573
[email protected]38b098f2012-03-14 21:11:57574content::WebContentsViewDelegate*
575 ChromeContentBrowserClient::GetWebContentsViewDelegate(
576 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27577 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32578}
579
[email protected]f364d1392011-04-08 21:03:10580void ChromeContentBrowserClient::RenderViewHostCreated(
581 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46582
[email protected]9f76c1e2012-03-05 15:15:58583 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46584 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02585 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46586
587 new ChromeRenderViewHostObserver(render_view_host,
588 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49589 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26590}
591
[email protected]44703cc72013-01-24 04:56:06592void ChromeContentBrowserClient::GuestWebContentsCreated(
593 WebContents* guest_web_contents, WebContents* embedder_web_contents) {
594 Profile* profile = Profile::FromBrowserContext(
595 embedder_web_contents->GetBrowserContext());
596 ExtensionService* service =
597 extensions::ExtensionSystem::Get(profile)->extension_service();
598 if (!service)
599 return;
600 const GURL& url = embedder_web_contents->GetSiteInstance()->GetSiteURL();
601 const Extension* extension = service->extensions()->
602 GetExtensionOrAppByURL(ExtensionURLInfo(url));
603 if (!extension)
604 return;
605 std::vector<ExtensionMsg_Loaded_Params> extensions;
606 extensions.push_back(ExtensionMsg_Loaded_Params(extension));
607 guest_web_contents->Send(new ExtensionMsg_Loaded(extensions));
608}
609
[email protected]f3b1a082011-11-18 00:34:30610void ChromeContentBrowserClient::RenderProcessHostCreated(
611 content::RenderProcessHost* host) {
612 int id = host->GetID();
613 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
614 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02615 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]ebd71962012-12-20 02:56:55616#if defined(ENABLE_PLUGINS)
[email protected]f3b1a082011-11-18 00:34:30617 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]ebd71962012-12-20 02:56:55618#endif
[email protected]658677f2012-06-09 06:04:02619#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08620 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03621#endif
[email protected]f3b1a082011-11-18 00:34:30622 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02623 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30624 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56625#if defined(OS_MACOSX)
626 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
627#endif
[email protected]f3b1a082011-11-18 00:34:30628 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03629 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07630 host->GetChannel()->AddFilter(
631 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38632
[email protected]2ccf45c2011-08-19 23:35:50633 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
634 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07635
636 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56637
638 RendererContentSettingRules rules;
639 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
640 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14641}
642
[email protected]3c788372013-01-10 08:34:28643content::WebUIControllerFactory*
644 ChromeContentBrowserClient::GetWebUIControllerFactory() {
645 return ChromeWebUIControllerFactory::GetInstance();
646}
647
[email protected]3d7474ff2011-07-27 17:47:37648GURL ChromeContentBrowserClient::GetEffectiveURL(
649 content::BrowserContext* browser_context, const GURL& url) {
650 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08651 // Get the effective URL for the given actual URL. If the URL is part of an
652 // installed app, the effective URL is an extension URL with the ID of that
653 // extension as the host. This has the effect of grouping apps together in
654 // a common SiteInstance.
[email protected]2ee3da9d62012-12-05 20:17:19655 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13656 extensions::ExtensionSystem::Get(profile)->extension_service();
657 if (!extension_service)
[email protected]36fb2c7c2011-04-04 15:49:08658 return url;
659
[email protected]06bdd2b2012-11-30 18:47:13660 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44661 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08662 if (!extension)
663 return url;
664
[email protected]15877ca2011-11-18 22:40:52665 // Bookmark apps do not use the hosted app process model, and should be
666 // treated as normal URLs.
667 if (extension->from_bookmark())
668 return url;
669
[email protected]36fb2c7c2011-04-04 15:49:08670 // If the URL is part of an extension's web extent, convert it to an
671 // extension URL.
672 return extension->GetResourceURL(url.path());
673}
674
[email protected]056ad2a2011-07-12 02:13:55675bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37676 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55677 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52678 // Because we expect to use the effective URL, URLs for hosted apps (apart
679 // from bookmark apps) should have an extension scheme by now.
[email protected]885c0e92012-11-13 20:27:42680 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55681 return false;
682
[email protected]3d7474ff2011-07-27 17:47:37683 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19684 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13685 extensions::ExtensionSystem::Get(profile)->extension_service();
686 if (!extension_service)
[email protected]056ad2a2011-07-12 02:13:55687 return false;
688
[email protected]06bdd2b2012-11-30 18:47:13689 const Extension* extension = extension_service->extensions()->
[email protected]615d88f2011-12-13 01:47:44690 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55691 if (!extension)
692 return false;
693
694 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53695 // permission, or that does not allow JavaScript access to the background
696 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55697 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53698 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06699 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]7b54ca02012-03-02 18:06:53700 !extension->allow_background_js_access()) {
701 return false;
702 }
703 }
[email protected]056ad2a2011-07-12 02:13:55704
[email protected]7b54ca02012-03-02 18:06:53705 // Hosted apps that have script access to their background page must use
706 // process per site, since all instances can make synchronous calls to the
707 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55708 return true;
709}
710
[email protected]46fb9442011-12-09 17:57:47711bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
712 return ProfileIOData::IsHandledURL(url);
713}
714
[email protected]2a5221b2011-09-27 23:07:31715bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30716 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31717 const GURL& site_url) {
718 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30719 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13720 ExtensionService* service =
721 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46722 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31723
[email protected]ffa97602011-11-17 17:55:52724 // Don't allow the Task Manager to share a process with anything else.
725 // Otherwise it can affect the renderers it is observing.
726 // Note: we could create another RenderProcessHostPrivilege bucket for
727 // this to allow multiple chrome://tasks instances to share, but that's
728 // a very unlikely case without serious consequences.
729 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
730 return false;
731
[email protected]8d3132f62011-10-12 07:13:42732 // These may be NULL during tests. In that case, just assume any site can
733 // share any host.
[email protected]6f371442011-11-09 06:45:46734 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31735 return true;
736
[email protected]eec0b33c2011-12-05 22:09:45737 // Otherwise, just make sure the process privilege matches the privilege
738 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57739 RenderProcessHostPrivilege privilege_required =
740 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45741 return GetProcessPrivilege(process_host, process_map, service) ==
742 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31743}
744
[email protected]76411f412012-02-22 18:56:06745// This function is trying to limit the amount of processes used by extensions
746// with background pages. It uses a globally set percentage of processes to
747// run such extensions and if the limit is exceeded, it returns true, to
748// indicate to the content module to group extensions together.
749bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
750 content::BrowserContext* browser_context, const GURL& url) {
751 // It has to be a valid URL for us to check for an extension.
752 if (!url.is_valid())
753 return false;
754
755 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]2ee3da9d62012-12-05 20:17:19756 ExtensionService* service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:13757 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]76411f412012-02-22 18:56:06758 if (!service)
759 return false;
760
761 // We have to have a valid extension with background page to proceed.
762 const Extension* extension =
763 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
764 if (!extension)
765 return false;
766 if (!extension->has_background_page())
767 return false;
768
769 std::set<int> process_ids;
770 size_t max_process_count =
771 content::RenderProcessHost::GetMaxRendererProcessCount();
772
773 // Go through all profiles to ensure we have total count of extension
774 // processes containing background pages, otherwise one profile can
775 // starve the other.
776 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
777 GetLoadedProfiles();
778 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03779 ExtensionProcessManager* epm =
780 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32781 for (ExtensionProcessManager::const_iterator iter =
782 epm->background_hosts().begin();
783 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13784 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32785 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06786 }
787 }
788
789 if (process_ids.size() >
790 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
791 return true;
792 }
793
794 return false;
795}
796
[email protected]6f371442011-11-09 06:45:46797void ChromeContentBrowserClient::SiteInstanceGotProcess(
798 SiteInstance* site_instance) {
799 CHECK(site_instance->HasProcess());
800
801 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02802 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13803 ExtensionService* service =
804 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46805 if (!service)
806 return;
807
808 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44809 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59810 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46811 if (!extension)
812 return;
813
[email protected]6bc04fd82011-12-04 02:29:35814 service->process_map()->Insert(extension->id(),
815 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33816 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46817 BrowserThread::PostTask(
818 BrowserThread::IO, FROM_HERE,
819 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59820 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46821 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35822 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33823 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46824}
825
826void ChromeContentBrowserClient::SiteInstanceDeleting(
827 SiteInstance* site_instance) {
828 if (!site_instance->HasProcess())
829 return;
830
831 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02832 site_instance->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13833 ExtensionService* service =
834 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]6f371442011-11-09 06:45:46835 if (!service)
836 return;
837
838 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44839 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:59840 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46841 if (!extension)
842 return;
843
[email protected]6bc04fd82011-12-04 02:29:35844 service->process_map()->Remove(extension->id(),
845 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33846 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46847 BrowserThread::PostTask(
848 BrowserThread::IO, FROM_HERE,
849 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59850 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46851 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35852 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33853 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46854}
855
[email protected]f05763972012-06-06 18:17:26856bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:08857 const GURL& current_url,
858 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26859 if (current_url.is_empty()) {
860 // Always choose a new process when navigating to extension URLs. The
861 // process grouping logic will combine all of a given extension's pages
862 // into the same process.
[email protected]885c0e92012-11-13 20:27:42863 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:26864 return true;
[email protected]e3daf3c2011-10-05 21:17:08865
[email protected]f05763972012-06-06 18:17:26866 return false;
867 }
868
869 // Also, we must switch if one is an extension and the other is not the exact
870 // same extension.
[email protected]885c0e92012-11-13 20:27:42871 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
872 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:26873 if (current_url.GetOrigin() != new_url.GetOrigin())
874 return true;
875 }
876
877 return false;
[email protected]e3daf3c2011-10-05 21:17:08878}
879
[email protected]395045c2012-05-22 15:04:38880bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
881 content::ResourceContext* resource_context, const GURL& current_url,
882 const GURL& new_url) {
883 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
884 return extensions::CrossesExtensionProcessBoundary(
885 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:17886 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:38887}
888
[email protected]763ec4ca2011-04-29 15:48:12889std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
890 const std::string& alias_name) {
891 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
892}
893
[email protected]b80f68432011-05-02 17:22:30894void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
895 CommandLine* command_line, int child_process_id) {
896#if defined(USE_LINUX_BREAKPAD)
897 if (IsCrashReporterEnabled()) {
898 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
899 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
900 }
901#elif defined(OS_MACOSX)
902 if (IsCrashReporterEnabled()) {
903 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
904 child_process_logging::GetClientId());
905 }
906#endif // OS_MACOSX
907
[email protected]f1933792011-06-14 00:49:34908 if (logging::DialogsAreSuppressed())
909 command_line->AppendSwitch(switches::kNoErrorDialogs);
910
[email protected]b80f68432011-05-02 17:22:30911 std::string process_type =
912 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17913 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52914 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30915 FilePath user_data_dir =
916 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
917 if (!user_data_dir.empty())
918 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
919#if defined(OS_CHROMEOS)
920 const std::string& login_profile =
921 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
922 if (!login_profile.empty())
923 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
924#endif
925
[email protected]f3b1a082011-11-18 00:34:30926 content::RenderProcessHost* process =
927 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37928 if (process) {
929 Profile* profile = Profile::FromBrowserContext(
930 process->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:13931 ExtensionService* extension_service =
932 extensions::ExtensionSystem::Get(profile)->extension_service();
933 if (extension_service) {
934 extensions::ProcessMap* process_map = extension_service->process_map();
[email protected]c8598d42012-09-25 21:17:00935 if (process_map && process_map->Contains(process->GetID()))
936 command_line->AppendSwitch(switches::kExtensionProcess);
937 }
[email protected]b80f68432011-05-02 17:22:30938
[email protected]a8d851f82011-12-21 00:32:37939 PrefService* prefs = profile->GetPrefs();
940 // Currently this pref is only registered if applied via a policy.
941 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
942 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
943 // Turn this policy into a command line switch.
944 command_line->AppendSwitch(switches::kDisable3DAPIs);
945 }
[email protected]718eab62011-10-05 21:16:52946
[email protected]a8d851f82011-12-21 00:32:37947 // Disable client-side phishing detection in the renderer if it is
948 // disabled in the Profile preferences or the browser process.
949 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
950 !g_browser_process->safe_browsing_detection_service()) {
951 command_line->AppendSwitch(
952 switches::kDisableClientSidePhishingDetection);
953 }
[email protected]0045b0f42012-07-26 11:52:08954
955 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:21956 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]47c7ec82012-01-18 03:29:21957 }
[email protected]4287a3d2011-06-13 23:56:51958
[email protected]87552982012-11-02 17:21:40959 if (content::IsThreadedCompositingEnabled())
960 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
961
[email protected]47c7ec82012-01-18 03:29:21962 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51963 static const char* const kSwitchNames[] = {
964 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48965 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51966 switches::kAllowScriptingGallery,
967 switches::kAppsCheckoutURL,
968 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31969 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51970 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50971 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53972 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:11973 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:51974 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21975 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51976 switches::kEnableCrxlessWebApps,
977 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:51978 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:51979 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:51980 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:48981 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:05982 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:51983 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:51984 switches::kMemoryProfiling,
985 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37986 switches::kNoJsRandomness,
[email protected]732b1604e2012-10-26 19:59:58987 switches::kPerformCrashAnalysis,
[email protected]f45c5f32012-04-18 19:26:37988 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51989 switches::kPpapiFlashArgs,
990 switches::kPpapiFlashInProcess,
991 switches::kPpapiFlashPath,
992 switches::kPpapiFlashVersion,
993 switches::kProfilingAtStart,
994 switches::kProfilingFile,
995 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37996 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51997 switches::kSilentDumpOnDCHECK,
[email protected]c79d9492012-10-04 19:56:30998 switches::kSpdyProxyOrigin,
[email protected]a446534d2012-02-09 00:07:38999 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:511000 };
1001
1002 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1003 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:171004 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:381005 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351006 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381007 switches::kEnableExperimentalExtensionApis,
1008 switches::kWhitelistedExtensionID,
1009 };
1010
1011 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1012 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511013 } else if (process_type == switches::kPluginProcess) {
1014 static const char* const kSwitchNames[] = {
1015 #if defined(OS_CHROMEOS)
1016 switches::kLoginProfile,
1017 #endif
1018 switches::kMemoryProfiling,
1019 switches::kSilentDumpOnDCHECK,
1020 switches::kUserDataDir,
1021 };
1022
1023 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1024 arraysize(kSwitchNames));
1025 } else if (process_type == switches::kZygoteProcess) {
1026 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511027 switches::kUserDataDir, // Make logs go to the right file.
1028 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501029 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511030 switches::kPpapiFlashInProcess,
1031 switches::kPpapiFlashPath,
1032 switches::kPpapiFlashVersion,
1033 };
1034
1035 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1036 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111037 } else if (process_type == switches::kGpuProcess) {
1038 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1039 // because GPU is expected to be unreliable.
1040 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1041 !command_line->HasSwitch(switches::kDisableBreakpad))
1042 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301043 }
[email protected]6f08af82011-09-15 01:19:031044
1045 // The command line switch kEnableBenchmarking needs to be specified along
1046 // with the kEnableStatsTable switch to ensure that the stats table global
1047 // is initialized correctly.
1048 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1049 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301050}
1051
1052std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431053 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1054 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:301055 return g_browser_process->GetApplicationLocale();
1056}
1057
[email protected]597a867b2011-11-18 18:31:201058std::string ChromeContentBrowserClient::GetAcceptLangs(
1059 content::BrowserContext* context) {
1060 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371061 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081062}
1063
[email protected]9ec0f452012-05-31 15:58:531064gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221065 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531066 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081067}
1068
[email protected]a2176792011-05-08 19:30:491069bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091070 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191071 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201072 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321073 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201074 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051075 return io_data->GetCookieSettings()->
1076 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491077}
1078
[email protected]ed24fad2011-05-10 22:44:011079bool ChromeContentBrowserClient::AllowGetCookie(
1080 const GURL& url,
1081 const GURL& first_party,
1082 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201083 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011084 int render_process_id,
1085 int render_view_id) {
1086 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201087 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051088 bool allow = io_data->GetCookieSettings()->
1089 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011090
[email protected]8093a542011-05-13 07:29:321091 BrowserThread::PostTask(
1092 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031093 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431094 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011095 return allow;
1096}
1097
1098bool ChromeContentBrowserClient::AllowSetCookie(
1099 const GURL& url,
1100 const GURL& first_party,
1101 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201102 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011103 int render_process_id,
1104 int render_view_id,
1105 net::CookieOptions* options) {
1106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201107 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051108 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1109 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1110
[email protected]8093a542011-05-13 07:29:321111 BrowserThread::PostTask(
1112 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031113 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431114 render_view_id, url, first_party, cookie_line, *options,
1115 !allow));
[email protected]ed24fad2011-05-10 22:44:011116 return allow;
1117}
1118
[email protected]d5a19162011-06-30 18:51:541119bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201120 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201122 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431123 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1124 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261125
[email protected]bf510ed2012-06-05 08:31:431126 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1127 // Could we even support per-origin settings?
1128 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541129}
1130
[email protected]5c5a88e2011-11-12 00:45:351131bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351132 const GURL& url,
1133 const string16& name,
1134 const string16& display_name,
1135 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201136 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481137 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201139 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351140 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1141 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1142
[email protected]62151052012-02-01 18:40:481143 // Record access to database for potential display in UI.
1144 std::vector<std::pair<int, int> >::const_iterator i;
1145 for (i = render_views.begin(); i != render_views.end(); ++i) {
1146 BrowserThread::PostTask(
1147 BrowserThread::UI, FROM_HERE,
1148 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1149 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351150 }
1151
1152 return allow;
1153}
1154
1155bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351156 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201157 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481158 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201160 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351161 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1162 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1163
[email protected]62151052012-02-01 18:40:481164 // Record access to file system for potential display in UI.
1165 std::vector<std::pair<int, int> >::const_iterator i;
1166 for (i = render_views.begin(); i != render_views.end(); ++i) {
1167 BrowserThread::PostTask(
1168 BrowserThread::UI, FROM_HERE,
1169 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1170 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351171 }
1172
1173 return allow;
1174}
1175
[email protected]7c5ff9a2012-03-02 07:42:491176bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1177 const GURL& url,
1178 const string16& name,
1179 content::ResourceContext* context,
1180 const std::vector<std::pair<int, int> >& render_views) {
1181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1182 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1183 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1184 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1185
1186 // Record access to IndexedDB for potential display in UI.
1187 std::vector<std::pair<int, int> >::const_iterator i;
1188 for (i = render_views.begin(); i != render_views.end(); ++i) {
1189 BrowserThread::PostTask(
1190 BrowserThread::UI, FROM_HERE,
1191 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1192 i->first, i->second, url, name, !allow));
1193 }
1194
1195 return allow;
1196}
1197
[email protected]6133f922011-07-01 21:34:341198net::URLRequestContext*
1199ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201200 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421202 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201203 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341204 return io_data->extensions_request_context();
1205 }
1206
1207 return NULL;
1208}
1209
[email protected]317f96c92011-05-31 06:53:411210QuotaPermissionContext*
1211ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1212 return new ChromeQuotaPermissionContext();
1213}
1214
[email protected]848dd042011-06-04 18:24:031215void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171216 int render_process_id,
1217 int render_view_id,
1218 int cert_error,
1219 const net::SSLInfo& ssl_info,
1220 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031221 bool overridable,
[email protected]d9be47702012-05-16 03:41:221222 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171223 const base::Callback<void(bool)>& callback,
1224 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411225 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131226 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171227 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411228 if (!tab) {
1229 NOTREACHED();
1230 return;
1231 }
1232 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501233 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301234 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011235 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1236 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411237 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171238 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411239 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171240 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411241 return;
1242 }
1243 }
1244
[email protected]1e87df32012-09-12 04:53:191245#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231246 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1247 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1248 if (captive_portal_tab_helper)
1249 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191250#endif
1251
[email protected]f9034cf2011-07-21 12:43:411252 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221253 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1254 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031255}
1256
[email protected]c99c442e2011-08-24 11:37:301257void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451258 int render_process_id,
1259 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401260 const net::HttpNetworkSession* network_session,
1261 net::SSLCertRequestInfo* cert_request_info,
1262 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131263 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451264 render_process_id, render_view_id);
1265 if (!tab) {
1266 NOTREACHED();
1267 return;
1268 }
1269
[email protected]6786bf402011-12-03 15:19:451270 GURL requesting_url("https://" + cert_request_info->host_and_port);
1271 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1272 << cert_request_info->host_and_port;
1273
[email protected]627e0512011-12-21 22:55:301274 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451275 scoped_ptr<Value> filter(
1276 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1277 requesting_url,
1278 requesting_url,
1279 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1280 std::string(), NULL));
1281
1282 if (filter.get()) {
1283 // Try to automatically select a client certificate.
1284 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1285 DictionaryValue* filter_dict =
1286 static_cast<DictionaryValue*>(filter.get());
1287
1288 const std::vector<scoped_refptr<net::X509Certificate> >&
1289 all_client_certs = cert_request_info->client_certs;
1290 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1291 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1292 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401293 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451294 return;
1295 }
1296 }
1297 } else {
1298 NOTREACHED();
1299 }
1300 }
1301
[email protected]11feec322012-09-18 03:58:521302 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1303 if (!ssl_tab_helper) {
1304 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451305 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141306 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401307 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451308 return;
1309 }
[email protected]11feec322012-09-18 03:58:521310 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401311 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451312}
1313
[email protected]3b455502012-12-11 18:22:581314void ChromeContentBrowserClient::AddCertificate(
[email protected]8ec26472011-06-06 16:52:451315 net::URLRequest* request,
[email protected]3b455502012-12-11 18:22:581316 net::CertificateMimeType cert_type,
1317 const void* cert_data,
1318 size_t cert_size,
[email protected]8ec26472011-06-06 16:52:451319 int render_process_id,
1320 int render_view_id) {
[email protected]3b455502012-12-11 18:22:581321 chrome::SSLAddCertificate(request, cert_type, cert_data, cert_size,
1322 render_process_id, render_view_id);
[email protected]8ec26472011-06-06 16:52:451323}
1324
[email protected]dc73a7b2012-03-25 15:27:181325content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1326 return MediaInternals::GetInstance();
1327}
1328
[email protected]94fb5102013-01-23 09:00:471329content::WebRTCInternals* ChromeContentBrowserClient::GetWebRTCInternals() {
1330 return ChromeWebRTCInternals::GetInstance();
1331}
1332
[email protected]941623e2011-06-07 23:06:041333void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1334 const GURL& source_origin,
1335 int callback_context,
1336 int render_process_id,
1337 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111338#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1340 WebContents* contents =
1341 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1342 if (!contents) {
[email protected]941623e2011-06-07 23:06:041343 NOTREACHED();
1344 return;
1345 }
1346
[email protected]d0d9c3ee2012-06-19 03:07:021347 // Skip showing the infobar if the request comes from an extension, and that
1348 // extension has the 'notify' permission. (If the extension does not have the
1349 // permission, the user will still be prompted.)
1350 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
[email protected]06bdd2b2012-11-30 18:47:131351 ExtensionService* service =
1352 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]d0d9c3ee2012-06-19 03:07:021353 const Extension* extension = !service ? NULL :
1354 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1355 source_origin));
[email protected]eb4832a2012-12-08 01:57:521356 RenderViewHost* rvh =
1357 RenderViewHost::FromID(render_process_id, render_view_id);
1358 if (IsExtensionWithPermissionOrSuggestInConsole(
1359 APIPermission::kNotification, extension, rvh)) {
[email protected]d0d9c3ee2012-06-19 03:07:021360 if (rvh)
1361 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1362 return;
1363 }
1364
1365 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371366 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021367 notifications->RequestPermission(source_origin, render_process_id,
1368 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111369#else
1370 NOTIMPLEMENTED();
1371#endif
[email protected]941623e2011-06-07 23:06:041372}
1373
1374WebKit::WebNotificationPresenter::Permission
1375 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021376 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201377 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021378 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111379#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201381 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021382 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1383 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061384 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041385 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041386
1387 // Fall back to the regular notification preferences, which works on an
1388 // origin basis.
1389 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371390 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041391 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111392#else
1393 return WebKit::WebNotificationPresenter::PermissionAllowed;
1394#endif
[email protected]941623e2011-06-07 23:06:041395}
1396
1397void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171398 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041399 int render_process_id,
1400 int render_view_id,
1401 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111402#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041403 RenderViewHost* rvh = RenderViewHost::FromID(
1404 render_process_id, render_view_id);
1405 if (!rvh) {
1406 NOTREACHED();
1407 return;
1408 }
1409
[email protected]9f76c1e2012-03-05 15:15:581410 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301411 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041412 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371413 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041414 service->ShowDesktopNotification(
1415 params, render_process_id, render_view_id,
1416 worker ? DesktopNotificationService::WorkerNotification :
1417 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111418#else
1419 NOTIMPLEMENTED();
1420#endif
[email protected]941623e2011-06-07 23:06:041421}
1422
1423void ChromeContentBrowserClient::CancelDesktopNotification(
1424 int render_process_id,
1425 int render_view_id,
1426 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111427#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041428 RenderViewHost* rvh = RenderViewHost::FromID(
1429 render_process_id, render_view_id);
1430 if (!rvh) {
1431 NOTREACHED();
1432 return;
1433 }
1434
[email protected]9f76c1e2012-03-05 15:15:581435 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301436 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041437 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371438 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041439 service->CancelDesktopNotification(
1440 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111441#else
1442 NOTIMPLEMENTED();
1443#endif
[email protected]941623e2011-06-07 23:06:041444}
1445
[email protected]9f3fba52011-06-08 20:37:191446bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351447 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021448 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191449 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201450 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011451 int render_process_id,
1452 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011454
1455 *no_javascript_access = false;
1456
[email protected]9f3fba52011-06-08 20:37:191457 // If the opener is trying to create a background window but doesn't have
1458 // the appropriate permission, fail the attempt.
1459 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201460 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531461 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1462
[email protected]03b6d552012-03-29 04:03:011463 if (!map->SecurityOriginHasAPIPermission(
1464 source_origin,
1465 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061466 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011467 return false;
1468 }
1469
[email protected]7b54ca02012-03-02 18:06:531470 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1471 // return a recently installed Extension even if this CanCreateWindow call
1472 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011473 // because the permission check above would have caused an early return
1474 // already. We must use the full URL to find hosted apps, though, and not
1475 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531476 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351477 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531478 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011479 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191480 }
1481 return true;
1482}
1483
1484std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201485 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1487 // Check if it's an extension-created worker, in which case we want to use
1488 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201489 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191490 const Extension* extension =
1491 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1492 return extension ? extension->name() : std::string();
1493}
1494
[email protected]99907362012-01-11 05:41:401495void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1496 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171497}
1498
[email protected]c52b2892012-03-07 11:01:021499content::SpeechRecognitionManagerDelegate*
1500 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321501#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021502 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321503#else
1504 return NULL;
1505#endif
[email protected]66cfec62012-02-24 17:57:511506}
1507
[email protected]ae6e9912011-07-27 01:18:281508net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1509 return g_browser_process->net_log();
1510}
1511
[email protected]32538d92011-08-25 00:09:231512AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1513 return new ChromeAccessTokenStore();
1514}
1515
[email protected]dbae6b02011-06-29 23:51:411516bool ChromeContentBrowserClient::IsFastShutdownPossible() {
[email protected]263ff4f2013-01-04 20:23:011517 return true;
[email protected]dbae6b02011-06-29 23:51:411518}
1519
[email protected]64d69de42012-02-06 00:19:541520void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321521 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061522 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581523 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061524 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061525
[email protected]f3986f82012-01-03 20:00:061526 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541527 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061528 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541529 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061530 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541531 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061532 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541533 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061534 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541535 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061536 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541537 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031538 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1539 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061540
[email protected]64d69de42012-02-06 00:19:541541 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401542 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541543 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401544 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541545 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401546 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541547 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401548 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061549
[email protected]ddf72142012-05-22 04:52:401550 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061551
[email protected]64d69de42012-02-06 00:19:541552 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401553 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541554 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061555 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541556 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061557 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1558 const DictionaryValue* inspector_settings =
1559 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1560 if (inspector_settings) {
1561 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1562 iter != inspector_settings->end_keys(); ++iter) {
1563 std::string value;
1564 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541565 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061566 std::make_pair(*iter, value));
1567 }
1568 }
[email protected]64d69de42012-02-06 00:19:541569 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061570
[email protected]ddf72142012-05-22 04:52:401571 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541572 web_prefs->javascript_enabled = false;
1573 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1574 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401575 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541576 web_prefs->plugins_enabled = false;
1577 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1578 web_prefs->java_enabled = false;
1579 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401580 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061581
[email protected]64d69de42012-02-06 00:19:541582 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1583 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061584
[email protected]64d69de42012-02-06 00:19:541585 web_prefs->memory_info_enabled =
1586 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1587 web_prefs->allow_displaying_insecure_content =
1588 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1589 web_prefs->allow_running_insecure_content =
1590 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321591#if defined(OS_ANDROID)
1592 web_prefs->font_scale_factor =
1593 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1594 web_prefs->force_enable_zoom =
1595 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
1596#endif
[email protected]9d06d88d2012-02-23 22:37:081597 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061598
[email protected]64d69de42012-02-06 00:19:541599 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151600 UserStyleSheetWatcher* user_style_sheet_watcher =
1601 UserStyleSheetWatcherFactory::GetForProfile(profile);
1602 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541603 web_prefs->user_style_sheet_enabled = true;
1604 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151605 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541606 } else {
1607 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061608 }
1609
[email protected]b7e44ff2012-02-16 03:37:341610 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101611#if defined(OS_MACOSX)
[email protected]325342e62013-01-09 02:29:031612 // TODO(groby): Bug 107371: Implement asynchronous spellchecking API for
[email protected]37b928e2012-05-30 09:01:101613 // Mac so it uses NSSpellChecker in the background.
1614 false;
1615#else
[email protected]61806872012-12-12 04:15:361616 true;
[email protected]37b928e2012-05-30 09:01:101617#endif
[email protected]b7e44ff2012-02-16 03:37:341618 web_prefs->unified_textchecker_enabled =
[email protected]57890242012-10-23 17:46:521619 web_prefs->asynchronous_spell_checking_enabled;
[email protected]dd5d0fb2012-01-18 03:37:571620
[email protected]64d69de42012-02-06 00:19:541621 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061622 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541623 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061624 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541625 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061626 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1627
1628 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541629 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061630 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541631 web_prefs->default_encoding);
1632 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401633 prefs->ClearPref(prefs::kDefaultCharset);
1634 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061635 }
[email protected]64d69de42012-02-06 00:19:541636 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061637
[email protected]88ecf66d2012-12-11 22:53:471638 if (content::IsForceCompositingModeEnabled())
1639 web_prefs->force_compositing_mode = true;
1640
[email protected]299d7f12012-05-23 05:31:151641 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1642 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]06bdd2b2012-11-30 18:47:131643 ExtensionService* service =
1644 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]f3986f82012-01-03 20:00:061645 if (service) {
[email protected]1bc28312012-11-08 08:31:531646 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1647 const Extension* extension = service->extensions()->GetByID(url.host());
1648 // Ensure that we are only granting extension preferences to URLs with
1649 // the correct scheme. Without this check, chrome-guest:// schemes used by
1650 // webview tags as well as hosts that happen to match the id of an
1651 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421652 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531653 extension_webkit_preferences::SetPreferences(
1654 extension, view_type, web_prefs);
1655 }
[email protected]f3986f82012-01-03 20:00:061656 }
1657
[email protected]299d7f12012-05-23 05:31:151658 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541659 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151660 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061661 // Disable all kinds of acceleration for background pages.
1662 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541663 web_prefs->force_compositing_mode = false;
1664 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061665 }
[email protected]2e21fe292012-03-02 22:52:321666
1667#if defined(FILE_MANAGER_EXTENSION)
1668 // Override the default of suppressing HW compositing for WebUI pages for the
1669 // file manager, which is implemented using WebUI but wants HW acceleration
1670 // for video decode & render.
1671 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1672 web_prefs->accelerated_compositing_enabled = true;
1673 web_prefs->accelerated_2d_canvas_enabled = true;
1674 }
1675#endif
[email protected]181a95ee2011-07-12 19:26:361676}
1677
1678void ChromeContentBrowserClient::UpdateInspectorSetting(
1679 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061680 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581681 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061682 DictionaryPrefUpdate update(
1683 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1684 prefs::kWebKitInspectorSettings);
1685 DictionaryValue* inspector_settings = update.Get();
1686 inspector_settings->SetWithoutPathExpansion(key,
1687 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361688}
1689
1690void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061691 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581692 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061693 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1694 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361695}
1696
[email protected]b8148ac2011-07-13 22:03:251697void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1698 BrowserURLHandler* handler) {
1699 // Add the default URL handlers.
1700 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1701 BrowserURLHandler::null_handler());
1702 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1703 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1704
[email protected]b3adbd02011-11-30 22:23:271705 // about: handler. Must come before chrome: handler, since it will
1706 // rewrite about: urls to chrome: URLs and then expect chrome: to
1707 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251708 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1709 BrowserURLHandler::null_handler());
1710 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241711 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251712}
1713
1714void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371715 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581716 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471717 BrowsingDataRemover* remover =
1718 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551719 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1720 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251721 // BrowsingDataRemover takes care of deleting itself when done.
1722}
1723
1724void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371725 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581726 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471727 BrowsingDataRemover* remover =
1728 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231729 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551730 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251731 // BrowsingDataRemover takes care of deleting itself when done.
1732}
1733
[email protected]e1d16eb92011-08-18 23:19:321734FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1735 return download_util::GetDefaultDownloadDirectory();
1736}
1737
[email protected]c9b6eb62011-10-18 20:49:391738std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1739 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1740}
1741
[email protected]b7631cc2012-09-15 05:08:381742void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1743 content::BrowserPpapiHost* browser_host) {
[email protected]6d17f6392012-12-05 05:24:541744#if defined(ENABLE_PLUGINS)
[email protected]b7631cc2012-09-15 05:08:381745 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1746 scoped_ptr<ppapi::host::HostFactory>(
1747 new ChromeBrowserPepperHostFactory(browser_host)));
[email protected]6d17f6392012-12-05 05:24:541748#endif
[email protected]b7631cc2012-09-15 05:08:381749}
1750
[email protected]0c7193742012-11-07 19:05:031751content::BrowserPpapiHost*
1752 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
1753 int plugin_process_id) {
1754 BrowserChildProcessHostIterator iter(content::PROCESS_TYPE_NACL_LOADER);
1755 while (!iter.Done()) {
1756 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
1757 if (host->process() &&
1758 host->process()->GetData().id == plugin_process_id) {
1759 // Found the plugin.
1760 return host->browser_ppapi_host();
1761 }
1762 ++iter;
1763 }
1764 return NULL;
1765}
1766
[email protected]38cd8f7f2012-06-15 22:06:071767bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:581768 content::BrowserContext* browser_context,
1769 const GURL& url,
1770 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:291771 if (!url.is_valid())
1772 return false;
1773
1774 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:421775 if (url.SchemeIs(extensions::kExtensionScheme) &&
1776 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:291777 return true;
[email protected]885c0e92012-11-13 20:27:421778 }
[email protected]a658d452012-03-02 12:45:291779
[email protected]9a5940d2012-04-27 19:16:231780 Profile* profile = Profile::FromBrowserContext(browser_context);
1781 const Extension* extension = NULL;
[email protected]2ee3da9d62012-12-05 20:17:191782 ExtensionService* extension_service = !profile ? NULL :
[email protected]06bdd2b2012-11-30 18:47:131783 extensions::ExtensionSystem::Get(profile)->extension_service();
1784 if (extension_service) {
1785 extension = extension_service->extensions()->
[email protected]9a5940d2012-04-27 19:16:231786 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1787 }
1788
[email protected]f237c0f2012-03-10 07:49:101789 // Need to check this now and not on construction because otherwise it won't
1790 // work with browser_tests.
1791 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1792 std::string allowed_list =
1793 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231794 if (allowed_list == "*") {
1795 // The wildcard allows socket API only for packaged and platform apps.
1796 return extension &&
[email protected]c4f459d2012-09-28 04:40:101797 (extension->GetType() == Extension::TYPE_LEGACY_PACKAGED_APP ||
[email protected]9a5940d2012-04-27 19:16:231798 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1799 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101800 StringTokenizer t(allowed_list, ",");
1801 while (t.GetNext()) {
1802 if (t.token() == host)
1803 return true;
1804 }
1805 }
1806
[email protected]a658d452012-03-02 12:45:291807 if (!extension)
1808 return false;
1809
[email protected]157cc902012-11-02 06:31:581810 extensions::SocketPermission::CheckParam extension_params(
1811 params.type, params.host, params.port);
1812 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
1813 &extension_params))
[email protected]a658d452012-03-02 12:45:291814 return true;
1815
1816 return false;
[email protected]e461da2f2012-02-16 19:06:401817}
1818
[email protected]a7944aa2012-10-15 10:12:141819FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
1820 FilePath directory;
1821 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
1822 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
1823}
1824
[email protected]e60c0232011-11-11 19:56:351825#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:181826void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
1827 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:381828 int child_process_id,
[email protected]c7abd422012-09-25 00:20:081829 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:391830#if defined(OS_ANDROID)
1831 FilePath data_path;
1832 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
1833 DCHECK(!data_path.empty());
1834
1835 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
1836 FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
1837 base::PlatformFile f =
1838 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
1839 DCHECK(f != base::kInvalidPlatformFileValue);
1840 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
1841 FileDescriptor(f, true)));
1842
1843 FilePath chrome_resources_pak =
1844 data_path.AppendASCII("chrome_100_percent.pak");
1845 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
1846 DCHECK(f != base::kInvalidPlatformFileValue);
[email protected]73592382013-01-18 19:22:371847 mappings->push_back(FileDescriptorInfo(kAndroidChrome100PercentPakDescriptor,
[email protected]29699c22012-10-03 23:57:391848 FileDescriptor(f, true)));
1849
1850 const std::string locale = GetApplicationLocale();
1851 FilePath locale_pak = ResourceBundle::GetSharedInstance().
1852 GetLocaleFilePath(locale, false);
1853 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
1854 DCHECK(f != base::kInvalidPlatformFileValue);
1855 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
1856 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:381857
[email protected]73592382013-01-18 19:22:371858 FilePath resources_pack_path;
1859 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path);
1860 f = base::CreatePlatformFile(resources_pack_path, flags, NULL, NULL);
1861 DCHECK(f != base::kInvalidPlatformFileValue);
1862 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
1863 FileDescriptor(f, true)));
1864
[email protected]40da3e0c2012-10-24 22:03:381865#if defined(USE_LINUX_BREAKPAD)
[email protected]82174aa2013-01-22 21:53:431866 if (IsCrashReporterEnabled()) {
1867 f = CrashDumpManager::GetInstance()->CreateMinidumpFile(child_process_id);
1868 if (f == base::kInvalidPlatformFileValue) {
1869 LOG(ERROR) << "Failed to create file for minidump, crash reporting will "
1870 "be disabled for this process.";
1871 } else {
1872 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
1873 FileDescriptor(f, true)));
1874 }
[email protected]40da3e0c2012-10-24 22:03:381875 }
1876#endif // defined(USE_LINUX_BREAKPAD)
1877
1878#else
1879 int crash_signal_fd = GetCrashSignalFD(command_line);
1880 if (crash_signal_fd >= 0) {
1881 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
1882 FileDescriptor(crash_signal_fd,
1883 false)));
1884 }
[email protected]29699c22012-10-03 23:57:391885#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:301886}
[email protected]e60c0232011-11-11 19:56:351887#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301888
[email protected]4a65826d2011-08-25 16:04:011889#if defined(OS_WIN)
1890const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1891 return chrome::kBrowserResourcesDll;
1892}
1893#endif
1894
[email protected]37a72af2011-06-13 05:42:011895#if defined(USE_NSS)
1896crypto::CryptoModuleBlockingPasswordDelegate*
1897 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1898 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:291899 return chrome::NewCryptoModuleBlockingDialogDelegate(
1900 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:011901}
1902#endif
1903
[email protected]e9a32a52012-06-14 23:32:431904void ChromeContentBrowserClient::SetApplicationLocale(
1905 const std::string& locale) {
1906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1907
1908 // This object is guaranteed to outlive all threads so we don't have to
1909 // worry about the lack of refcounting and can just post as Unretained.
1910 //
1911 // The common case is that this function is called early in Chrome startup
1912 // before any threads are created (it will also be called later if the user
1913 // changes the pref). In this case, there will be no threads created and
1914 // posting will fail. When there are no threads, we can just set the string
1915 // without worrying about threadsafety.
1916 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1917 base::Bind(
1918 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
1919 base::Unretained(this), locale)))
1920 io_thread_application_locale_ = locale;
1921}
1922
1923void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1924 const std::string& locale) {
1925 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1926 io_thread_application_locale_ = locale;
1927}
1928
[email protected]d977f9c2011-03-14 16:10:261929} // namespace chrome