blob: cd5048a8ea4eb4818d9fdd23d217ff365a616363 [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]32538d92011-08-25 00:09:2339#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1240#include "chrome/browser/google/google_util.h"
[email protected]117b6b42012-02-29 09:11:0841#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]dc73a7b2012-03-25 15:27:1842#include "chrome/browser/media/media_internals.h"
[email protected]0c7193742012-11-07 19:05:0343#include "chrome/browser/nacl_host/nacl_process_host.h"
[email protected]ae6e9912011-07-27 01:18:2844#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0445#include "chrome/browser/notifications/desktop_notification_service.h"
46#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]e0ada9c2012-03-20 03:54:4347#include "chrome/browser/pepper_gtalk_message_filter.h"
[email protected]0609b17f2011-05-31 20:13:4248#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1249#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0650#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4151#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5052#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]2736c032012-05-11 18:06:0753#include "chrome/browser/prerender/prerender_message_filter.h"
[email protected]f9034cf2011-07-21 12:43:4154#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1455#include "chrome/browser/printing/printing_message_filter.h"
56#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3257#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0658#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1459#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3360#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]b7631cc2012-09-15 05:08:3861#include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h"
[email protected]8aa7a412011-11-07 12:33:4262#include "chrome/browser/renderer_host/plugin_info_message_filter.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]8ec26472011-06-06 16:52:4566#include "chrome/browser/ssl/ssl_add_cert_handler.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]871dc682012-06-11 19:35:3372#include "chrome/browser/ui/tab_contents/tab_contents.h"
[email protected]863f70a2012-01-27 02:05:5073#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0674#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1575#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]9ec0f452012-05-31 15:58:5376#include "chrome/browser/view_type_utils.h"
[email protected]b80f68432011-05-02 17:22:3077#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0178#include "chrome/common/chrome_constants.h"
[email protected]a7944aa2012-10-15 10:12:1479#include "chrome/common/chrome_paths.h"
[email protected]b80f68432011-05-02 17:22:3080#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0481#include "chrome/common/extensions/extension.h"
[email protected]395045c2012-05-22 15:04:3882#include "chrome/common/extensions/extension_process_policy.h"
[email protected]615d88f2011-12-13 01:47:4483#include "chrome/common/extensions/extension_set.h"
[email protected]157cc902012-11-02 06:31:5884#include "chrome/common/extensions/permissions/socket_permission.h"
[email protected]f1933792011-06-14 00:49:3485#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1286#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3887#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0988#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4389#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3090#include "content/public/browser/browser_main_parts.h"
[email protected]b7631cc2012-09-15 05:08:3891#include "content/public/browser/browser_ppapi_host.h"
[email protected]825b1662012-03-12 19:07:3192#include "content/public/browser/browser_url_handler.h"
[email protected]0c7193742012-11-07 19:05:0393#include "content/public/browser/child_process_data.h"
[email protected]b9535422012-02-09 01:47:5994#include "content/public/browser/child_process_security_policy.h"
[email protected]cb6430932012-10-31 00:53:3695#include "content/public/browser/compositor_util.h"
[email protected]f3b1a082011-11-18 00:34:3096#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3397#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0598#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3399#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:19100#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:10101#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:43102#include "content/public/common/child_process_host.h"
[email protected]a1733df2012-06-22 11:24:18103#include "content/public/common/content_descriptors.h"
[email protected]885c0e92012-11-13 20:27:42104#include "extensions/common/constants.h"
[email protected]c9b6eb62011-10-18 20:49:39105#include "grit/generated_resources.h"
[email protected]2a281332012-07-11 22:20:23106#include "grit/ui_resources.h"
[email protected]1bc28312012-11-08 08:31:53107#include "net/base/escape.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
184 "jdfhpkjeckflbbleddjlpimecpbjdeep" // see crbug.com/142514
[email protected]e461da2f2012-02-16 19:06:40185};
186
[email protected]f8f93eb2012-09-25 03:06:24187// Returns a copy of the given url with its host set to given host and path set
188// to given path. Other parts of the url will be the same.
189GURL ReplaceURLHostAndPath(const GURL& url,
190 const std::string& host,
191 const std::string& path) {
192 url_canon::Replacements<char> replacements;
193 replacements.SetHost(host.c_str(),
194 url_parse::Component(0, host.length()));
195 replacements.SetPath(path.c_str(),
196 url_parse::Component(0, path.length()));
197 return url.ReplaceComponents(replacements);
198}
199
200// Maps "foo://bar/baz/" to "foo://chrome/bar/baz/".
201GURL AddUberHost(const GURL& url) {
202 const std::string uber_host = chrome::kChromeUIUberHost;
203 const std::string new_path = url.host() + url.path();
204
205 return ReplaceURLHostAndPath(url, uber_host, new_path);
206}
207
[email protected]045bf7c2012-09-28 20:27:36208// If url->host() is "chrome" and url->path() has characters other than the
209// first slash, changes the url from "foo://chrome/bar/" to "foo://bar/" and
210// returns true. Otherwise returns false.
[email protected]f8f93eb2012-09-25 03:06:24211bool RemoveUberHost(GURL* url) {
212 if (url->host() != chrome::kChromeUIUberHost)
213 return false;
214
[email protected]045bf7c2012-09-28 20:27:36215 if (url->path().empty() || url->path() == "/")
216 return false;
217
[email protected]f8f93eb2012-09-25 03:06:24218 const std::string old_path = url->path();
219
220 const std::string::size_type separator = old_path.find('/', 1);
221 std::string new_host;
222 std::string new_path;
223 if (separator == std::string::npos) {
[email protected]045bf7c2012-09-28 20:27:36224 new_host = old_path.substr(1);
[email protected]f8f93eb2012-09-25 03:06:24225 } else {
226 new_host = old_path.substr(1, separator - 1);
227 new_path = old_path.substr(separator);
228 }
229
230 *url = ReplaceURLHostAndPath(*url, new_host, new_path);
231
232 return true;
233}
234
[email protected]b8148ac2011-07-13 22:03:25235// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42236bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]f8f93eb2012-09-25 03:06:24237 // Do not handle special URLs such as "about:foo"
238 if (!url->host().empty()) {
239 const GURL chrome_url = AddUberHost(*url);
240
241 // Handle valid "chrome://chrome/foo" URLs so the reverse handler will
242 // be called.
243 if (ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
244 browser_context, chrome_url))
245 return true;
246 }
247
[email protected]863f70a2012-01-27 02:05:50248 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
249 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25250 return false;
251
[email protected]fe69558d2012-03-12 11:34:49252#if defined(OS_CHROMEOS)
253 // Special case : in ChromeOS in Guest mode bookmarks and history are
254 // disabled for security reasons. New tab page explains the reasons, so
255 // we redirect user to new tab page.
256 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
257 if (url->SchemeIs(chrome::kChromeUIScheme) &&
258 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
259 url->DomainIs(chrome::kChromeUIHistoryHost))) {
260 // Rewrite with new tab URL
261 *url = GURL(chrome::kChromeUINewTabURL);
262 }
263 }
264#endif
265
[email protected]b8148ac2011-07-13 22:03:25266 // Special case the new tab page. In older versions of Chrome, the new tab
267 // page was hosted at chrome-internal:<blah>. This might be in people's saved
268 // sessions or bookmarks, so we say any URL with that scheme triggers the new
269 // tab page.
270 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
271 // Rewrite it with the proper new tab URL.
272 *url = GURL(chrome::kChromeUINewTabURL);
273 }
274
275 return true;
276}
277
[email protected]f8f93eb2012-09-25 03:06:24278// Reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to
279// "chrome://foo/".
280bool HandleWebUIReverse(GURL* url, content::BrowserContext* browser_context) {
281 if (!url->is_valid() || !url->SchemeIs(chrome::kChromeUIScheme))
282 return false;
283
284 return RemoveUberHost(url);
285}
286
[email protected]8d3132f62011-10-12 07:13:42287// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
288// below. Extension, and isolated apps require different privileges to be
289// granted to their RenderProcessHosts. This classification allows us to make
290// sure URLs are served by hosts with the right set of privileges.
291enum RenderProcessHostPrivilege {
292 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45293 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42294 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45295 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42296};
297
298RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
299 const GURL& url,
300 ExtensionService* service) {
301 // Default to a normal renderer cause it is lower privileged. This should only
302 // occur if the URL on a site instance is either malformed, or uninitialized.
303 // If it is malformed, then there is no need for better privileges anyways.
304 // If it is uninitialized, but eventually settles on being an a scheme other
305 // than normal webrenderer, the navigation logic will correct us out of band
306 // anyways.
307 if (!url.is_valid())
308 return PRIV_NORMAL;
309
[email protected]885c0e92012-11-13 20:27:42310 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44311 const Extension* extension =
312 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45313 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42314 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45315 if (extension && extension->is_hosted_app())
316 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42317
318 return PRIV_EXTENSION;
319 }
320
321 return PRIV_NORMAL;
322}
323
324RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30325 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46326 extensions::ProcessMap* process_map,
327 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46328 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30329 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46330 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21331 return PRIV_NORMAL;
332
[email protected]6f371442011-11-09 06:45:46333 for (std::set<std::string>::iterator iter = extension_ids.begin();
334 iter != extension_ids.end(); ++iter) {
335 const Extension* extension = service->GetExtensionById(*iter, false);
336 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42337 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45338 if (extension && extension->is_hosted_app())
339 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42340 }
341
[email protected]676f6ab2011-10-19 20:23:21342 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42343}
344
[email protected]6786bf402011-12-03 15:19:45345bool CertMatchesFilter(const net::X509Certificate& cert,
346 const base::DictionaryValue& filter) {
347 // TODO(markusheintz): This is the minimal required filter implementation.
348 // Implement a better matcher.
349
350 // An empty filter matches any client certificate since no requirements are
351 // specified at all.
352 if (filter.empty())
353 return true;
354
355 std::string common_name;
356 if (filter.GetString("ISSUER.CN", &common_name) &&
357 (cert.issuer().common_name == common_name)) {
358 return true;
359 }
360 return false;
361}
362
[email protected]f3986f82012-01-03 20:00:06363// Fills |map| with the per-script font prefs under path |map_name|.
364void FillFontFamilyMap(const PrefService* prefs,
365 const char* map_name,
366 WebPreferences::ScriptFontFamilyMap* map) {
367 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
368 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
369 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
370 std::string font_family = prefs->GetString(pref_name.c_str());
[email protected]d0471062012-10-26 09:00:23371 if (!font_family.empty())
372 (*map)[script] = UTF8ToUTF16(font_family);
[email protected]f3986f82012-01-03 20:00:06373 }
374}
375
[email protected]a1733df2012-06-22 11:24:18376#if defined(OS_POSIX) && !defined(OS_MACOSX)
377int GetCrashSignalFD(const CommandLine& command_line) {
378 if (command_line.HasSwitch(switches::kExtensionProcess)) {
379 ExtensionCrashHandlerHostLinux* crash_handler =
380 ExtensionCrashHandlerHostLinux::GetInstance();
381 return crash_handler->GetDeathSignalSocket();
382 }
383
384 std::string process_type =
385 command_line.GetSwitchValueASCII(switches::kProcessType);
386
387 if (process_type == switches::kRendererProcess)
388 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
389
390 if (process_type == switches::kPluginProcess)
391 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
392
393 if (process_type == switches::kPpapiPluginProcess)
394 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
395
396 if (process_type == switches::kGpuProcess)
397 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
398
399 return -1;
400}
401#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
402
[email protected]9dbfff12011-07-01 19:37:07403} // namespace
[email protected]c5dbef02011-05-13 05:06:09404
[email protected]d977f9c2011-03-14 16:10:26405namespace chrome {
406
[email protected]e461da2f2012-02-16 19:06:40407ChromeContentBrowserClient::ChromeContentBrowserClient() {
408 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
409 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40410}
411
412ChromeContentBrowserClient::~ChromeContentBrowserClient() {
413}
414
[email protected]bca18382012-06-25 19:15:23415// static
416void ChromeContentBrowserClient::RegisterUserPrefs(PrefService* prefs) {
417 prefs->RegisterBooleanPref(prefs::kDisable3DAPIs,
418 false,
419 PrefService::UNSYNCABLE_PREF);
420 prefs->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing,
421 true,
422 PrefService::UNSYNCABLE_PREF);
423 prefs->RegisterBooleanPref(prefs::kEnableMemoryInfo,
424 false,
425 PrefService::UNSYNCABLE_PREF);
426}
427
[email protected]50462bf02011-11-21 19:13:31428content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
429 const content::MainFunctionParams& parameters) {
430 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30431 // Construct the Main browser parts based on the OS type.
432#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31433 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04434#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31435 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30436#elif defined(OS_CHROMEOS)
[email protected]2c624d02012-11-15 19:37:22437 main_parts = new chromeos::ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26438#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31439 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14440#elif defined(OS_ANDROID)
[email protected]81054f812012-08-30 00:47:09441 main_parts = new ChromeBrowserMainPartsAndroid(parameters);
[email protected]b48c9182011-10-26 18:03:30442#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31443 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04444#else
[email protected]b48c9182011-10-26 18:03:30445 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31446 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30447#endif
448
[email protected]c7480942011-11-08 19:18:27449 // Construct additional browser parts. Stages are called in the order in
450 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22451#if defined(TOOLKIT_GTK)
[email protected]684dace42012-07-01 14:30:41452 chrome::AddGtkToolkitExtraParts(main_parts);
[email protected]f967b722011-09-07 00:58:04453#endif
[email protected]c7480942011-11-08 19:18:27454
455#if defined(TOOLKIT_VIEWS)
[email protected]684dace42012-07-01 14:30:41456 chrome::AddViewsToolkitExtraParts(main_parts);
[email protected]c7480942011-11-08 19:18:27457#endif
458
[email protected]dc04be7c2012-03-15 23:57:49459#if defined(USE_ASH)
[email protected]684dace42012-07-01 14:30:41460 chrome::AddAshToolkitExtraParts(main_parts);
[email protected]dc04be7c2012-03-15 23:57:49461#endif
462
[email protected]e050ef142012-03-21 01:04:24463#if defined(USE_AURA)
[email protected]684dace42012-07-01 14:30:41464 chrome::AddAuraToolkitExtraParts(main_parts);
[email protected]e050ef142012-03-21 01:04:24465#endif
466
[email protected]50462bf02011-11-21 19:13:31467 return main_parts;
[email protected]f967b722011-09-07 00:58:04468}
469
[email protected]38b098f2012-03-14 21:11:57470content::WebContentsView*
471 ChromeContentBrowserClient::OverrideCreateWebContentsView(
[email protected]5a3bdf52012-05-24 15:12:57472 WebContents* web_contents,
473 content::RenderViewHostDelegateView** render_view_host_delegate_view) {
[email protected]38b098f2012-03-14 21:11:57474 return NULL;
475}
476
[email protected]e94bbcb2012-09-07 05:33:57477std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite(
[email protected]d1198fd2012-08-13 22:50:19478 content::BrowserContext* browser_context,
[email protected]e94bbcb2012-09-07 05:33:57479 const GURL& site) {
[email protected]1bc28312012-11-08 08:31:53480 std::string partition_id;
481
482 // The partition ID for webview guest processes is the string value of its
483 // SiteInstance URL - "chrome-guest://app_id/persist?partition".
484 if (site.SchemeIs(chrome::kGuestScheme))
485 partition_id = site.spec();
486
487 DCHECK(IsValidStoragePartitionId(browser_context,partition_id));
488 return partition_id;
489}
490
491bool ChromeContentBrowserClient::IsValidStoragePartitionId(
492 content::BrowserContext* browser_context,
493 const std::string& partition_id) {
494 // The default ID is empty and is always valid.
495 if (partition_id.empty())
496 return true;
497
498 return GURL(partition_id).is_valid();
499}
500
501void ChromeContentBrowserClient::GetStoragePartitionConfigForSite(
502 content::BrowserContext* browser_context,
503 const GURL& site,
[email protected]14acc642012-11-17 12:20:10504 bool can_be_default,
[email protected]1bc28312012-11-08 08:31:53505 std::string* partition_domain,
506 std::string* partition_name,
507 bool* in_memory) {
[email protected]14acc642012-11-17 12:20:10508 // Default to the browser-wide storage partition and override based on |site|
509 // below.
510 partition_domain->clear();
511 partition_name->clear();
512 *in_memory = false;
513
[email protected]1bc28312012-11-08 08:31:53514 // For the webview tag, we create special guest processes, which host the
515 // tag content separately from the main application that embeds the tag.
516 // A webview tag can specify both the partition name and whether the storage
517 // for that partition should be persisted. Each tag gets a SiteInstance with
518 // a specially formatted URL, based on the application it is hosted by and
519 // the partition requested by it. The format for that URL is:
520 // chrome-guest://partition_domain/persist?partition_name
521 if (site.SchemeIs(chrome::kGuestScheme)) {
522 // Since guest URLs are only used for packaged apps, there must be an app
523 // id in the URL.
524 CHECK(site.has_host());
525 *partition_domain = site.host();
526 // Since persistence is optional, the path must either be empty or the
527 // literal string.
528 *in_memory = (site.path() != "/persist");
529 // The partition name is user supplied value, which we have encoded when the
530 // URL was created, so it needs to be decoded.
531 *partition_name = net::UnescapeURLComponent(site.query(),
532 net::UnescapeRule::NORMAL);
[email protected]14acc642012-11-17 12:20:10533 } else if (site.SchemeIs(extensions::kExtensionScheme)) {
534 // If |can_be_default| is false, the caller is stating that the |site|
535 // should be parsed as if it had isolated storage. In particular it is
536 // important to NOT check ExtensionService for the is_storage_isolated()
537 // attribute because this code path is run during Extension uninstall
538 // to do cleanup after the Extension has already been unloaded from the
539 // ExtensionService.
540 bool is_isolated = !can_be_default;
541 if (can_be_default) {
542 const Extension* extension = NULL;
543 Profile* profile = Profile::FromBrowserContext(browser_context);
544 ExtensionService* extension_service =
545 extensions::ExtensionSystem::Get(profile)->extension_service();
546 if (extension_service) {
547 extension = extension_service->extensions()->
548 GetExtensionOrAppByURL(ExtensionURLInfo(site));
549 if (extension && extension->is_storage_isolated()) {
550 is_isolated = true;
551 }
552 }
553 }
[email protected]1bc28312012-11-08 08:31:53554
[email protected]14acc642012-11-17 12:20:10555 if (is_isolated) {
556 CHECK(site.has_host());
557 // For extensions with isolated storage, the the host of the |site| is
558 // the |partition_domain|. The |in_memory| and |partition_name| are only
559 // used in guest schemes so they are cleared here.
560 *partition_domain = site.host();
[email protected]1bc28312012-11-08 08:31:53561 *in_memory = false;
[email protected]14acc642012-11-17 12:20:10562 partition_name->clear();
[email protected]1bc28312012-11-08 08:31:53563 }
[email protected]d1198fd2012-08-13 22:50:19564 }
565
[email protected]14acc642012-11-17 12:20:10566 // Assert that if |can_be_default| is false, the code above must have found a
567 // non-default partition. If this fails, the caller has a serious logic
568 // error about which StoragePartition they expect to be in and it is not
569 // safe to continue.
570 CHECK(can_be_default || !partition_domain->empty());
[email protected]d7c7c98a2012-07-12 21:27:44571}
572
[email protected]38b098f2012-03-14 21:11:57573content::WebContentsViewDelegate*
574 ChromeContentBrowserClient::GetWebContentsViewDelegate(
575 content::WebContents* web_contents) {
[email protected]d33220292012-07-04 01:41:27576 return chrome::CreateWebContentsViewDelegate(web_contents);
[email protected]74313b42011-08-24 16:51:32577}
578
[email protected]f364d1392011-04-08 21:03:10579void ChromeContentBrowserClient::RenderViewHostCreated(
580 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46581
[email protected]9f76c1e2012-03-05 15:15:58582 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46583 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02584 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46585
586 new ChromeRenderViewHostObserver(render_view_host,
587 profile->GetNetworkPredictor());
[email protected]40404bc2012-07-25 17:40:49588 new extensions::MessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26589}
590
[email protected]f3b1a082011-11-18 00:34:30591void ChromeContentBrowserClient::RenderProcessHostCreated(
592 content::RenderProcessHost* host) {
593 int id = host->GetID();
594 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
595 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02596 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30597 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]658677f2012-06-09 06:04:02598#if defined(ENABLE_PRINTING)
[email protected]0045b0f42012-07-26 11:52:08599 host->GetChannel()->AddFilter(new PrintingMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03600#endif
[email protected]f3b1a082011-11-18 00:34:30601 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02602 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30603 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56604#if defined(OS_MACOSX)
605 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
606#endif
[email protected]f3b1a082011-11-18 00:34:30607 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03608 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]2736c032012-05-11 18:06:07609 host->GetChannel()->AddFilter(
610 new prerender::PrerenderMessageFilter(id, profile));
[email protected]3e69bc82011-05-26 23:22:38611
[email protected]2ccf45c2011-08-19 23:35:50612 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
613 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07614
615 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56616
617 RendererContentSettingRules rules;
618 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
619 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]40da3e0c2012-10-24 22:03:38620
621#if defined(OS_ANDROID) && defined(USE_LINUX_BREAKPAD)
622 InitCrashDumpManager();
623#endif
[email protected]05fcf982011-04-19 00:44:14624}
625
[email protected]e0ada9c2012-03-20 03:54:43626void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
627 content::BrowserChildProcessHost* host) {
628 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
629}
630
[email protected]863f70a2012-01-27 02:05:50631content::WebUIControllerFactory*
632 ChromeContentBrowserClient::GetWebUIControllerFactory() {
633 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56634}
635
[email protected]3d7474ff2011-07-27 17:47:37636GURL ChromeContentBrowserClient::GetEffectiveURL(
637 content::BrowserContext* browser_context, const GURL& url) {
638 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08639 // Get the effective URL for the given actual URL. If the URL is part of an
640 // installed app, the effective URL is an extension URL with the ID of that
641 // extension as the host. This has the effect of grouping apps together in
642 // a common SiteInstance.
643 if (!profile || !profile->GetExtensionService())
644 return url;
645
[email protected]615d88f2011-12-13 01:47:44646 const Extension* extension = profile->GetExtensionService()->extensions()->
647 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08648 if (!extension)
649 return url;
650
[email protected]15877ca2011-11-18 22:40:52651 // Bookmark apps do not use the hosted app process model, and should be
652 // treated as normal URLs.
653 if (extension->from_bookmark())
654 return url;
655
[email protected]36fb2c7c2011-04-04 15:49:08656 // If the URL is part of an extension's web extent, convert it to an
657 // extension URL.
658 return extension->GetResourceURL(url.path());
659}
660
[email protected]056ad2a2011-07-12 02:13:55661bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37662 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55663 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52664 // Because we expect to use the effective URL, URLs for hosted apps (apart
665 // from bookmark apps) should have an extension scheme by now.
[email protected]885c0e92012-11-13 20:27:42666 if (!effective_url.SchemeIs(extensions::kExtensionScheme))
[email protected]056ad2a2011-07-12 02:13:55667 return false;
668
[email protected]3d7474ff2011-07-27 17:47:37669 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55670 if (!profile || !profile->GetExtensionService())
671 return false;
672
[email protected]615d88f2011-12-13 01:47:44673 const Extension* extension = profile->GetExtensionService()->extensions()->
674 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55675 if (!extension)
676 return false;
677
678 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53679 // permission, or that does not allow JavaScript access to the background
680 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55681 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53682 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
[email protected]c2e66e12012-06-27 06:27:06683 if (!extension->HasAPIPermission(APIPermission::kBackground) ||
[email protected]7b54ca02012-03-02 18:06:53684 !extension->allow_background_js_access()) {
685 return false;
686 }
687 }
[email protected]056ad2a2011-07-12 02:13:55688
[email protected]7b54ca02012-03-02 18:06:53689 // Hosted apps that have script access to their background page must use
690 // process per site, since all instances can make synchronous calls to the
691 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55692 return true;
693}
694
[email protected]46fb9442011-12-09 17:57:47695bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
696 return ProfileIOData::IsHandledURL(url);
697}
698
[email protected]2a5221b2011-09-27 23:07:31699bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30700 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31701 const GURL& site_url) {
702 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30703 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42704 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46705 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31706
[email protected]ffa97602011-11-17 17:55:52707 // Don't allow the Task Manager to share a process with anything else.
708 // Otherwise it can affect the renderers it is observing.
709 // Note: we could create another RenderProcessHostPrivilege bucket for
710 // this to allow multiple chrome://tasks instances to share, but that's
711 // a very unlikely case without serious consequences.
712 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
713 return false;
714
[email protected]8d3132f62011-10-12 07:13:42715 // These may be NULL during tests. In that case, just assume any site can
716 // share any host.
[email protected]6f371442011-11-09 06:45:46717 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31718 return true;
719
[email protected]a8c269a2011-10-25 20:17:22720 // Experimental:
[email protected]c6f2e672012-11-15 01:47:02721 // If --enable-strict-site-isolation or --site-per-process is enabled, do not
722 // allow non-WebUI pages to share a renderer process. (We could allow pages
723 // from the same site or extensions of the same type to share, if we knew what
724 // the given process was dedicated to. Allowing no sharing is simpler for
725 // now.) This may cause resource exhaustion issues if too many sites are open
726 // at once.
[email protected]a8c269a2011-10-25 20:17:22727 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]c6f2e672012-11-15 01:47:02728 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) ||
729 command_line.HasSwitch(switches::kSitePerProcess))
[email protected]a8c269a2011-10-25 20:17:22730 return false;
731
[email protected]eec0b33c2011-12-05 22:09:45732 // Otherwise, just make sure the process privilege matches the privilege
733 // required by the site.
[email protected]e94bbcb2012-09-07 05:33:57734 RenderProcessHostPrivilege privilege_required =
735 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45736 return GetProcessPrivilege(process_host, process_map, service) ==
737 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31738}
739
[email protected]76411f412012-02-22 18:56:06740// This function is trying to limit the amount of processes used by extensions
741// with background pages. It uses a globally set percentage of processes to
742// run such extensions and if the limit is exceeded, it returns true, to
743// indicate to the content module to group extensions together.
744bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
745 content::BrowserContext* browser_context, const GURL& url) {
746 // It has to be a valid URL for us to check for an extension.
747 if (!url.is_valid())
748 return false;
749
750 Profile* profile = Profile::FromBrowserContext(browser_context);
751 ExtensionService* service = profile->GetExtensionService();
752 if (!service)
753 return false;
754
755 // We have to have a valid extension with background page to proceed.
756 const Extension* extension =
757 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
758 if (!extension)
759 return false;
760 if (!extension->has_background_page())
761 return false;
762
763 std::set<int> process_ids;
764 size_t max_process_count =
765 content::RenderProcessHost::GetMaxRendererProcessCount();
766
767 // Go through all profiles to ensure we have total count of extension
768 // processes containing background pages, otherwise one profile can
769 // starve the other.
770 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
771 GetLoadedProfiles();
772 for (size_t i = 0; i < profiles.size(); ++i) {
[email protected]be93bba02012-10-24 16:44:03773 ExtensionProcessManager* epm =
774 extensions::ExtensionSystem::Get(profiles[i])->process_manager();
[email protected]d1fe1352012-04-26 00:47:32775 for (ExtensionProcessManager::const_iterator iter =
776 epm->background_hosts().begin();
777 iter != epm->background_hosts().end(); ++iter) {
[email protected]3a1dc572012-07-31 22:25:13778 const extensions::ExtensionHost* host = *iter;
[email protected]d1fe1352012-04-26 00:47:32779 process_ids.insert(host->render_process_host()->GetID());
[email protected]76411f412012-02-22 18:56:06780 }
781 }
782
783 if (process_ids.size() >
784 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
785 return true;
786 }
787
788 return false;
789}
790
[email protected]6f371442011-11-09 06:45:46791void ChromeContentBrowserClient::SiteInstanceGotProcess(
792 SiteInstance* site_instance) {
793 CHECK(site_instance->HasProcess());
794
795 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02796 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46797 ExtensionService* service = profile->GetExtensionService();
798 if (!service)
799 return;
800
801 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44802 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]77ab17312012-09-28 15:34:59803 site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46804 if (!extension)
805 return;
806
[email protected]6bc04fd82011-12-04 02:29:35807 service->process_map()->Insert(extension->id(),
808 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33809 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46810 BrowserThread::PostTask(
811 BrowserThread::IO, FROM_HERE,
812 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59813 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46814 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35815 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33816 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46817}
818
819void ChromeContentBrowserClient::SiteInstanceDeleting(
820 SiteInstance* site_instance) {
821 if (!site_instance->HasProcess())
822 return;
823
824 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02825 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46826 ExtensionService* service = profile->GetExtensionService();
827 if (!service)
828 return;
829
830 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44831 service->extensions()->GetExtensionOrAppByURL(
[email protected]77ab17312012-09-28 15:34:59832 ExtensionURLInfo(site_instance->GetSiteURL()));
[email protected]6f371442011-11-09 06:45:46833 if (!extension)
834 return;
835
[email protected]6bc04fd82011-12-04 02:29:35836 service->process_map()->Remove(extension->id(),
837 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33838 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46839 BrowserThread::PostTask(
840 BrowserThread::IO, FROM_HERE,
841 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]bd306722012-07-11 20:43:59842 extensions::ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46843 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35844 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33845 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46846}
847
[email protected]f05763972012-06-06 18:17:26848bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
[email protected]e3daf3c2011-10-05 21:17:08849 const GURL& current_url,
850 const GURL& new_url) {
[email protected]f05763972012-06-06 18:17:26851 if (current_url.is_empty()) {
852 // Always choose a new process when navigating to extension URLs. The
853 // process grouping logic will combine all of a given extension's pages
854 // into the same process.
[email protected]885c0e92012-11-13 20:27:42855 if (new_url.SchemeIs(extensions::kExtensionScheme))
[email protected]f05763972012-06-06 18:17:26856 return true;
[email protected]e3daf3c2011-10-05 21:17:08857
[email protected]f05763972012-06-06 18:17:26858 return false;
859 }
860
861 // Also, we must switch if one is an extension and the other is not the exact
862 // same extension.
[email protected]885c0e92012-11-13 20:27:42863 if (current_url.SchemeIs(extensions::kExtensionScheme) ||
864 new_url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]f05763972012-06-06 18:17:26865 if (current_url.GetOrigin() != new_url.GetOrigin())
866 return true;
867 }
868
869 return false;
[email protected]e3daf3c2011-10-05 21:17:08870}
871
[email protected]395045c2012-05-22 15:04:38872bool ChromeContentBrowserClient::ShouldSwapProcessesForRedirect(
873 content::ResourceContext* resource_context, const GURL& current_url,
874 const GURL& new_url) {
875 ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
876 return extensions::CrossesExtensionProcessBoundary(
877 io_data->GetExtensionInfoMap()->extensions(),
[email protected]ea7b7d82012-05-25 17:29:17878 ExtensionURLInfo(current_url), ExtensionURLInfo(new_url), false);
[email protected]395045c2012-05-22 15:04:38879}
880
[email protected]763ec4ca2011-04-29 15:48:12881std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
882 const std::string& alias_name) {
883 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
884}
885
[email protected]b80f68432011-05-02 17:22:30886void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
887 CommandLine* command_line, int child_process_id) {
888#if defined(USE_LINUX_BREAKPAD)
889 if (IsCrashReporterEnabled()) {
890 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
891 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
892 }
893#elif defined(OS_MACOSX)
894 if (IsCrashReporterEnabled()) {
895 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
896 child_process_logging::GetClientId());
897 }
898#endif // OS_MACOSX
899
[email protected]f1933792011-06-14 00:49:34900 if (logging::DialogsAreSuppressed())
901 command_line->AppendSwitch(switches::kNoErrorDialogs);
902
[email protected]b80f68432011-05-02 17:22:30903 std::string process_type =
904 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17905 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52906 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30907 FilePath user_data_dir =
908 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
909 if (!user_data_dir.empty())
910 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
911#if defined(OS_CHROMEOS)
912 const std::string& login_profile =
913 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
914 if (!login_profile.empty())
915 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
916#endif
917
[email protected]f3b1a082011-11-18 00:34:30918 content::RenderProcessHost* process =
919 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37920 if (process) {
921 Profile* profile = Profile::FromBrowserContext(
922 process->GetBrowserContext());
[email protected]c8598d42012-09-25 21:17:00923 if (profile->GetExtensionService()) {
924 extensions::ProcessMap* process_map =
925 profile->GetExtensionService()->process_map();
926 if (process_map && process_map->Contains(process->GetID()))
927 command_line->AppendSwitch(switches::kExtensionProcess);
928 }
[email protected]b80f68432011-05-02 17:22:30929
[email protected]a8d851f82011-12-21 00:32:37930 PrefService* prefs = profile->GetPrefs();
931 // Currently this pref is only registered if applied via a policy.
932 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
933 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
934 // Turn this policy into a command line switch.
935 command_line->AppendSwitch(switches::kDisable3DAPIs);
936 }
[email protected]718eab62011-10-05 21:16:52937
[email protected]a8d851f82011-12-21 00:32:37938 // Disable client-side phishing detection in the renderer if it is
939 // disabled in the Profile preferences or the browser process.
940 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
941 !g_browser_process->safe_browsing_detection_service()) {
942 command_line->AppendSwitch(
943 switches::kDisableClientSidePhishingDetection);
944 }
[email protected]0045b0f42012-07-26 11:52:08945
946 if (!prefs->GetBoolean(prefs::kPrintPreviewDisabled))
[email protected]47c7ec82012-01-18 03:29:21947 command_line->AppendSwitch(switches::kRendererPrintPreview);
[email protected]47c7ec82012-01-18 03:29:21948 }
[email protected]4287a3d2011-06-13 23:56:51949
[email protected]87552982012-11-02 17:21:40950 if (content::IsThreadedCompositingEnabled())
951 command_line->AppendSwitch(switches::kEnableThreadedCompositing);
952
[email protected]47c7ec82012-01-18 03:29:21953 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51954 static const char* const kSwitchNames[] = {
955 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48956 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51957 switches::kAllowScriptingGallery,
958 switches::kAppsCheckoutURL,
959 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31960 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51961 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50962 switches::kDisableBundledPpapiFlash,
[email protected]e9dfe222012-05-11 22:05:53963 switches::kDisableExtensionsResourceWhitelist,
[email protected]b0553c7e2012-09-19 21:36:11964 switches::kDisableScriptedPrintThrottling,
[email protected]4287a3d2011-06-13 23:56:51965 switches::kDumpHistogramsOnExit,
[email protected]47c7ec82012-01-18 03:29:21966 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13967 switches::kEnableBundledPpapiFlash,
[email protected]4e7d1a22012-11-06 13:57:03968 switches::kEnableChromeStyleDialogs,
[email protected]4287a3d2011-06-13 23:56:51969 switches::kEnableCrxlessWebApps,
970 switches::kEnableExperimentalExtensionApis,
[email protected]4287a3d2011-06-13 23:56:51971 switches::kEnableIPCFuzzing,
[email protected]aa75e4ed2012-11-08 23:51:51972 switches::kEnableInteractiveAutocomplete,
[email protected]4287a3d2011-06-13 23:56:51973 switches::kEnableNaCl,
[email protected]45a9c0a2012-11-08 21:00:29974 switches::kEnableNaClSRPCProxy,
[email protected]bcbe7652012-02-22 00:08:48975 switches::kEnablePasswordGeneration,
[email protected]284b03c2012-08-13 17:55:05976 switches::kEnablePnacl,
[email protected]4287a3d2011-06-13 23:56:51977 switches::kEnableWatchdog,
[email protected]4287a3d2011-06-13 23:56:51978 switches::kMemoryProfiling,
979 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37980 switches::kNoJsRandomness,
[email protected]732b1604e2012-10-26 19:59:58981 switches::kPerformCrashAnalysis,
[email protected]f45c5f32012-04-18 19:26:37982 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51983 switches::kPpapiFlashArgs,
984 switches::kPpapiFlashInProcess,
985 switches::kPpapiFlashPath,
986 switches::kPpapiFlashVersion,
987 switches::kProfilingAtStart,
988 switches::kProfilingFile,
989 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37990 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51991 switches::kSilentDumpOnDCHECK,
[email protected]c79d9492012-10-04 19:56:30992 switches::kSpdyProxyOrigin,
[email protected]a446534d2012-02-09 00:07:38993 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51994 };
995
996 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
997 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17998 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38999 static const char* const kSwitchNames[] = {
[email protected]eb653f82012-05-24 02:31:351000 switches::kAllowHTTPBackgroundPage,
[email protected]a446534d2012-02-09 00:07:381001 switches::kEnableExperimentalExtensionApis,
1002 switches::kWhitelistedExtensionID,
1003 };
1004
1005 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1006 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:511007 } else if (process_type == switches::kPluginProcess) {
1008 static const char* const kSwitchNames[] = {
1009 #if defined(OS_CHROMEOS)
1010 switches::kLoginProfile,
1011 #endif
1012 switches::kMemoryProfiling,
1013 switches::kSilentDumpOnDCHECK,
1014 switches::kUserDataDir,
1015 };
1016
1017 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1018 arraysize(kSwitchNames));
1019 } else if (process_type == switches::kZygoteProcess) {
1020 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:511021 switches::kUserDataDir, // Make logs go to the right file.
1022 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:501023 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:131024 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:511025 switches::kPpapiFlashInProcess,
1026 switches::kPpapiFlashPath,
1027 switches::kPpapiFlashVersion,
1028 };
1029
1030 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
1031 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:111032 } else if (process_type == switches::kGpuProcess) {
1033 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
1034 // because GPU is expected to be unreliable.
1035 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
1036 !command_line->HasSwitch(switches::kDisableBreakpad))
1037 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:301038 }
[email protected]6f08af82011-09-15 01:19:031039
1040 // The command line switch kEnableBenchmarking needs to be specified along
1041 // with the kEnableStatsTable switch to ensure that the stats table global
1042 // is initialized correctly.
1043 if (command_line->HasSwitch(switches::kEnableBenchmarking))
1044 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:301045}
1046
1047std::string ChromeContentBrowserClient::GetApplicationLocale() {
[email protected]e9a32a52012-06-14 23:32:431048 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
1049 return io_thread_application_locale_;
[email protected]b80f68432011-05-02 17:22:301050 return g_browser_process->GetApplicationLocale();
1051}
1052
[email protected]597a867b2011-11-18 18:31:201053std::string ChromeContentBrowserClient::GetAcceptLangs(
1054 content::BrowserContext* context) {
1055 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:371056 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:081057}
1058
[email protected]9ec0f452012-05-31 15:58:531059gfx::ImageSkia* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:221060 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]9ec0f452012-05-31 15:58:531061 return rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
[email protected]ac55e292011-06-24 05:16:081062}
1063
[email protected]a2176792011-05-08 19:30:491064bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:091065 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:191066 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:201067 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:321068 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201069 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051070 return io_data->GetCookieSettings()->
1071 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:491072}
1073
[email protected]ed24fad2011-05-10 22:44:011074bool ChromeContentBrowserClient::AllowGetCookie(
1075 const GURL& url,
1076 const GURL& first_party,
1077 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:201078 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011079 int render_process_id,
1080 int render_view_id) {
1081 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201082 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051083 bool allow = io_data->GetCookieSettings()->
1084 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:011085
[email protected]8093a542011-05-13 07:29:321086 BrowserThread::PostTask(
1087 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031088 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:431089 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:011090 return allow;
1091}
1092
1093bool ChromeContentBrowserClient::AllowSetCookie(
1094 const GURL& url,
1095 const GURL& first_party,
1096 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:201097 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:011098 int render_process_id,
1099 int render_view_id,
1100 net::CookieOptions* options) {
1101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201102 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:051103 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1104 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
1105
[email protected]8093a542011-05-13 07:29:321106 BrowserThread::PostTask(
1107 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:031108 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:431109 render_view_id, url, first_party, cookie_line, *options,
1110 !allow));
[email protected]ed24fad2011-05-10 22:44:011111 return allow;
1112}
1113
[email protected]ea628e32012-08-02 21:50:161114bool ChromeContentBrowserClient::AllowPluginLocalDataAccess(
1115 const GURL& document_url,
1116 const GURL& plugin_url,
1117 content::ResourceContext* context) {
1118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1119 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1120 return io_data->GetCookieSettings()->IsReadingCookieAllowed(document_url,
1121 plugin_url);
1122}
1123
1124bool ChromeContentBrowserClient::AllowPluginLocalDataSessionOnly(
1125 const GURL& url,
1126 content::ResourceContext* context) {
1127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1128 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1129 return io_data->GetCookieSettings()->IsCookieSessionOnly(url);
1130}
1131
[email protected]d5a19162011-06-30 18:51:541132bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:201133 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:541134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201135 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]bf510ed2012-06-05 08:31:431136 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1137 ContentSetting setting = cookie_settings->GetDefaultCookieSetting(NULL);
[email protected]1848cdc2012-02-17 10:48:261138
[email protected]bf510ed2012-06-05 08:31:431139 // TODO(bauerb): Should we also disallow local state if the default is BLOCK?
1140 // Could we even support per-origin settings?
1141 return setting != CONTENT_SETTING_SESSION_ONLY;
[email protected]d5a19162011-06-30 18:51:541142}
1143
[email protected]5c5a88e2011-11-12 00:45:351144bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:351145 const GURL& url,
1146 const string16& name,
1147 const string16& display_name,
1148 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:201149 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481150 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201152 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351153 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1154 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1155
[email protected]62151052012-02-01 18:40:481156 // Record access to database for potential display in UI.
1157 std::vector<std::pair<int, int> >::const_iterator i;
1158 for (i = render_views.begin(); i != render_views.end(); ++i) {
1159 BrowserThread::PostTask(
1160 BrowserThread::UI, FROM_HERE,
1161 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
1162 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:351163 }
1164
1165 return allow;
1166}
1167
1168bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:351169 const GURL& url,
[email protected]df02aca2012-02-09 21:03:201170 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:481171 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:351172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201173 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:351174 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1175 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1176
[email protected]62151052012-02-01 18:40:481177 // Record access to file system for potential display in UI.
1178 std::vector<std::pair<int, int> >::const_iterator i;
1179 for (i = render_views.begin(); i != render_views.end(); ++i) {
1180 BrowserThread::PostTask(
1181 BrowserThread::UI, FROM_HERE,
1182 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
1183 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:351184 }
1185
1186 return allow;
1187}
1188
[email protected]7c5ff9a2012-03-02 07:42:491189bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
1190 const GURL& url,
1191 const string16& name,
1192 content::ResourceContext* context,
1193 const std::vector<std::pair<int, int> >& render_views) {
1194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1195 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
1196 CookieSettings* cookie_settings = io_data->GetCookieSettings();
1197 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
1198
1199 // Record access to IndexedDB for potential display in UI.
1200 std::vector<std::pair<int, int> >::const_iterator i;
1201 for (i = render_views.begin(); i != render_views.end(); ++i) {
1202 BrowserThread::PostTask(
1203 BrowserThread::UI, FROM_HERE,
1204 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
1205 i->first, i->second, url, name, !allow));
1206 }
1207
1208 return allow;
1209}
1210
[email protected]6133f922011-07-01 21:34:341211net::URLRequestContext*
1212ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201213 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]885c0e92012-11-13 20:27:421215 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201216 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341217 return io_data->extensions_request_context();
1218 }
1219
1220 return NULL;
1221}
1222
[email protected]317f96c92011-05-31 06:53:411223QuotaPermissionContext*
1224ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1225 return new ChromeQuotaPermissionContext();
1226}
1227
[email protected]a0ce3282011-08-19 20:49:521228void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421229 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421230}
1231
[email protected]a0ce3282011-08-19 20:49:521232void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521233 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521234}
1235
[email protected]848dd042011-06-04 18:24:031236void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171237 int render_process_id,
1238 int render_view_id,
1239 int cert_error,
1240 const net::SSLInfo& ssl_info,
1241 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031242 bool overridable,
[email protected]d9be47702012-05-16 03:41:221243 bool strict_enforcement,
[email protected]4cf611e32012-02-13 16:06:171244 const base::Callback<void(bool)>& callback,
1245 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411246 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131247 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171248 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411249 if (!tab) {
1250 NOTREACHED();
1251 return;
1252 }
1253 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501254 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301255 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]3a6ec762012-10-17 16:01:011256 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab,
1257 NULL)) {
[email protected]f9034cf2011-07-21 12:43:411258 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171259 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411260 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171261 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411262 return;
1263 }
1264 }
1265
[email protected]1e87df32012-09-12 04:53:191266#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
[email protected]eb0b9dd2012-09-19 21:36:231267 captive_portal::CaptivePortalTabHelper* captive_portal_tab_helper =
1268 captive_portal::CaptivePortalTabHelper::FromWebContents(tab);
1269 if (captive_portal_tab_helper)
1270 captive_portal_tab_helper->OnSSLCertError(ssl_info);
[email protected]1e87df32012-09-12 04:53:191271#endif
1272
[email protected]f9034cf2011-07-21 12:43:411273 // Otherwise, display an SSL blocking page.
[email protected]d9be47702012-05-16 03:41:221274 new SSLBlockingPage(tab, cert_error, ssl_info, request_url, overridable,
1275 strict_enforcement, callback);
[email protected]848dd042011-06-04 18:24:031276}
1277
[email protected]c99c442e2011-08-24 11:37:301278void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451279 int render_process_id,
1280 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401281 const net::HttpNetworkSession* network_session,
1282 net::SSLCertRequestInfo* cert_request_info,
1283 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131284 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451285 render_process_id, render_view_id);
1286 if (!tab) {
1287 NOTREACHED();
1288 return;
1289 }
1290
[email protected]6786bf402011-12-03 15:19:451291 GURL requesting_url("https://" + cert_request_info->host_and_port);
1292 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1293 << cert_request_info->host_and_port;
1294
[email protected]627e0512011-12-21 22:55:301295 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451296 scoped_ptr<Value> filter(
1297 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1298 requesting_url,
1299 requesting_url,
1300 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1301 std::string(), NULL));
1302
1303 if (filter.get()) {
1304 // Try to automatically select a client certificate.
1305 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1306 DictionaryValue* filter_dict =
1307 static_cast<DictionaryValue*>(filter.get());
1308
1309 const std::vector<scoped_refptr<net::X509Certificate> >&
1310 all_client_certs = cert_request_info->client_certs;
1311 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1312 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1313 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401314 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451315 return;
1316 }
1317 }
1318 } else {
1319 NOTREACHED();
1320 }
1321 }
1322
[email protected]11feec322012-09-18 03:58:521323 SSLTabHelper* ssl_tab_helper = SSLTabHelper::FromWebContents(tab);
1324 if (!ssl_tab_helper) {
1325 // If there is no SSLTabHelper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451326 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141327 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401328 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451329 return;
1330 }
[email protected]11feec322012-09-18 03:58:521331 ssl_tab_helper->ShowClientCertificateRequestDialog(
[email protected]7a593db2012-02-13 21:19:401332 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451333}
1334
1335void ChromeContentBrowserClient::AddNewCertificate(
1336 net::URLRequest* request,
1337 net::X509Certificate* cert,
1338 int render_process_id,
1339 int render_view_id) {
1340 // The handler will run the UI and delete itself when it's finished.
1341 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1342}
1343
[email protected]dc73a7b2012-03-25 15:27:181344content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1345 return MediaInternals::GetInstance();
1346}
1347
[email protected]941623e2011-06-07 23:06:041348void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1349 const GURL& source_origin,
1350 int callback_context,
1351 int render_process_id,
1352 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111353#if defined(ENABLE_NOTIFICATIONS)
[email protected]d0d9c3ee2012-06-19 03:07:021354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1355 WebContents* contents =
1356 tab_util::GetWebContentsByID(render_process_id, render_view_id);
1357 if (!contents) {
[email protected]941623e2011-06-07 23:06:041358 NOTREACHED();
1359 return;
1360 }
1361
[email protected]d0d9c3ee2012-06-19 03:07:021362 // Skip showing the infobar if the request comes from an extension, and that
1363 // extension has the 'notify' permission. (If the extension does not have the
1364 // permission, the user will still be prompted.)
1365 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
1366 ExtensionService* service = profile->GetExtensionService();
1367 const Extension* extension = !service ? NULL :
1368 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
1369 source_origin));
1370 if (extension &&
[email protected]c2e66e12012-06-27 06:27:061371 extension->HasAPIPermission(APIPermission::kNotification)) {
[email protected]d0d9c3ee2012-06-19 03:07:021372 RenderViewHost* rvh =
1373 RenderViewHost::FromID(render_process_id, render_view_id);
1374 if (rvh)
1375 rvh->DesktopNotificationPermissionRequestDone(callback_context);
1376 return;
1377 }
1378
1379 DesktopNotificationService* notifications =
[email protected]3d7474ff2011-07-27 17:47:371380 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]d0d9c3ee2012-06-19 03:07:021381 notifications->RequestPermission(source_origin, render_process_id,
1382 render_view_id, callback_context, contents);
[email protected]5fd2e842012-03-01 00:29:111383#else
1384 NOTIMPLEMENTED();
1385#endif
[email protected]941623e2011-06-07 23:06:041386}
1387
1388WebKit::WebNotificationPresenter::Permission
1389 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021390 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201391 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021392 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111393#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201395 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021396 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1397 source_origin, render_process_id,
[email protected]c2e66e12012-06-27 06:27:061398 APIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041399 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041400
1401 // Fall back to the regular notification preferences, which works on an
1402 // origin basis.
1403 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371404 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041405 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111406#else
1407 return WebKit::WebNotificationPresenter::PermissionAllowed;
1408#endif
[email protected]941623e2011-06-07 23:06:041409}
1410
1411void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171412 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041413 int render_process_id,
1414 int render_view_id,
1415 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111416#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041417 RenderViewHost* rvh = RenderViewHost::FromID(
1418 render_process_id, render_view_id);
1419 if (!rvh) {
1420 NOTREACHED();
1421 return;
1422 }
1423
[email protected]9f76c1e2012-03-05 15:15:581424 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301425 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041426 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371427 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041428 service->ShowDesktopNotification(
1429 params, render_process_id, render_view_id,
1430 worker ? DesktopNotificationService::WorkerNotification :
1431 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111432#else
1433 NOTIMPLEMENTED();
1434#endif
[email protected]941623e2011-06-07 23:06:041435}
1436
1437void ChromeContentBrowserClient::CancelDesktopNotification(
1438 int render_process_id,
1439 int render_view_id,
1440 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111441#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041442 RenderViewHost* rvh = RenderViewHost::FromID(
1443 render_process_id, render_view_id);
1444 if (!rvh) {
1445 NOTREACHED();
1446 return;
1447 }
1448
[email protected]9f76c1e2012-03-05 15:15:581449 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301450 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041451 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371452 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041453 service->CancelDesktopNotification(
1454 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111455#else
1456 NOTIMPLEMENTED();
1457#endif
[email protected]941623e2011-06-07 23:06:041458}
1459
[email protected]9f3fba52011-06-08 20:37:191460bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351461 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021462 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191463 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201464 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011465 int render_process_id,
1466 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191467 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011468
1469 *no_javascript_access = false;
1470
[email protected]9f3fba52011-06-08 20:37:191471 // If the opener is trying to create a background window but doesn't have
1472 // the appropriate permission, fail the attempt.
1473 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201474 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531475 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1476
[email protected]03b6d552012-03-29 04:03:011477 if (!map->SecurityOriginHasAPIPermission(
1478 source_origin,
1479 render_process_id,
[email protected]c2e66e12012-06-27 06:27:061480 APIPermission::kBackground)) {
[email protected]03b6d552012-03-29 04:03:011481 return false;
1482 }
1483
[email protected]7b54ca02012-03-02 18:06:531484 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1485 // return a recently installed Extension even if this CanCreateWindow call
1486 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011487 // because the permission check above would have caused an early return
1488 // already. We must use the full URL to find hosted apps, though, and not
1489 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531490 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351491 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531492 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011493 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191494 }
1495 return true;
1496}
1497
1498std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201499 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1501 // Check if it's an extension-created worker, in which case we want to use
1502 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201503 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191504 const Extension* extension =
1505 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1506 return extension ? extension->name() : std::string();
1507}
1508
[email protected]99907362012-01-11 05:41:401509void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1510 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171511}
1512
[email protected]c52b2892012-03-07 11:01:021513content::SpeechRecognitionManagerDelegate*
1514 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321515#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021516 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321517#else
1518 return NULL;
1519#endif
[email protected]66cfec62012-02-24 17:57:511520}
1521
[email protected]ae6e9912011-07-27 01:18:281522net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1523 return g_browser_process->net_log();
1524}
1525
[email protected]32538d92011-08-25 00:09:231526AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1527 return new ChromeAccessTokenStore();
1528}
1529
[email protected]dbae6b02011-06-29 23:51:411530bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1531 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1532 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1533}
1534
[email protected]64d69de42012-02-06 00:19:541535void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321536 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061537 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581538 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061539 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061540
[email protected]f3986f82012-01-03 20:00:061541 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541542 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061543 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541544 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061545 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541546 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061547 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541548 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061549 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541550 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061551 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541552 &web_prefs->fantasy_font_family_map);
[email protected]85edc232012-10-05 08:56:031553 FillFontFamilyMap(prefs, prefs::kWebKitPictographFontFamilyMap,
1554 &web_prefs->pictograph_font_family_map);
[email protected]f3986f82012-01-03 20:00:061555
[email protected]64d69de42012-02-06 00:19:541556 web_prefs->default_font_size =
[email protected]ddf72142012-05-22 04:52:401557 prefs->GetInteger(prefs::kWebKitDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541558 web_prefs->default_fixed_font_size =
[email protected]ddf72142012-05-22 04:52:401559 prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541560 web_prefs->minimum_font_size =
[email protected]ddf72142012-05-22 04:52:401561 prefs->GetInteger(prefs::kWebKitMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541562 web_prefs->minimum_logical_font_size =
[email protected]ddf72142012-05-22 04:52:401563 prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
[email protected]f3986f82012-01-03 20:00:061564
[email protected]ddf72142012-05-22 04:52:401565 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061566
[email protected]64d69de42012-02-06 00:19:541567 web_prefs->javascript_can_open_windows_automatically =
[email protected]ddf72142012-05-22 04:52:401568 prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541569 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061570 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541571 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061572 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1573 const DictionaryValue* inspector_settings =
1574 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1575 if (inspector_settings) {
1576 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1577 iter != inspector_settings->end_keys(); ++iter) {
1578 std::string value;
1579 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541580 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061581 std::make_pair(*iter, value));
1582 }
1583 }
[email protected]64d69de42012-02-06 00:19:541584 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061585
[email protected]ddf72142012-05-22 04:52:401586 if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled))
[email protected]64d69de42012-02-06 00:19:541587 web_prefs->javascript_enabled = false;
1588 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1589 web_prefs->web_security_enabled = false;
[email protected]ddf72142012-05-22 04:52:401590 if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled))
[email protected]64d69de42012-02-06 00:19:541591 web_prefs->plugins_enabled = false;
1592 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1593 web_prefs->java_enabled = false;
1594 web_prefs->loads_images_automatically =
[email protected]ddf72142012-05-22 04:52:401595 prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061596
[email protected]64d69de42012-02-06 00:19:541597 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1598 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061599
[email protected]64d69de42012-02-06 00:19:541600 web_prefs->memory_info_enabled =
1601 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1602 web_prefs->allow_displaying_insecure_content =
1603 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1604 web_prefs->allow_running_insecure_content =
1605 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]d3b935f2012-10-19 23:14:321606#if defined(OS_ANDROID)
1607 web_prefs->font_scale_factor =
1608 static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor));
1609 web_prefs->force_enable_zoom =
1610 prefs->GetBoolean(prefs::kWebKitForceEnableZoom);
1611#endif
[email protected]9d06d88d2012-02-23 22:37:081612 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061613
[email protected]64d69de42012-02-06 00:19:541614 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151615 UserStyleSheetWatcher* user_style_sheet_watcher =
1616 UserStyleSheetWatcherFactory::GetForProfile(profile);
1617 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541618 web_prefs->user_style_sheet_enabled = true;
1619 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151620 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541621 } else {
1622 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061623 }
1624
[email protected]b7e44ff2012-02-16 03:37:341625 web_prefs->asynchronous_spell_checking_enabled =
[email protected]37b928e2012-05-30 09:01:101626#if defined(OS_MACOSX)
1627 // TODO(hbono): Bug 107371: Implement asynchronous spellchecking API for
1628 // Mac so it uses NSSpellChecker in the background.
1629 false;
1630#else
1631 !CommandLine::ForCurrentProcess()->
[email protected]57890242012-10-23 17:46:521632 HasSwitch(switches::kForceSyncSpellCheck);
[email protected]37b928e2012-05-30 09:01:101633#endif
[email protected]b7e44ff2012-02-16 03:37:341634 web_prefs->unified_textchecker_enabled =
[email protected]57890242012-10-23 17:46:521635 web_prefs->asynchronous_spell_checking_enabled;
[email protected]dd5d0fb2012-01-18 03:37:571636
[email protected]64d69de42012-02-06 00:19:541637 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061638 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541639 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061640 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541641 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061642 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1643
1644 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541645 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061646 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541647 web_prefs->default_encoding);
1648 if (web_prefs->default_encoding.empty()) {
[email protected]ddf72142012-05-22 04:52:401649 prefs->ClearPref(prefs::kDefaultCharset);
1650 web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061651 }
[email protected]64d69de42012-02-06 00:19:541652 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061653
[email protected]299d7f12012-05-23 05:31:151654 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
1655 chrome::ViewType view_type = chrome::GetViewType(web_contents);
[email protected]f3986f82012-01-03 20:00:061656 ExtensionService* service = profile->GetExtensionService();
1657 if (service) {
[email protected]1bc28312012-11-08 08:31:531658 const GURL& url = rvh->GetSiteInstance()->GetSiteURL();
1659 const Extension* extension = service->extensions()->GetByID(url.host());
1660 // Ensure that we are only granting extension preferences to URLs with
1661 // the correct scheme. Without this check, chrome-guest:// schemes used by
1662 // webview tags as well as hosts that happen to match the id of an
1663 // installed extension would get the wrong preferences.
[email protected]885c0e92012-11-13 20:27:421664 if (url.SchemeIs(extensions::kExtensionScheme)) {
[email protected]1bc28312012-11-08 08:31:531665 extension_webkit_preferences::SetPreferences(
1666 extension, view_type, web_prefs);
1667 }
[email protected]f3986f82012-01-03 20:00:061668 }
1669
[email protected]b7c4f032012-08-07 16:38:561670 if (content::IsForceCompositingModeEnabled())
[email protected]4abe58d2012-06-08 03:09:091671 web_prefs->force_compositing_mode = true;
1672
[email protected]299d7f12012-05-23 05:31:151673 if (view_type == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541674 web_prefs->allow_scripts_to_close_windows = true;
[email protected]299d7f12012-05-23 05:31:151675 } else if (view_type == chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
[email protected]f3986f82012-01-03 20:00:061676 // Disable all kinds of acceleration for background pages.
1677 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541678 web_prefs->force_compositing_mode = false;
1679 web_prefs->accelerated_compositing_enabled = false;
[email protected]f3986f82012-01-03 20:00:061680 }
[email protected]2e21fe292012-03-02 22:52:321681
1682#if defined(FILE_MANAGER_EXTENSION)
1683 // Override the default of suppressing HW compositing for WebUI pages for the
1684 // file manager, which is implemented using WebUI but wants HW acceleration
1685 // for video decode & render.
1686 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1687 web_prefs->accelerated_compositing_enabled = true;
1688 web_prefs->accelerated_2d_canvas_enabled = true;
1689 }
1690#endif
[email protected]181a95ee2011-07-12 19:26:361691}
1692
1693void ChromeContentBrowserClient::UpdateInspectorSetting(
1694 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061695 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581696 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061697 DictionaryPrefUpdate update(
1698 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1699 prefs::kWebKitInspectorSettings);
1700 DictionaryValue* inspector_settings = update.Get();
1701 inspector_settings->SetWithoutPathExpansion(key,
1702 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361703}
1704
1705void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061706 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581707 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061708 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1709 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361710}
1711
[email protected]b8148ac2011-07-13 22:03:251712void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1713 BrowserURLHandler* handler) {
1714 // Add the default URL handlers.
1715 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1716 BrowserURLHandler::null_handler());
1717 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1718 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1719
[email protected]b3adbd02011-11-30 22:23:271720 // about: handler. Must come before chrome: handler, since it will
1721 // rewrite about: urls to chrome: URLs and then expect chrome: to
1722 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251723 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1724 BrowserURLHandler::null_handler());
1725 // chrome: & friends.
[email protected]f8f93eb2012-09-25 03:06:241726 handler->AddHandlerPair(&HandleWebUI, &HandleWebUIReverse);
[email protected]b8148ac2011-07-13 22:03:251727}
1728
1729void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371730 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581731 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471732 BrowsingDataRemover* remover =
1733 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]3d4d4cf2012-06-04 10:40:551734 remover->Remove(BrowsingDataRemover::REMOVE_CACHE,
1735 BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251736 // BrowsingDataRemover takes care of deleting itself when done.
1737}
1738
1739void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371740 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581741 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]38b892b42012-09-04 13:25:471742 BrowsingDataRemover* remover =
1743 BrowsingDataRemover::CreateForUnboundedRange(profile);
[email protected]dceaa912011-09-06 17:17:231744 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]3d4d4cf2012-06-04 10:40:551745 remover->Remove(remove_mask, BrowsingDataHelper::UNPROTECTED_WEB);
[email protected]b8148ac2011-07-13 22:03:251746 // BrowsingDataRemover takes care of deleting itself when done.
1747}
1748
[email protected]e1d16eb92011-08-18 23:19:321749FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1750 return download_util::GetDefaultDownloadDirectory();
1751}
1752
[email protected]c9b6eb62011-10-18 20:49:391753std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1754 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1755}
1756
[email protected]b7631cc2012-09-15 05:08:381757void ChromeContentBrowserClient::DidCreatePpapiPlugin(
1758 content::BrowserPpapiHost* browser_host) {
1759 browser_host->GetPpapiHost()->AddHostFactoryFilter(
1760 scoped_ptr<ppapi::host::HostFactory>(
1761 new ChromeBrowserPepperHostFactory(browser_host)));
1762}
1763
[email protected]0c7193742012-11-07 19:05:031764content::BrowserPpapiHost*
1765 ChromeContentBrowserClient::GetExternalBrowserPpapiHost(
1766 int plugin_process_id) {
1767 BrowserChildProcessHostIterator iter(content::PROCESS_TYPE_NACL_LOADER);
1768 while (!iter.Done()) {
1769 NaClProcessHost* host = static_cast<NaClProcessHost*>(iter.GetDelegate());
1770 if (host->process() &&
1771 host->process()->GetData().id == plugin_process_id) {
1772 // Found the plugin.
1773 return host->browser_ppapi_host();
1774 }
1775 ++iter;
1776 }
1777 return NULL;
1778}
1779
[email protected]38cd8f7f2012-06-15 22:06:071780bool ChromeContentBrowserClient::AllowPepperSocketAPI(
[email protected]157cc902012-11-02 06:31:581781 content::BrowserContext* browser_context,
1782 const GURL& url,
1783 const content::SocketPermissionRequest& params) {
[email protected]a658d452012-03-02 12:45:291784 if (!url.is_valid())
1785 return false;
1786
1787 std::string host = url.host();
[email protected]885c0e92012-11-13 20:27:421788 if (url.SchemeIs(extensions::kExtensionScheme) &&
1789 allowed_socket_origins_.count(host)) {
[email protected]a658d452012-03-02 12:45:291790 return true;
[email protected]885c0e92012-11-13 20:27:421791 }
[email protected]a658d452012-03-02 12:45:291792
[email protected]9a5940d2012-04-27 19:16:231793 Profile* profile = Profile::FromBrowserContext(browser_context);
1794 const Extension* extension = NULL;
1795 if (profile && profile->GetExtensionService()) {
1796 extension = profile->GetExtensionService()->extensions()->
1797 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1798 }
1799
[email protected]f237c0f2012-03-10 07:49:101800 // Need to check this now and not on construction because otherwise it won't
1801 // work with browser_tests.
1802 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1803 std::string allowed_list =
1804 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
[email protected]9a5940d2012-04-27 19:16:231805 if (allowed_list == "*") {
1806 // The wildcard allows socket API only for packaged and platform apps.
1807 return extension &&
[email protected]c4f459d2012-09-28 04:40:101808 (extension->GetType() == Extension::TYPE_LEGACY_PACKAGED_APP ||
[email protected]9a5940d2012-04-27 19:16:231809 extension->GetType() == Extension::TYPE_PLATFORM_APP);
1810 } else if (!allowed_list.empty()) {
[email protected]f237c0f2012-03-10 07:49:101811 StringTokenizer t(allowed_list, ",");
1812 while (t.GetNext()) {
1813 if (t.token() == host)
1814 return true;
1815 }
1816 }
1817
[email protected]a658d452012-03-02 12:45:291818 if (!extension)
1819 return false;
1820
[email protected]157cc902012-11-02 06:31:581821 extensions::SocketPermission::CheckParam extension_params(
1822 params.type, params.host, params.port);
1823 if (extension->CheckAPIPermissionWithParam(APIPermission::kSocket,
1824 &extension_params))
[email protected]a658d452012-03-02 12:45:291825 return true;
1826
1827 return false;
[email protected]e461da2f2012-02-16 19:06:401828}
1829
[email protected]38cd8f7f2012-06-15 22:06:071830bool ChromeContentBrowserClient::AllowPepperPrivateFileAPI() {
1831 return CommandLine::ForCurrentProcess()->HasSwitch(
1832 switches::kPpapiFlashInProcess);
1833}
1834
[email protected]a7944aa2012-10-15 10:12:141835FilePath ChromeContentBrowserClient::GetHyphenDictionaryDirectory() {
1836 FilePath directory;
1837 PathService::Get(chrome::DIR_APP_DICTIONARIES, &directory);
1838 return directory.Append(FILE_PATH_LITERAL("Hyphen"));
1839}
1840
[email protected]e60c0232011-11-11 19:56:351841#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]a1733df2012-06-22 11:24:181842void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
1843 const CommandLine& command_line,
[email protected]40da3e0c2012-10-24 22:03:381844 int child_process_id,
[email protected]c7abd422012-09-25 00:20:081845 std::vector<FileDescriptorInfo>* mappings) {
[email protected]29699c22012-10-03 23:57:391846#if defined(OS_ANDROID)
1847 FilePath data_path;
1848 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &data_path);
1849 DCHECK(!data_path.empty());
1850
1851 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
1852 FilePath chrome_pak = data_path.AppendASCII("chrome.pak");
1853 base::PlatformFile f =
1854 base::CreatePlatformFile(chrome_pak, flags, NULL, NULL);
1855 DCHECK(f != base::kInvalidPlatformFileValue);
1856 mappings->push_back(FileDescriptorInfo(kAndroidChromePakDescriptor,
1857 FileDescriptor(f, true)));
1858
1859 FilePath chrome_resources_pak =
1860 data_path.AppendASCII("chrome_100_percent.pak");
1861 f = base::CreatePlatformFile(chrome_resources_pak, flags, NULL, NULL);
1862 DCHECK(f != base::kInvalidPlatformFileValue);
1863 mappings->push_back(FileDescriptorInfo(kAndroidUIResourcesPakDescriptor,
1864 FileDescriptor(f, true)));
1865
1866 const std::string locale = GetApplicationLocale();
1867 FilePath locale_pak = ResourceBundle::GetSharedInstance().
1868 GetLocaleFilePath(locale, false);
1869 f = base::CreatePlatformFile(locale_pak, flags, NULL, NULL);
1870 DCHECK(f != base::kInvalidPlatformFileValue);
1871 mappings->push_back(FileDescriptorInfo(kAndroidLocalePakDescriptor,
1872 FileDescriptor(f, true)));
[email protected]40da3e0c2012-10-24 22:03:381873
1874#if defined(USE_LINUX_BREAKPAD)
1875 f = crash_dump_manager_->CreateMinidumpFile(child_process_id);
1876 if (f == base::kInvalidPlatformFileValue) {
1877 LOG(ERROR) << "Failed to create file for minidump, crash reporting will be "
1878 "disabled for this process.";
1879 } else {
1880 mappings->push_back(FileDescriptorInfo(kAndroidMinidumpDescriptor,
1881 FileDescriptor(f, true)));
1882 }
1883#endif // defined(USE_LINUX_BREAKPAD)
1884
1885#else
1886 int crash_signal_fd = GetCrashSignalFD(command_line);
1887 if (crash_signal_fd >= 0) {
1888 mappings->push_back(FileDescriptorInfo(kCrashDumpSignal,
1889 FileDescriptor(crash_signal_fd,
1890 false)));
1891 }
[email protected]29699c22012-10-03 23:57:391892#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:301893}
[email protected]e60c0232011-11-11 19:56:351894#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301895
[email protected]4a65826d2011-08-25 16:04:011896#if defined(OS_WIN)
1897const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1898 return chrome::kBrowserResourcesDll;
1899}
1900#endif
1901
[email protected]40da3e0c2012-10-24 22:03:381902#if defined(OS_ANDROID)
1903void ChromeContentBrowserClient::InitCrashDumpManager() {
1904 if (!crash_dump_manager_.get())
1905 crash_dump_manager_.reset(new CrashDumpManager());
1906}
1907#endif
1908
[email protected]37a72af2011-06-13 05:42:011909#if defined(USE_NSS)
1910crypto::CryptoModuleBlockingPasswordDelegate*
1911 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1912 const GURL& url) {
[email protected]6246ac52012-09-24 01:55:291913 return chrome::NewCryptoModuleBlockingDialogDelegate(
1914 chrome::kCryptoModulePasswordKeygen, url.host());
[email protected]37a72af2011-06-13 05:42:011915}
1916#endif
1917
[email protected]e9a32a52012-06-14 23:32:431918void ChromeContentBrowserClient::SetApplicationLocale(
1919 const std::string& locale) {
1920 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1921
1922 // This object is guaranteed to outlive all threads so we don't have to
1923 // worry about the lack of refcounting and can just post as Unretained.
1924 //
1925 // The common case is that this function is called early in Chrome startup
1926 // before any threads are created (it will also be called later if the user
1927 // changes the pref). In this case, there will be no threads created and
1928 // posting will fail. When there are no threads, we can just set the string
1929 // without worrying about threadsafety.
1930 if (!BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
1931 base::Bind(
1932 &ChromeContentBrowserClient::SetApplicationLocaleOnIOThread,
1933 base::Unretained(this), locale)))
1934 io_thread_application_locale_ = locale;
1935}
1936
1937void ChromeContentBrowserClient::SetApplicationLocaleOnIOThread(
1938 const std::string& locale) {
1939 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1940 io_thread_application_locale_ = locale;
1941}
1942
[email protected]d977f9c2011-03-14 16:10:261943} // namespace chrome