blob: 9cd6c70e741d4ab6eb31d7d8b601ff0e0765d423 [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]e461da2f2012-02-16 19:06:4013#include "base/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0614#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3015#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2516#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3017#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2318#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1219#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0320#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4121#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5622#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0523#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4524#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3225#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0826#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3227#include "chrome/browser/download/download_util.h"
[email protected]6e672df2012-01-25 10:39:4728#include "chrome/browser/extensions/api/webrequest/webrequest_api.h"
[email protected]76411f412012-02-22 18:56:0629#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0430#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1031#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]9c1662b2012-03-06 15:44:3332#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2633#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2534#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0635#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]32538d92011-08-25 00:09:2336#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1237#include "chrome/browser/google/google_util.h"
[email protected]117b6b42012-02-29 09:11:0838#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]ae6e9912011-07-27 01:18:2839#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0440#include "chrome/browser/notifications/desktop_notification_service.h"
41#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4242#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1243#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0644#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4145#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5046#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4147#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1448#include "chrome/browser/printing/printing_message_filter.h"
49#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3250#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0651#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1452#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3353#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4254#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1455#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0256#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4657#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4558#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0359#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4560#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
61#include "chrome/browser/tab_contents/tab_util.h"
[email protected]117b6b42012-02-29 09:11:0862#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]8ec26472011-06-06 16:52:4563#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]863f70a2012-01-27 02:05:5064#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0665#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]b80f68432011-05-02 17:22:3066#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0167#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3068#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0469#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4470#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3471#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1272#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3873#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0974#include "chrome/common/url_constants.h"
[email protected]b48c9182011-10-26 18:03:3075#include "content/public/browser/browser_main_parts.h"
[email protected]825b1662012-03-12 19:07:3176#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5977#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3078#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3379#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0580#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3381#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1982#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1083#include "content/public/browser/web_contents_view.h"
[email protected]c9b6eb62011-10-18 20:49:3984#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3485#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4086#include "net/base/ssl_cert_request_info.h"
[email protected]aa84a7e2012-03-15 21:29:0687#include "net/cookies/cookie_monster.h"
88#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3989#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0890#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3691#include "webkit/glue/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:2692
[email protected]b48c9182011-10-26 18:03:3093#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3894#include "chrome/browser/chrome_browser_main_win.h"
95#elif defined(OS_MACOSX)
96#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:5697#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]38b098f2012-03-14 21:11:5798#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h"
[email protected]b48c9182011-10-26 18:03:3099#elif defined(OS_CHROMEOS)
100#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49101#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]e60c0232011-11-11 19:56:35102#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:30103#include "chrome/browser/chrome_browser_main_linux.h"
104#elif defined(OS_POSIX)
105#include "chrome/browser/chrome_browser_main_posix.h"
106#endif
107
[email protected]61e69822012-03-14 22:08:57108#if defined(OS_WIN) && !defined(USE_AURA)
109#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_win.h"
110#endif
111
[email protected]b48c9182011-10-26 18:03:30112#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31113#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38114#endif
115
[email protected]c7480942011-11-08 19:18:27116#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31117#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]38b098f2012-03-14 21:11:57118#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c7480942011-11-08 19:18:27119#endif
120
121#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31122#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
123#endif
124
[email protected]e60c0232011-11-11 19:56:35125#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30126#include "base/linux_util.h"
127#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43128#endif
[email protected]b80f68432011-05-02 17:22:30129
[email protected]38b098f2012-03-14 21:11:57130#if defined(TOOLKIT_GTK)
131#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_gtk.h"
[email protected]74313b42011-08-24 16:51:32132#endif
[email protected]37a72af2011-06-13 05:42:01133#if defined(USE_NSS)
134#include "chrome/browser/ui/crypto_module_password_dialog.h"
135#endif
136
[email protected]c8c77182011-12-21 15:04:47137using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39138using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31139using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59140using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00141using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11142using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33143using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13144using content::WebContents;
[email protected]631bb742011-11-02 11:29:39145
[email protected]c5dbef02011-05-13 05:06:09146namespace {
147
[email protected]e461da2f2012-02-16 19:06:40148const char* kPredefinedAllowedSocketOrigins[] = {
149 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
150 "pnhechapfaindjhompbnflcldabbghjo" // HTerm App (SSH Client)
151};
152
[email protected]b8148ac2011-07-13 22:03:25153// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42154bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50155 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
156 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25157 return false;
158
[email protected]fe69558d2012-03-12 11:34:49159#if defined(OS_CHROMEOS)
160 // Special case : in ChromeOS in Guest mode bookmarks and history are
161 // disabled for security reasons. New tab page explains the reasons, so
162 // we redirect user to new tab page.
163 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
164 if (url->SchemeIs(chrome::kChromeUIScheme) &&
165 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
166 url->DomainIs(chrome::kChromeUIHistoryHost))) {
167 // Rewrite with new tab URL
168 *url = GURL(chrome::kChromeUINewTabURL);
169 }
170 }
171#endif
172
[email protected]b8148ac2011-07-13 22:03:25173 // Special case the new tab page. In older versions of Chrome, the new tab
174 // page was hosted at chrome-internal:<blah>. This might be in people's saved
175 // sessions or bookmarks, so we say any URL with that scheme triggers the new
176 // tab page.
177 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
178 // Rewrite it with the proper new tab URL.
179 *url = GURL(chrome::kChromeUINewTabURL);
180 }
181
182 return true;
183}
184
[email protected]8d3132f62011-10-12 07:13:42185// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
186// below. Extension, and isolated apps require different privileges to be
187// granted to their RenderProcessHosts. This classification allows us to make
188// sure URLs are served by hosts with the right set of privileges.
189enum RenderProcessHostPrivilege {
190 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45191 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42192 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45193 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42194};
195
196RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
197 const GURL& url,
198 ExtensionService* service) {
199 // Default to a normal renderer cause it is lower privileged. This should only
200 // occur if the URL on a site instance is either malformed, or uninitialized.
201 // If it is malformed, then there is no need for better privileges anyways.
202 // If it is uninitialized, but eventually settles on being an a scheme other
203 // than normal webrenderer, the navigation logic will correct us out of band
204 // anyways.
205 if (!url.is_valid())
206 return PRIV_NORMAL;
207
208 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44209 const Extension* extension =
210 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45211 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42212 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45213 if (extension && extension->is_hosted_app())
214 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42215
216 return PRIV_EXTENSION;
217 }
218
219 return PRIV_NORMAL;
220}
221
222RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30223 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46224 extensions::ProcessMap* process_map,
225 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46226 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30227 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46228 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21229 return PRIV_NORMAL;
230
[email protected]6f371442011-11-09 06:45:46231 for (std::set<std::string>::iterator iter = extension_ids.begin();
232 iter != extension_ids.end(); ++iter) {
233 const Extension* extension = service->GetExtensionById(*iter, false);
234 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42235 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45236 if (extension && extension->is_hosted_app())
237 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42238 }
239
[email protected]676f6ab2011-10-19 20:23:21240 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42241}
242
[email protected]eec0b33c2011-12-05 22:09:45243bool IsIsolatedAppInProcess(const GURL& site_url,
244 content::RenderProcessHost* process_host,
245 extensions::ProcessMap* process_map,
246 ExtensionService* service) {
247 std::set<std::string> extension_ids =
248 process_map->GetExtensionsInProcess(process_host->GetID());
249 if (extension_ids.empty())
250 return false;
251
252 for (std::set<std::string>::iterator iter = extension_ids.begin();
253 iter != extension_ids.end(); ++iter) {
254 const Extension* extension = service->GetExtensionById(*iter, false);
255 if (extension &&
256 extension->is_storage_isolated() &&
257 extension->url() == site_url)
258 return true;
259 }
260
261 return false;
262}
263
[email protected]6786bf402011-12-03 15:19:45264bool CertMatchesFilter(const net::X509Certificate& cert,
265 const base::DictionaryValue& filter) {
266 // TODO(markusheintz): This is the minimal required filter implementation.
267 // Implement a better matcher.
268
269 // An empty filter matches any client certificate since no requirements are
270 // specified at all.
271 if (filter.empty())
272 return true;
273
274 std::string common_name;
275 if (filter.GetString("ISSUER.CN", &common_name) &&
276 (cert.issuer().common_name == common_name)) {
277 return true;
278 }
279 return false;
280}
281
[email protected]f3986f82012-01-03 20:00:06282// Fills |map| with the per-script font prefs under path |map_name|.
283void FillFontFamilyMap(const PrefService* prefs,
284 const char* map_name,
285 WebPreferences::ScriptFontFamilyMap* map) {
286 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
287 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
288 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
289 std::string font_family = prefs->GetString(pref_name.c_str());
290 if (!font_family.empty())
291 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
292 }
293}
294
[email protected]9dbfff12011-07-01 19:37:07295} // namespace
[email protected]c5dbef02011-05-13 05:06:09296
[email protected]d977f9c2011-03-14 16:10:26297namespace chrome {
298
[email protected]e461da2f2012-02-16 19:06:40299ChromeContentBrowserClient::ChromeContentBrowserClient() {
300 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
301 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40302}
303
304ChromeContentBrowserClient::~ChromeContentBrowserClient() {
305}
306
[email protected]50462bf02011-11-21 19:13:31307content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
308 const content::MainFunctionParams& parameters) {
309 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30310 // Construct the Main browser parts based on the OS type.
311#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31312 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04313#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31314 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30315#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31316 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35317#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31318 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14319#elif defined(OS_ANDROID)
320 // Do nothing for Android.
321 // TODO(klobag): Android initialization should use the
322 // *BrowserMainParts class-hierarchy for setting up custom initialization.
323 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30324#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31325 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04326#else
[email protected]b48c9182011-10-26 18:03:30327 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31328 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30329#endif
330
[email protected]c7480942011-11-08 19:18:27331 // Construct additional browser parts. Stages are called in the order in
332 // which they are added.
[email protected]b48c9182011-10-26 18:03:30333#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31334 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04335#endif
[email protected]c7480942011-11-08 19:18:27336
337#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31338 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27339#endif
340
341#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31342 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27343#endif
344
[email protected]50462bf02011-11-21 19:13:31345 return main_parts;
[email protected]f967b722011-09-07 00:58:04346}
347
[email protected]38b098f2012-03-14 21:11:57348content::WebContentsView*
349 ChromeContentBrowserClient::OverrideCreateWebContentsView(
350 WebContents* web_contents) {
351#if defined(TOOLKIT_VIEWS)
[email protected]8dad546b2012-01-17 21:47:35352 return new TabContentsViewViews(web_contents);
[email protected]38b098f2012-03-14 21:11:57353#endif
354 return NULL;
355}
356
357content::WebContentsViewDelegate*
358 ChromeContentBrowserClient::GetWebContentsViewDelegate(
359 content::WebContents* web_contents) {
360#if defined(OS_WIN) && !defined(USE_AURA)
361 return new ChromeWebContentsViewDelegateWin(web_contents);
362#elif defined(TOOLKIT_GTK)
363 return new ChromeWebContentsViewDelegateGtk(web_contents);
[email protected]74313b42011-08-24 16:51:32364#elif defined(OS_MACOSX)
[email protected]38b098f2012-03-14 21:11:57365 return
366 chrome_web_contents_view_delegate_mac::CreateWebContentsViewDelegateMac(
367 web_contents);
[email protected]74313b42011-08-24 16:51:32368#else
[email protected]38b098f2012-03-14 21:11:57369 return NULL;
[email protected]74313b42011-08-24 16:51:32370#endif
371}
372
[email protected]f364d1392011-04-08 21:03:10373void ChromeContentBrowserClient::RenderViewHostCreated(
374 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46375
[email protected]9f76c1e2012-03-05 15:15:58376 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46377 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02378 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46379
380 new ChromeRenderViewHostObserver(render_view_host,
381 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10382 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26383}
384
[email protected]f3b1a082011-11-18 00:34:30385void ChromeContentBrowserClient::RenderProcessHostCreated(
386 content::RenderProcessHost* host) {
387 int id = host->GetID();
388 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
389 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02390 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30391 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03392#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30393 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03394#endif
[email protected]f3b1a082011-11-18 00:34:30395 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02396 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30397 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56398#if defined(OS_MACOSX)
399 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
400#endif
[email protected]f3b1a082011-11-18 00:34:30401 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03402 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38403
[email protected]2ccf45c2011-08-19 23:35:50404 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
405 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07406
407 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56408
409 RendererContentSettingRules rules;
410 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
411 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14412}
413
[email protected]863f70a2012-01-27 02:05:50414content::WebUIControllerFactory*
415 ChromeContentBrowserClient::GetWebUIControllerFactory() {
416 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56417}
418
[email protected]3d7474ff2011-07-27 17:47:37419GURL ChromeContentBrowserClient::GetEffectiveURL(
420 content::BrowserContext* browser_context, const GURL& url) {
421 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08422 // Get the effective URL for the given actual URL. If the URL is part of an
423 // installed app, the effective URL is an extension URL with the ID of that
424 // extension as the host. This has the effect of grouping apps together in
425 // a common SiteInstance.
426 if (!profile || !profile->GetExtensionService())
427 return url;
428
[email protected]615d88f2011-12-13 01:47:44429 const Extension* extension = profile->GetExtensionService()->extensions()->
430 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08431 if (!extension)
432 return url;
433
[email protected]15877ca2011-11-18 22:40:52434 // Bookmark apps do not use the hosted app process model, and should be
435 // treated as normal URLs.
436 if (extension->from_bookmark())
437 return url;
438
[email protected]36fb2c7c2011-04-04 15:49:08439 // If the URL is part of an extension's web extent, convert it to an
440 // extension URL.
441 return extension->GetResourceURL(url.path());
442}
443
[email protected]056ad2a2011-07-12 02:13:55444bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37445 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55446 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52447 // Because we expect to use the effective URL, URLs for hosted apps (apart
448 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55449 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
450 return false;
451
[email protected]3d7474ff2011-07-27 17:47:37452 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55453 if (!profile || !profile->GetExtensionService())
454 return false;
455
[email protected]615d88f2011-12-13 01:47:44456 const Extension* extension = profile->GetExtensionService()->extensions()->
457 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55458 if (!extension)
459 return false;
460
461 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53462 // permission, or that does not allow JavaScript access to the background
463 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55464 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53465 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
466 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
467 !extension->allow_background_js_access()) {
468 return false;
469 }
470 }
[email protected]056ad2a2011-07-12 02:13:55471
[email protected]7b54ca02012-03-02 18:06:53472 // Hosted apps that have script access to their background page must use
473 // process per site, since all instances can make synchronous calls to the
474 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55475 return true;
476}
477
[email protected]46fb9442011-12-09 17:57:47478bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
479 return ProfileIOData::IsHandledURL(url);
480}
481
[email protected]2a5221b2011-09-27 23:07:31482bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30483 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31484 const GURL& site_url) {
485 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30486 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42487 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46488 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31489
[email protected]ffa97602011-11-17 17:55:52490 // Don't allow the Task Manager to share a process with anything else.
491 // Otherwise it can affect the renderers it is observing.
492 // Note: we could create another RenderProcessHostPrivilege bucket for
493 // this to allow multiple chrome://tasks instances to share, but that's
494 // a very unlikely case without serious consequences.
495 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
496 return false;
497
[email protected]8d3132f62011-10-12 07:13:42498 // These may be NULL during tests. In that case, just assume any site can
499 // share any host.
[email protected]6f371442011-11-09 06:45:46500 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31501 return true;
502
[email protected]a8c269a2011-10-25 20:17:22503 // Experimental:
504 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
505 // to share a renderer process. (We could allow pages from the same site or
506 // extensions of the same type to share, if we knew what the given process
507 // was dedicated to. Allowing no sharing is simpler for now.) This may
508 // cause resource exhaustion issues if too many sites are open at once.
509 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
510 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
511 return false;
512
[email protected]eec0b33c2011-12-05 22:09:45513 // An isolated app is only allowed to share with the exact same app in order
514 // to provide complete renderer process isolation. This also works around
515 // issue http://crbug.com/85588, where different isolated apps in the same
516 // process would end up using the first app's storage contexts.
517 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42518 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45519 if (privilege_required == PRIV_ISOLATED)
520 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
521
522 // Otherwise, just make sure the process privilege matches the privilege
523 // required by the site.
524 return GetProcessPrivilege(process_host, process_map, service) ==
525 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31526}
527
[email protected]76411f412012-02-22 18:56:06528// This function is trying to limit the amount of processes used by extensions
529// with background pages. It uses a globally set percentage of processes to
530// run such extensions and if the limit is exceeded, it returns true, to
531// indicate to the content module to group extensions together.
532bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
533 content::BrowserContext* browser_context, const GURL& url) {
534 // It has to be a valid URL for us to check for an extension.
535 if (!url.is_valid())
536 return false;
537
538 Profile* profile = Profile::FromBrowserContext(browser_context);
539 ExtensionService* service = profile->GetExtensionService();
540 if (!service)
541 return false;
542
543 // We have to have a valid extension with background page to proceed.
544 const Extension* extension =
545 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
546 if (!extension)
547 return false;
548 if (!extension->has_background_page())
549 return false;
550
551 std::set<int> process_ids;
552 size_t max_process_count =
553 content::RenderProcessHost::GetMaxRendererProcessCount();
554
555 // Go through all profiles to ensure we have total count of extension
556 // processes containing background pages, otherwise one profile can
557 // starve the other.
558 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
559 GetLoadedProfiles();
560 for (size_t i = 0; i < profiles.size(); ++i) {
561 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
562 for (ExtensionProcessManager::const_iterator iter = epm->begin();
563 iter != epm->end();
564 ++iter) {
565 ExtensionHost* host = *iter;
566 if (host->extension()->has_background_page()) {
567 process_ids.insert(host->render_process_host()->GetID());
568 }
569 }
570 }
571
572 if (process_ids.size() >
573 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
574 return true;
575 }
576
577 return false;
578}
579
[email protected]6f371442011-11-09 06:45:46580void ChromeContentBrowserClient::SiteInstanceGotProcess(
581 SiteInstance* site_instance) {
582 CHECK(site_instance->HasProcess());
583
584 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02585 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46586 ExtensionService* service = profile->GetExtensionService();
587 if (!service)
588 return;
589
590 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44591 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33592 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46593 if (!extension)
594 return;
595
[email protected]6bc04fd82011-12-04 02:29:35596 service->process_map()->Insert(extension->id(),
597 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33598 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46599 BrowserThread::PostTask(
600 BrowserThread::IO, FROM_HERE,
601 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]e15be2b2012-03-09 08:42:11602 profile->GetExtensionInfoMap(),
[email protected]6f371442011-11-09 06:45:46603 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35604 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33605 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46606}
607
608void ChromeContentBrowserClient::SiteInstanceDeleting(
609 SiteInstance* site_instance) {
610 if (!site_instance->HasProcess())
611 return;
612
613 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02614 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46615 ExtensionService* service = profile->GetExtensionService();
616 if (!service)
617 return;
618
619 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44620 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33621 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46622 if (!extension)
623 return;
624
[email protected]6bc04fd82011-12-04 02:29:35625 service->process_map()->Remove(extension->id(),
626 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33627 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46628 BrowserThread::PostTask(
629 BrowserThread::IO, FROM_HERE,
630 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]e15be2b2012-03-09 08:42:11631 profile->GetExtensionInfoMap(),
[email protected]6f371442011-11-09 06:45:46632 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35633 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33634 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46635}
636
[email protected]e3daf3c2011-10-05 21:17:08637bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
638 const GURL& current_url,
639 const GURL& new_url) {
640 if (current_url.is_empty()) {
641 // Always choose a new process when navigating to extension URLs. The
642 // process grouping logic will combine all of a given extension's pages
643 // into the same process.
644 if (new_url.SchemeIs(chrome::kExtensionScheme))
645 return true;
646
647 return false;
648 }
649
650 // Also, we must switch if one is an extension and the other is not the exact
651 // same extension.
652 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
653 new_url.SchemeIs(chrome::kExtensionScheme)) {
654 if (current_url.GetOrigin() != new_url.GetOrigin())
655 return true;
656 }
657
658 return false;
659}
660
[email protected]763ec4ca2011-04-29 15:48:12661std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
662 const std::string& alias_name) {
663 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
664}
665
[email protected]b80f68432011-05-02 17:22:30666void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
667 CommandLine* command_line, int child_process_id) {
668#if defined(USE_LINUX_BREAKPAD)
669 if (IsCrashReporterEnabled()) {
670 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
671 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
672 }
673#elif defined(OS_MACOSX)
674 if (IsCrashReporterEnabled()) {
675 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
676 child_process_logging::GetClientId());
677 }
678#endif // OS_MACOSX
679
[email protected]f1933792011-06-14 00:49:34680 if (logging::DialogsAreSuppressed())
681 command_line->AppendSwitch(switches::kNoErrorDialogs);
682
[email protected]b80f68432011-05-02 17:22:30683 std::string process_type =
684 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17685 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52686 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30687 FilePath user_data_dir =
688 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
689 if (!user_data_dir.empty())
690 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
691#if defined(OS_CHROMEOS)
692 const std::string& login_profile =
693 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
694 if (!login_profile.empty())
695 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
696#endif
697
[email protected]f3b1a082011-11-18 00:34:30698 content::RenderProcessHost* process =
699 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37700 if (process) {
701 Profile* profile = Profile::FromBrowserContext(
702 process->GetBrowserContext());
703 extensions::ProcessMap* process_map =
704 profile->GetExtensionService()->process_map();
705 if (process_map && process_map->Contains(process->GetID()))
706 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30707
[email protected]a8d851f82011-12-21 00:32:37708 PrefService* prefs = profile->GetPrefs();
709 // Currently this pref is only registered if applied via a policy.
710 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
711 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
712 // Turn this policy into a command line switch.
713 command_line->AppendSwitch(switches::kDisable3DAPIs);
714 }
[email protected]718eab62011-10-05 21:16:52715
[email protected]a8d851f82011-12-21 00:32:37716 // Disable client-side phishing detection in the renderer if it is
717 // disabled in the Profile preferences or the browser process.
718 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
719 !g_browser_process->safe_browsing_detection_service()) {
720 command_line->AppendSwitch(
721 switches::kDisableClientSidePhishingDetection);
722 }
[email protected]8c40da62011-07-13 22:58:46723 }
[email protected]47c7ec82012-01-18 03:29:21724 {
725 PrefService* local_state = g_browser_process->local_state();
726 if (local_state &&
727 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
728 command_line->AppendSwitch(switches::kRendererPrintPreview);
729 }
730 }
[email protected]4287a3d2011-06-13 23:56:51731
[email protected]47c7ec82012-01-18 03:29:21732 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51733 static const char* const kSwitchNames[] = {
734 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48735 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51736 switches::kAllowScriptingGallery,
737 switches::kAppsCheckoutURL,
738 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31739 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51740 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50741 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51742 switches::kDumpHistogramsOnExit,
[email protected]b7e44ff2012-02-16 03:37:34743 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21744 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13745 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51746 switches::kEnableCrxlessWebApps,
747 switches::kEnableExperimentalExtensionApis,
748 switches::kEnableInBrowserThumbnailing,
749 switches::kEnableIPCFuzzing,
750 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:48751 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53752 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51753 switches::kEnableWatchdog,
754 switches::kExperimentalSpellcheckerFeatures,
755 switches::kMemoryProfiling,
756 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04757 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51758 switches::kPpapiFlashArgs,
759 switches::kPpapiFlashInProcess,
760 switches::kPpapiFlashPath,
761 switches::kPpapiFlashVersion,
762 switches::kProfilingAtStart,
763 switches::kProfilingFile,
764 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51765 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38766 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51767 };
768
769 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
770 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17771 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38772 static const char* const kSwitchNames[] = {
773 switches::kEnableExperimentalExtensionApis,
774 switches::kWhitelistedExtensionID,
775 };
776
777 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
778 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51779 } else if (process_type == switches::kPluginProcess) {
780 static const char* const kSwitchNames[] = {
781 #if defined(OS_CHROMEOS)
782 switches::kLoginProfile,
783 #endif
784 switches::kMemoryProfiling,
785 switches::kSilentDumpOnDCHECK,
786 switches::kUserDataDir,
787 };
788
789 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
790 arraysize(kSwitchNames));
791 } else if (process_type == switches::kZygoteProcess) {
792 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51793 switches::kUserDataDir, // Make logs go to the right file.
794 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50795 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13796 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51797 switches::kPpapiFlashInProcess,
798 switches::kPpapiFlashPath,
799 switches::kPpapiFlashVersion,
800 };
801
802 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
803 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11804 } else if (process_type == switches::kGpuProcess) {
805 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
806 // because GPU is expected to be unreliable.
807 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
808 !command_line->HasSwitch(switches::kDisableBreakpad))
809 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30810 }
[email protected]6f08af82011-09-15 01:19:03811
812 // The command line switch kEnableBenchmarking needs to be specified along
813 // with the kEnableStatsTable switch to ensure that the stats table global
814 // is initialized correctly.
815 if (command_line->HasSwitch(switches::kEnableBenchmarking))
816 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30817}
818
819std::string ChromeContentBrowserClient::GetApplicationLocale() {
820 return g_browser_process->GetApplicationLocale();
821}
822
[email protected]597a867b2011-11-18 18:31:20823std::string ChromeContentBrowserClient::GetAcceptLangs(
824 content::BrowserContext* context) {
825 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37826 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08827}
828
[email protected]ac55e292011-06-24 05:16:08829SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22830 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08831 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
832}
833
[email protected]a2176792011-05-08 19:30:49834bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09835 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19836 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20837 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32838 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20839 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05840 return io_data->GetCookieSettings()->
841 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49842}
843
[email protected]ed24fad2011-05-10 22:44:01844bool ChromeContentBrowserClient::AllowGetCookie(
845 const GURL& url,
846 const GURL& first_party,
847 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20848 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01849 int render_process_id,
850 int render_view_id) {
851 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20852 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05853 bool allow = io_data->GetCookieSettings()->
854 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01855
[email protected]8093a542011-05-13 07:29:32856 BrowserThread::PostTask(
857 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03858 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
859 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01860 return allow;
861}
862
863bool ChromeContentBrowserClient::AllowSetCookie(
864 const GURL& url,
865 const GURL& first_party,
866 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20867 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01868 int render_process_id,
869 int render_view_id,
870 net::CookieOptions* options) {
871 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20872 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05873 CookieSettings* cookie_settings = io_data->GetCookieSettings();
874 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
875
876 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09877 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01878
[email protected]8093a542011-05-13 07:29:32879 BrowserThread::PostTask(
880 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03881 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
882 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01883 return allow;
884}
885
[email protected]d5a19162011-06-30 18:51:54886bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20887 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54888 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20889 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26890
891 if (!io_data->clear_local_state_on_exit()->GetValue())
892 return true;
893
[email protected]068b7b52012-02-27 12:41:44894 // Disable clearing the local state on exit if the browsing session is going
[email protected]1848cdc2012-02-17 10:48:26895 // to be restored on the next startup.
896 SessionStartupPref::Type startup_pref =
897 SessionStartupPref::PrefValueToType(
898 io_data->session_startup_pref()->GetValue());
899 return (startup_pref == SessionStartupPref::LAST &&
[email protected]068b7b52012-02-27 12:41:44900 !CommandLine::ForCurrentProcess()->HasSwitch(
901 switches::kDisableRestoreSessionState));
[email protected]d5a19162011-06-30 18:51:54902}
903
[email protected]5c5a88e2011-11-12 00:45:35904bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35905 const GURL& url,
906 const string16& name,
907 const string16& display_name,
908 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20909 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48910 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35911 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20912 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35913 CookieSettings* cookie_settings = io_data->GetCookieSettings();
914 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
915
[email protected]62151052012-02-01 18:40:48916 // Record access to database for potential display in UI.
917 std::vector<std::pair<int, int> >::const_iterator i;
918 for (i = render_views.begin(); i != render_views.end(); ++i) {
919 BrowserThread::PostTask(
920 BrowserThread::UI, FROM_HERE,
921 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
922 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35923 }
924
925 return allow;
926}
927
928bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35929 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20930 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48931 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35932 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20933 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35934 CookieSettings* cookie_settings = io_data->GetCookieSettings();
935 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
936
[email protected]62151052012-02-01 18:40:48937 // Record access to file system for potential display in UI.
938 std::vector<std::pair<int, int> >::const_iterator i;
939 for (i = render_views.begin(); i != render_views.end(); ++i) {
940 BrowserThread::PostTask(
941 BrowserThread::UI, FROM_HERE,
942 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
943 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35944 }
945
946 return allow;
947}
948
[email protected]7c5ff9a2012-03-02 07:42:49949bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
950 const GURL& url,
951 const string16& name,
952 content::ResourceContext* context,
953 const std::vector<std::pair<int, int> >& render_views) {
954 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
955 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
956 CookieSettings* cookie_settings = io_data->GetCookieSettings();
957 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
958
959 // Record access to IndexedDB for potential display in UI.
960 std::vector<std::pair<int, int> >::const_iterator i;
961 for (i = render_views.begin(); i != render_views.end(); ++i) {
962 BrowserThread::PostTask(
963 BrowserThread::UI, FROM_HERE,
964 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
965 i->first, i->second, url, name, !allow));
966 }
967
968 return allow;
969}
970
[email protected]6133f922011-07-01 21:34:34971net::URLRequestContext*
972ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20973 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34974 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
975 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20976 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34977 return io_data->extensions_request_context();
978 }
979
980 return NULL;
981}
982
[email protected]317f96c92011-05-31 06:53:41983QuotaPermissionContext*
984ChromeContentBrowserClient::CreateQuotaPermissionContext() {
985 return new ChromeQuotaPermissionContext();
986}
987
[email protected]a0ce3282011-08-19 20:49:52988void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42989 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42990}
991
[email protected]a0ce3282011-08-19 20:49:52992void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52993 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52994}
995
[email protected]848dd042011-06-04 18:24:03996void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:17997 int render_process_id,
998 int render_view_id,
999 int cert_error,
1000 const net::SSLInfo& ssl_info,
1001 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031002 bool overridable,
[email protected]4cf611e32012-02-13 16:06:171003 const base::Callback<void(bool)>& callback,
1004 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411005 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131006 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171007 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411008 if (!tab) {
1009 NOTREACHED();
1010 return;
1011 }
1012 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501013 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301014 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091015 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411016 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171017 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411018 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171019 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411020 return;
1021 }
1022 }
1023
1024 // Otherwise, display an SSL blocking page.
[email protected]4cf611e32012-02-13 16:06:171025 new SSLBlockingPage(
1026 tab, cert_error, ssl_info, request_url, overridable, callback);
[email protected]848dd042011-06-04 18:24:031027}
1028
[email protected]c99c442e2011-08-24 11:37:301029void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451030 int render_process_id,
1031 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401032 const net::HttpNetworkSession* network_session,
1033 net::SSLCertRequestInfo* cert_request_info,
1034 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131035 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451036 render_process_id, render_view_id);
1037 if (!tab) {
1038 NOTREACHED();
1039 return;
1040 }
1041
[email protected]6786bf402011-12-03 15:19:451042 GURL requesting_url("https://" + cert_request_info->host_and_port);
1043 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1044 << cert_request_info->host_and_port;
1045
[email protected]627e0512011-12-21 22:55:301046 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451047 scoped_ptr<Value> filter(
1048 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1049 requesting_url,
1050 requesting_url,
1051 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1052 std::string(), NULL));
1053
1054 if (filter.get()) {
1055 // Try to automatically select a client certificate.
1056 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1057 DictionaryValue* filter_dict =
1058 static_cast<DictionaryValue*>(filter.get());
1059
1060 const std::vector<scoped_refptr<net::X509Certificate> >&
1061 all_client_certs = cert_request_info->client_certs;
1062 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1063 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1064 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401065 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451066 return;
1067 }
1068 }
1069 } else {
1070 NOTREACHED();
1071 }
1072 }
1073
[email protected]8ec26472011-06-06 16:52:451074 TabContentsWrapper* wrapper =
1075 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451076 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131077 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451078 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141079 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401080 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451081 return;
1082 }
[email protected]7a593db2012-02-13 21:19:401083 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1084 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451085}
1086
1087void ChromeContentBrowserClient::AddNewCertificate(
1088 net::URLRequest* request,
1089 net::X509Certificate* cert,
1090 int render_process_id,
1091 int render_view_id) {
1092 // The handler will run the UI and delete itself when it's finished.
1093 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1094}
1095
[email protected]a93670ab2012-02-24 03:46:391096void ChromeContentBrowserClient::RequestMediaAccessPermission(
1097 const content::MediaStreamRequest* request,
1098 const content::MediaResponseCallback& callback) {
1099 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1100
[email protected]117b6b42012-02-29 09:11:081101 WebContents* contents = tab_util::GetWebContentsByID(
1102 request->render_process_id, request->render_view_id);
1103 if (!contents) {
1104 // Abort, if the tab was closed after the request was made but before we
1105 // got to this point.
1106 callback.Run(content::MediaStreamDevices());
1107 return;
1108 }
1109
1110 TabContentsWrapper* tab =
1111 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1112 DCHECK(tab);
1113
1114 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1115 InfoBarDelegate* old_infobar = NULL;
1116 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1117 old_infobar =
1118 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfobarDelegate();
1119 }
1120
[email protected]3bc518b2012-03-09 03:01:501121#if defined(TOOLKIT_VIEWS) || defined(OS_LINUX)
[email protected]117b6b42012-02-29 09:11:081122 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1123 request,
1124 callback);
1125 if (old_infobar)
1126 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1127 else
1128 infobar_helper->AddInfoBar(infobar);
[email protected]3bc518b2012-03-09 03:01:501129#elif defined(OS_MACOSX)
1130 // TODO(macourteau): UI is not implemented yet for OS X. Fallback to
[email protected]117b6b42012-02-29 09:11:081131 // the default behaviour and allow access to the first device of each
1132 // requested type.
1133 content::MediaStreamDevices devices;
[email protected]a93670ab2012-02-24 03:46:391134 for (content::MediaStreamDeviceMap::const_iterator it =
1135 request->devices.begin(); it != request->devices.end(); ++it) {
[email protected]6c6415a2012-03-01 17:17:281136 if (!it->second.empty())
1137 devices.push_back(*it->second.begin());
[email protected]a93670ab2012-02-24 03:46:391138 }
1139
[email protected]a93670ab2012-02-24 03:46:391140 callback.Run(devices);
[email protected]3bc518b2012-03-09 03:01:501141#endif // TOOLKIT_VIEWS || OS_LINUX
[email protected]a93670ab2012-02-24 03:46:391142}
1143
[email protected]941623e2011-06-07 23:06:041144void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1145 const GURL& source_origin,
1146 int callback_context,
1147 int render_process_id,
1148 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111149#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041150 RenderViewHost* rvh = RenderViewHost::FromID(
1151 render_process_id, render_view_id);
1152 if (!rvh) {
1153 NOTREACHED();
1154 return;
1155 }
1156
[email protected]9f76c1e2012-03-05 15:15:581157 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301158 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041159 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371160 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041161 service->RequestPermission(
1162 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131163 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111164#else
1165 NOTIMPLEMENTED();
1166#endif
[email protected]941623e2011-06-07 23:06:041167}
1168
1169WebKit::WebNotificationPresenter::Permission
1170 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021171 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201172 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021173 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111174#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201176 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021177 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1178 source_origin, render_process_id,
1179 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041180 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041181
1182 // Fall back to the regular notification preferences, which works on an
1183 // origin basis.
1184 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371185 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041186 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111187#else
1188 return WebKit::WebNotificationPresenter::PermissionAllowed;
1189#endif
[email protected]941623e2011-06-07 23:06:041190}
1191
1192void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171193 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041194 int render_process_id,
1195 int render_view_id,
1196 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111197#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041198 RenderViewHost* rvh = RenderViewHost::FromID(
1199 render_process_id, render_view_id);
1200 if (!rvh) {
1201 NOTREACHED();
1202 return;
1203 }
1204
[email protected]9f76c1e2012-03-05 15:15:581205 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301206 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041207 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371208 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041209 service->ShowDesktopNotification(
1210 params, render_process_id, render_view_id,
1211 worker ? DesktopNotificationService::WorkerNotification :
1212 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111213#else
1214 NOTIMPLEMENTED();
1215#endif
[email protected]941623e2011-06-07 23:06:041216}
1217
1218void ChromeContentBrowserClient::CancelDesktopNotification(
1219 int render_process_id,
1220 int render_view_id,
1221 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111222#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041223 RenderViewHost* rvh = RenderViewHost::FromID(
1224 render_process_id, render_view_id);
1225 if (!rvh) {
1226 NOTREACHED();
1227 return;
1228 }
1229
[email protected]9f76c1e2012-03-05 15:15:581230 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301231 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041232 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371233 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041234 service->CancelDesktopNotification(
1235 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111236#else
1237 NOTIMPLEMENTED();
1238#endif
[email protected]941623e2011-06-07 23:06:041239}
1240
[email protected]9f3fba52011-06-08 20:37:191241bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351242 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021243 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191244 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201245 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021246 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1248 // If the opener is trying to create a background window but doesn't have
1249 // the appropriate permission, fail the attempt.
1250 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201251 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531252 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1253
1254 // If the opener is not allowed to script its background window, then return
1255 // false so that the window.open call returns null. In this case, only
1256 // the manifest is permitted to create a background window.
1257 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1258 // return a recently installed Extension even if this CanCreateWindow call
1259 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]2b751a12012-03-06 03:00:351260 // because the permission check below will still fail. We must use the
1261 // full URL to find hosted apps, though, and not just the origin.
[email protected]7b54ca02012-03-02 18:06:531262 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351263 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531264 if (extension && !extension->allow_background_js_access())
1265 return false;
1266
1267 return map->SecurityOriginHasAPIPermission(
[email protected]34eec7ffe32011-11-02 23:49:021268 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191269 }
1270 return true;
1271}
1272
1273std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201274 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1276 // Check if it's an extension-created worker, in which case we want to use
1277 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201278 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191279 const Extension* extension =
1280 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1281 return extension ? extension->name() : std::string();
1282}
1283
[email protected]99907362012-01-11 05:41:401284void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1285 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171286}
1287
[email protected]c52b2892012-03-07 11:01:021288content::SpeechRecognitionManagerDelegate*
1289 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321290#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021291 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321292#else
1293 return NULL;
1294#endif
[email protected]66cfec62012-02-24 17:57:511295}
1296
[email protected]3cb054e62011-06-13 05:21:171297ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1298 return g_browser_process->clipboard();
1299}
1300
[email protected]ae6e9912011-07-27 01:18:281301net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1302 return g_browser_process->net_log();
1303}
1304
[email protected]32538d92011-08-25 00:09:231305AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1306 return new ChromeAccessTokenStore();
1307}
1308
[email protected]dbae6b02011-06-29 23:51:411309bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1310 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1311 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1312}
1313
[email protected]64d69de42012-02-06 00:19:541314void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321315 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061316 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581317 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061318 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061319
[email protected]64d69de42012-02-06 00:19:541320 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061321 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541322 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061323 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541324 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061325 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541326 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061327 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541328 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061329 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541330 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061331 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1332
1333 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541334 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061335 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541336 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061337 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541338 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061339 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541340 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061341 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541342 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061343 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541344 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061345
[email protected]64d69de42012-02-06 00:19:541346 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061347 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541348 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061349 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541350 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061351 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541352 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061353 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1354
[email protected]64d69de42012-02-06 00:19:541355 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061356
[email protected]64d69de42012-02-06 00:19:541357 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061358 prefs->GetBoolean(
1359 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541360 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061361 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541362 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061363 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1364 const DictionaryValue* inspector_settings =
1365 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1366 if (inspector_settings) {
1367 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1368 iter != inspector_settings->end_keys(); ++iter) {
1369 std::string value;
1370 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541371 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061372 std::make_pair(*iter, value));
1373 }
1374 }
[email protected]64d69de42012-02-06 00:19:541375 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061376
[email protected]64d69de42012-02-06 00:19:541377 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1378 web_prefs->javascript_enabled = false;
1379 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1380 web_prefs->web_security_enabled = false;
1381 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1382 web_prefs->plugins_enabled = false;
1383 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1384 web_prefs->java_enabled = false;
1385 web_prefs->loads_images_automatically =
1386 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061387
[email protected]64d69de42012-02-06 00:19:541388 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1389 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061390
[email protected]64d69de42012-02-06 00:19:541391 web_prefs->memory_info_enabled =
1392 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1393 web_prefs->allow_displaying_insecure_content =
1394 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1395 web_prefs->allow_running_insecure_content =
1396 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081397 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061398
[email protected]64d69de42012-02-06 00:19:541399 // The user stylesheet watcher may not exist in a testing profile.
1400 if (profile->GetUserStyleSheetWatcher()) {
1401 web_prefs->user_style_sheet_enabled = true;
1402 web_prefs->user_style_sheet_location =
1403 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1404 } else {
1405 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061406 }
1407
[email protected]b7e44ff2012-02-16 03:37:341408 web_prefs->asynchronous_spell_checking_enabled =
1409 CommandLine::ForCurrentProcess()->
1410 HasSwitch(switches::kEnableAsynchronousSpellChecking);
1411 web_prefs->unified_textchecker_enabled =
1412 web_prefs->asynchronous_spell_checking_enabled ||
1413 CommandLine::ForCurrentProcess()->
1414 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571415
[email protected]64d69de42012-02-06 00:19:541416 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061417 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541418 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061419 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541420 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061421 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1422
1423 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541424 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061425 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541426 web_prefs->default_encoding);
1427 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061428 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541429 web_prefs->default_encoding =
1430 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061431 }
[email protected]64d69de42012-02-06 00:19:541432 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061433
1434 ExtensionService* service = profile->GetExtensionService();
1435 if (service) {
1436 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581437 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061438 extension_webkit_preferences::SetPreferences(
[email protected]9f76c1e2012-03-05 15:15:581439 extension, rvh->GetDelegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061440 }
1441
[email protected]9f76c1e2012-03-05 15:15:581442 if (rvh->GetDelegate()->GetRenderViewType() ==
1443 chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541444 web_prefs->allow_scripts_to_close_windows = true;
[email protected]9f76c1e2012-03-05 15:15:581445 } else if (rvh->GetDelegate()->GetRenderViewType() ==
[email protected]f3986f82012-01-03 20:00:061446 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1447 // Disable all kinds of acceleration for background pages.
1448 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541449 web_prefs->force_compositing_mode = false;
1450 web_prefs->accelerated_compositing_enabled = false;
1451 web_prefs->accelerated_2d_canvas_enabled = false;
1452 web_prefs->accelerated_video_enabled = false;
1453 web_prefs->accelerated_painting_enabled = false;
1454 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061455 }
[email protected]2e21fe292012-03-02 22:52:321456
1457#if defined(FILE_MANAGER_EXTENSION)
1458 // Override the default of suppressing HW compositing for WebUI pages for the
1459 // file manager, which is implemented using WebUI but wants HW acceleration
1460 // for video decode & render.
1461 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1462 web_prefs->accelerated_compositing_enabled = true;
1463 web_prefs->accelerated_2d_canvas_enabled = true;
1464 }
1465#endif
[email protected]181a95ee2011-07-12 19:26:361466}
1467
1468void ChromeContentBrowserClient::UpdateInspectorSetting(
1469 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061470 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581471 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061472 DictionaryPrefUpdate update(
1473 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1474 prefs::kWebKitInspectorSettings);
1475 DictionaryValue* inspector_settings = update.Get();
1476 inspector_settings->SetWithoutPathExpansion(key,
1477 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361478}
1479
1480void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061481 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581482 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061483 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1484 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361485}
1486
[email protected]b8148ac2011-07-13 22:03:251487void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1488 BrowserURLHandler* handler) {
1489 // Add the default URL handlers.
1490 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1491 BrowserURLHandler::null_handler());
1492 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1493 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1494
[email protected]b3adbd02011-11-30 22:23:271495 // about: handler. Must come before chrome: handler, since it will
1496 // rewrite about: urls to chrome: URLs and then expect chrome: to
1497 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251498 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1499 BrowserURLHandler::null_handler());
1500 // chrome: & friends.
1501 handler->AddHandlerPair(&HandleWebUI,
1502 BrowserURLHandler::null_handler());
1503}
1504
1505void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371506 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581507 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251508 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1509 BrowsingDataRemover::EVERYTHING,
1510 base::Time());
1511 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1512 // BrowsingDataRemover takes care of deleting itself when done.
1513}
1514
1515void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371516 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581517 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251518 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1519 BrowsingDataRemover::EVERYTHING,
1520 base::Time());
[email protected]dceaa912011-09-06 17:17:231521 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251522 remover->Remove(remove_mask);
1523 // BrowsingDataRemover takes care of deleting itself when done.
1524}
1525
[email protected]e1d16eb92011-08-18 23:19:321526FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1527 return download_util::GetDefaultDownloadDirectory();
1528}
1529
[email protected]c9b6eb62011-10-18 20:49:391530std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1531 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1532}
1533
[email protected]a658d452012-03-02 12:45:291534bool ChromeContentBrowserClient::AllowSocketAPI(
1535 content::BrowserContext* browser_context, const GURL& url) {
1536 if (!url.is_valid())
1537 return false;
1538
1539 std::string host = url.host();
1540 if (allowed_socket_origins_.count(host))
1541 return true;
1542
[email protected]f237c0f2012-03-10 07:49:101543 // Need to check this now and not on construction because otherwise it won't
1544 // work with browser_tests.
1545 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1546 std::string allowed_list =
1547 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
1548 if (!allowed_list.empty()) {
1549 StringTokenizer t(allowed_list, ",");
1550 while (t.GetNext()) {
1551 if (t.token() == host)
1552 return true;
1553 }
1554 }
1555
[email protected]a658d452012-03-02 12:45:291556 Profile* profile = Profile::FromBrowserContext(browser_context);
1557 if (!profile || !profile->GetExtensionService())
1558 return false;
1559
1560 const Extension* extension = profile->GetExtensionService()->extensions()->
1561 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1562 if (!extension)
1563 return false;
1564
1565 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1566 return true;
1567
1568 return false;
[email protected]e461da2f2012-02-16 19:06:401569}
1570
[email protected]e60c0232011-11-11 19:56:351571#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301572int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521573 const CommandLine& command_line) {
[email protected]6e677a342012-02-11 01:21:141574#if defined(OS_ANDROID)
1575 // TODO(carlosvaldivia): Upstream breakpad code for Android and remove this
1576 // fork. http://crbug.com/113560
1577 NOTIMPLEMENTED();
1578#else
[email protected]718eab62011-10-05 21:16:521579 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071580 ExtensionCrashHandlerHostLinux* crash_handler =
1581 ExtensionCrashHandlerHostLinux::GetInstance();
1582 return crash_handler->GetDeathSignalSocket();
1583 }
1584
[email protected]718eab62011-10-05 21:16:521585 std::string process_type =
1586 command_line.GetSwitchValueASCII(switches::kProcessType);
1587
1588 if (process_type == switches::kRendererProcess)
1589 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1590
[email protected]b80f68432011-05-02 17:22:301591 if (process_type == switches::kPluginProcess)
1592 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1593
1594 if (process_type == switches::kPpapiPluginProcess)
1595 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1596
1597 if (process_type == switches::kGpuProcess)
1598 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
[email protected]6e677a342012-02-11 01:21:141599#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:301600
1601 return -1;
1602}
[email protected]e60c0232011-11-11 19:56:351603#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301604
[email protected]4a65826d2011-08-25 16:04:011605#if defined(OS_WIN)
1606const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1607 return chrome::kBrowserResourcesDll;
1608}
1609#endif
1610
[email protected]37a72af2011-06-13 05:42:011611#if defined(USE_NSS)
1612crypto::CryptoModuleBlockingPasswordDelegate*
1613 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1614 const GURL& url) {
1615 return browser::NewCryptoModuleBlockingDialogDelegate(
1616 browser::kCryptoModulePasswordKeygen, url.host());
1617}
1618#endif
1619
[email protected]d977f9c2011-03-14 16:10:261620} // namespace chrome