blob: f3346123f4807576329b341276b251ec4d7f5638 [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]2b33dcd02012-03-18 01:34:1628#include "chrome/browser/extensions/api/web_request/web_request_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]dc04be7c2012-03-15 23:57:49125#if defined(USE_ASH)
126#include "chrome/browser/chrome_browser_main_extra_parts_ash.h"
127#endif
128
[email protected]e60c0232011-11-11 19:56:35129#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30130#include "base/linux_util.h"
131#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43132#endif
[email protected]b80f68432011-05-02 17:22:30133
[email protected]38b098f2012-03-14 21:11:57134#if defined(TOOLKIT_GTK)
135#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_gtk.h"
[email protected]74313b42011-08-24 16:51:32136#endif
[email protected]37a72af2011-06-13 05:42:01137#if defined(USE_NSS)
138#include "chrome/browser/ui/crypto_module_password_dialog.h"
139#endif
140
[email protected]c8c77182011-12-21 15:04:47141using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39142using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31143using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59144using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00145using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11146using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33147using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13148using content::WebContents;
[email protected]631bb742011-11-02 11:29:39149
[email protected]c5dbef02011-05-13 05:06:09150namespace {
151
[email protected]e461da2f2012-02-16 19:06:40152const char* kPredefinedAllowedSocketOrigins[] = {
153 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
154 "pnhechapfaindjhompbnflcldabbghjo" // HTerm App (SSH Client)
155};
156
[email protected]b8148ac2011-07-13 22:03:25157// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42158bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50159 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
160 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25161 return false;
162
[email protected]fe69558d2012-03-12 11:34:49163#if defined(OS_CHROMEOS)
164 // Special case : in ChromeOS in Guest mode bookmarks and history are
165 // disabled for security reasons. New tab page explains the reasons, so
166 // we redirect user to new tab page.
167 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
168 if (url->SchemeIs(chrome::kChromeUIScheme) &&
169 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
170 url->DomainIs(chrome::kChromeUIHistoryHost))) {
171 // Rewrite with new tab URL
172 *url = GURL(chrome::kChromeUINewTabURL);
173 }
174 }
175#endif
176
[email protected]b8148ac2011-07-13 22:03:25177 // Special case the new tab page. In older versions of Chrome, the new tab
178 // page was hosted at chrome-internal:<blah>. This might be in people's saved
179 // sessions or bookmarks, so we say any URL with that scheme triggers the new
180 // tab page.
181 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
182 // Rewrite it with the proper new tab URL.
183 *url = GURL(chrome::kChromeUINewTabURL);
184 }
185
186 return true;
187}
188
[email protected]8d3132f62011-10-12 07:13:42189// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
190// below. Extension, and isolated apps require different privileges to be
191// granted to their RenderProcessHosts. This classification allows us to make
192// sure URLs are served by hosts with the right set of privileges.
193enum RenderProcessHostPrivilege {
194 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45195 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42196 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45197 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42198};
199
200RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
201 const GURL& url,
202 ExtensionService* service) {
203 // Default to a normal renderer cause it is lower privileged. This should only
204 // occur if the URL on a site instance is either malformed, or uninitialized.
205 // If it is malformed, then there is no need for better privileges anyways.
206 // If it is uninitialized, but eventually settles on being an a scheme other
207 // than normal webrenderer, the navigation logic will correct us out of band
208 // anyways.
209 if (!url.is_valid())
210 return PRIV_NORMAL;
211
212 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44213 const Extension* extension =
214 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45215 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42216 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45217 if (extension && extension->is_hosted_app())
218 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42219
220 return PRIV_EXTENSION;
221 }
222
223 return PRIV_NORMAL;
224}
225
226RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30227 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46228 extensions::ProcessMap* process_map,
229 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46230 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30231 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46232 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21233 return PRIV_NORMAL;
234
[email protected]6f371442011-11-09 06:45:46235 for (std::set<std::string>::iterator iter = extension_ids.begin();
236 iter != extension_ids.end(); ++iter) {
237 const Extension* extension = service->GetExtensionById(*iter, false);
238 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42239 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45240 if (extension && extension->is_hosted_app())
241 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42242 }
243
[email protected]676f6ab2011-10-19 20:23:21244 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42245}
246
[email protected]eec0b33c2011-12-05 22:09:45247bool IsIsolatedAppInProcess(const GURL& site_url,
248 content::RenderProcessHost* process_host,
249 extensions::ProcessMap* process_map,
250 ExtensionService* service) {
251 std::set<std::string> extension_ids =
252 process_map->GetExtensionsInProcess(process_host->GetID());
253 if (extension_ids.empty())
254 return false;
255
256 for (std::set<std::string>::iterator iter = extension_ids.begin();
257 iter != extension_ids.end(); ++iter) {
258 const Extension* extension = service->GetExtensionById(*iter, false);
259 if (extension &&
260 extension->is_storage_isolated() &&
261 extension->url() == site_url)
262 return true;
263 }
264
265 return false;
266}
267
[email protected]6786bf402011-12-03 15:19:45268bool CertMatchesFilter(const net::X509Certificate& cert,
269 const base::DictionaryValue& filter) {
270 // TODO(markusheintz): This is the minimal required filter implementation.
271 // Implement a better matcher.
272
273 // An empty filter matches any client certificate since no requirements are
274 // specified at all.
275 if (filter.empty())
276 return true;
277
278 std::string common_name;
279 if (filter.GetString("ISSUER.CN", &common_name) &&
280 (cert.issuer().common_name == common_name)) {
281 return true;
282 }
283 return false;
284}
285
[email protected]f3986f82012-01-03 20:00:06286// Fills |map| with the per-script font prefs under path |map_name|.
287void FillFontFamilyMap(const PrefService* prefs,
288 const char* map_name,
289 WebPreferences::ScriptFontFamilyMap* map) {
290 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
291 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
292 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
293 std::string font_family = prefs->GetString(pref_name.c_str());
294 if (!font_family.empty())
295 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
296 }
297}
298
[email protected]9dbfff12011-07-01 19:37:07299} // namespace
[email protected]c5dbef02011-05-13 05:06:09300
[email protected]d977f9c2011-03-14 16:10:26301namespace chrome {
302
[email protected]e461da2f2012-02-16 19:06:40303ChromeContentBrowserClient::ChromeContentBrowserClient() {
304 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
305 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40306}
307
308ChromeContentBrowserClient::~ChromeContentBrowserClient() {
309}
310
[email protected]50462bf02011-11-21 19:13:31311content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
312 const content::MainFunctionParams& parameters) {
313 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30314 // Construct the Main browser parts based on the OS type.
315#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31316 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04317#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31318 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30319#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31320 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35321#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31322 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14323#elif defined(OS_ANDROID)
324 // Do nothing for Android.
325 // TODO(klobag): Android initialization should use the
326 // *BrowserMainParts class-hierarchy for setting up custom initialization.
327 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30328#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31329 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04330#else
[email protected]b48c9182011-10-26 18:03:30331 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31332 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30333#endif
334
[email protected]c7480942011-11-08 19:18:27335 // Construct additional browser parts. Stages are called in the order in
336 // which they are added.
[email protected]b48c9182011-10-26 18:03:30337#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31338 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04339#endif
[email protected]c7480942011-11-08 19:18:27340
341#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31342 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27343#endif
344
345#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31346 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27347#endif
348
[email protected]dc04be7c2012-03-15 23:57:49349#if defined(USE_ASH)
350 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
351#endif
352
[email protected]50462bf02011-11-21 19:13:31353 return main_parts;
[email protected]f967b722011-09-07 00:58:04354}
355
[email protected]38b098f2012-03-14 21:11:57356content::WebContentsView*
357 ChromeContentBrowserClient::OverrideCreateWebContentsView(
358 WebContents* web_contents) {
359#if defined(TOOLKIT_VIEWS)
[email protected]8dad546b2012-01-17 21:47:35360 return new TabContentsViewViews(web_contents);
[email protected]38b098f2012-03-14 21:11:57361#endif
362 return NULL;
363}
364
365content::WebContentsViewDelegate*
366 ChromeContentBrowserClient::GetWebContentsViewDelegate(
367 content::WebContents* web_contents) {
368#if defined(OS_WIN) && !defined(USE_AURA)
369 return new ChromeWebContentsViewDelegateWin(web_contents);
370#elif defined(TOOLKIT_GTK)
371 return new ChromeWebContentsViewDelegateGtk(web_contents);
[email protected]74313b42011-08-24 16:51:32372#elif defined(OS_MACOSX)
[email protected]38b098f2012-03-14 21:11:57373 return
374 chrome_web_contents_view_delegate_mac::CreateWebContentsViewDelegateMac(
375 web_contents);
[email protected]74313b42011-08-24 16:51:32376#else
[email protected]38b098f2012-03-14 21:11:57377 return NULL;
[email protected]74313b42011-08-24 16:51:32378#endif
379}
380
[email protected]f364d1392011-04-08 21:03:10381void ChromeContentBrowserClient::RenderViewHostCreated(
382 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46383
[email protected]9f76c1e2012-03-05 15:15:58384 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46385 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02386 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46387
388 new ChromeRenderViewHostObserver(render_view_host,
389 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10390 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26391}
392
[email protected]f3b1a082011-11-18 00:34:30393void ChromeContentBrowserClient::RenderProcessHostCreated(
394 content::RenderProcessHost* host) {
395 int id = host->GetID();
396 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
397 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02398 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30399 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03400#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30401 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03402#endif
[email protected]f3b1a082011-11-18 00:34:30403 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02404 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30405 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56406#if defined(OS_MACOSX)
407 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
408#endif
[email protected]f3b1a082011-11-18 00:34:30409 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03410 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38411
[email protected]2ccf45c2011-08-19 23:35:50412 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
413 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07414
415 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56416
417 RendererContentSettingRules rules;
418 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
419 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14420}
421
[email protected]863f70a2012-01-27 02:05:50422content::WebUIControllerFactory*
423 ChromeContentBrowserClient::GetWebUIControllerFactory() {
424 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56425}
426
[email protected]3d7474ff2011-07-27 17:47:37427GURL ChromeContentBrowserClient::GetEffectiveURL(
428 content::BrowserContext* browser_context, const GURL& url) {
429 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08430 // Get the effective URL for the given actual URL. If the URL is part of an
431 // installed app, the effective URL is an extension URL with the ID of that
432 // extension as the host. This has the effect of grouping apps together in
433 // a common SiteInstance.
434 if (!profile || !profile->GetExtensionService())
435 return url;
436
[email protected]615d88f2011-12-13 01:47:44437 const Extension* extension = profile->GetExtensionService()->extensions()->
438 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08439 if (!extension)
440 return url;
441
[email protected]15877ca2011-11-18 22:40:52442 // Bookmark apps do not use the hosted app process model, and should be
443 // treated as normal URLs.
444 if (extension->from_bookmark())
445 return url;
446
[email protected]36fb2c7c2011-04-04 15:49:08447 // If the URL is part of an extension's web extent, convert it to an
448 // extension URL.
449 return extension->GetResourceURL(url.path());
450}
451
[email protected]056ad2a2011-07-12 02:13:55452bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37453 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55454 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52455 // Because we expect to use the effective URL, URLs for hosted apps (apart
456 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55457 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
458 return false;
459
[email protected]3d7474ff2011-07-27 17:47:37460 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55461 if (!profile || !profile->GetExtensionService())
462 return false;
463
[email protected]615d88f2011-12-13 01:47:44464 const Extension* extension = profile->GetExtensionService()->extensions()->
465 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55466 if (!extension)
467 return false;
468
469 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53470 // permission, or that does not allow JavaScript access to the background
471 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55472 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53473 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
474 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
475 !extension->allow_background_js_access()) {
476 return false;
477 }
478 }
[email protected]056ad2a2011-07-12 02:13:55479
[email protected]7b54ca02012-03-02 18:06:53480 // Hosted apps that have script access to their background page must use
481 // process per site, since all instances can make synchronous calls to the
482 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55483 return true;
484}
485
[email protected]46fb9442011-12-09 17:57:47486bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
487 return ProfileIOData::IsHandledURL(url);
488}
489
[email protected]2a5221b2011-09-27 23:07:31490bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30491 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31492 const GURL& site_url) {
493 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30494 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42495 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46496 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31497
[email protected]ffa97602011-11-17 17:55:52498 // Don't allow the Task Manager to share a process with anything else.
499 // Otherwise it can affect the renderers it is observing.
500 // Note: we could create another RenderProcessHostPrivilege bucket for
501 // this to allow multiple chrome://tasks instances to share, but that's
502 // a very unlikely case without serious consequences.
503 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
504 return false;
505
[email protected]8d3132f62011-10-12 07:13:42506 // These may be NULL during tests. In that case, just assume any site can
507 // share any host.
[email protected]6f371442011-11-09 06:45:46508 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31509 return true;
510
[email protected]a8c269a2011-10-25 20:17:22511 // Experimental:
512 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
513 // to share a renderer process. (We could allow pages from the same site or
514 // extensions of the same type to share, if we knew what the given process
515 // was dedicated to. Allowing no sharing is simpler for now.) This may
516 // cause resource exhaustion issues if too many sites are open at once.
517 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
518 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
519 return false;
520
[email protected]eec0b33c2011-12-05 22:09:45521 // An isolated app is only allowed to share with the exact same app in order
522 // to provide complete renderer process isolation. This also works around
523 // issue http://crbug.com/85588, where different isolated apps in the same
524 // process would end up using the first app's storage contexts.
525 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42526 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45527 if (privilege_required == PRIV_ISOLATED)
528 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
529
530 // Otherwise, just make sure the process privilege matches the privilege
531 // required by the site.
532 return GetProcessPrivilege(process_host, process_map, service) ==
533 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31534}
535
[email protected]76411f412012-02-22 18:56:06536// This function is trying to limit the amount of processes used by extensions
537// with background pages. It uses a globally set percentage of processes to
538// run such extensions and if the limit is exceeded, it returns true, to
539// indicate to the content module to group extensions together.
540bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
541 content::BrowserContext* browser_context, const GURL& url) {
542 // It has to be a valid URL for us to check for an extension.
543 if (!url.is_valid())
544 return false;
545
546 Profile* profile = Profile::FromBrowserContext(browser_context);
547 ExtensionService* service = profile->GetExtensionService();
548 if (!service)
549 return false;
550
551 // We have to have a valid extension with background page to proceed.
552 const Extension* extension =
553 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
554 if (!extension)
555 return false;
556 if (!extension->has_background_page())
557 return false;
558
559 std::set<int> process_ids;
560 size_t max_process_count =
561 content::RenderProcessHost::GetMaxRendererProcessCount();
562
563 // Go through all profiles to ensure we have total count of extension
564 // processes containing background pages, otherwise one profile can
565 // starve the other.
566 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
567 GetLoadedProfiles();
568 for (size_t i = 0; i < profiles.size(); ++i) {
569 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
570 for (ExtensionProcessManager::const_iterator iter = epm->begin();
571 iter != epm->end();
572 ++iter) {
573 ExtensionHost* host = *iter;
574 if (host->extension()->has_background_page()) {
575 process_ids.insert(host->render_process_host()->GetID());
576 }
577 }
578 }
579
580 if (process_ids.size() >
581 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
582 return true;
583 }
584
585 return false;
586}
587
[email protected]6f371442011-11-09 06:45:46588void ChromeContentBrowserClient::SiteInstanceGotProcess(
589 SiteInstance* site_instance) {
590 CHECK(site_instance->HasProcess());
591
592 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02593 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46594 ExtensionService* service = profile->GetExtensionService();
595 if (!service)
596 return;
597
598 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44599 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33600 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46601 if (!extension)
602 return;
603
[email protected]6bc04fd82011-12-04 02:29:35604 service->process_map()->Insert(extension->id(),
605 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33606 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46607 BrowserThread::PostTask(
608 BrowserThread::IO, FROM_HERE,
609 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]e15be2b2012-03-09 08:42:11610 profile->GetExtensionInfoMap(),
[email protected]6f371442011-11-09 06:45:46611 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35612 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33613 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46614}
615
616void ChromeContentBrowserClient::SiteInstanceDeleting(
617 SiteInstance* site_instance) {
618 if (!site_instance->HasProcess())
619 return;
620
621 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02622 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46623 ExtensionService* service = profile->GetExtensionService();
624 if (!service)
625 return;
626
627 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44628 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33629 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46630 if (!extension)
631 return;
632
[email protected]6bc04fd82011-12-04 02:29:35633 service->process_map()->Remove(extension->id(),
634 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33635 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46636 BrowserThread::PostTask(
637 BrowserThread::IO, FROM_HERE,
638 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]e15be2b2012-03-09 08:42:11639 profile->GetExtensionInfoMap(),
[email protected]6f371442011-11-09 06:45:46640 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35641 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33642 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46643}
644
[email protected]e3daf3c2011-10-05 21:17:08645bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
646 const GURL& current_url,
647 const GURL& new_url) {
648 if (current_url.is_empty()) {
649 // Always choose a new process when navigating to extension URLs. The
650 // process grouping logic will combine all of a given extension's pages
651 // into the same process.
652 if (new_url.SchemeIs(chrome::kExtensionScheme))
653 return true;
654
655 return false;
656 }
657
658 // Also, we must switch if one is an extension and the other is not the exact
659 // same extension.
660 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
661 new_url.SchemeIs(chrome::kExtensionScheme)) {
662 if (current_url.GetOrigin() != new_url.GetOrigin())
663 return true;
664 }
665
666 return false;
667}
668
[email protected]763ec4ca2011-04-29 15:48:12669std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
670 const std::string& alias_name) {
671 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
672}
673
[email protected]b80f68432011-05-02 17:22:30674void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
675 CommandLine* command_line, int child_process_id) {
676#if defined(USE_LINUX_BREAKPAD)
677 if (IsCrashReporterEnabled()) {
678 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
679 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
680 }
681#elif defined(OS_MACOSX)
682 if (IsCrashReporterEnabled()) {
683 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
684 child_process_logging::GetClientId());
685 }
686#endif // OS_MACOSX
687
[email protected]f1933792011-06-14 00:49:34688 if (logging::DialogsAreSuppressed())
689 command_line->AppendSwitch(switches::kNoErrorDialogs);
690
[email protected]b80f68432011-05-02 17:22:30691 std::string process_type =
692 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17693 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52694 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30695 FilePath user_data_dir =
696 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
697 if (!user_data_dir.empty())
698 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
699#if defined(OS_CHROMEOS)
700 const std::string& login_profile =
701 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
702 if (!login_profile.empty())
703 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
704#endif
705
[email protected]f3b1a082011-11-18 00:34:30706 content::RenderProcessHost* process =
707 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37708 if (process) {
709 Profile* profile = Profile::FromBrowserContext(
710 process->GetBrowserContext());
711 extensions::ProcessMap* process_map =
712 profile->GetExtensionService()->process_map();
713 if (process_map && process_map->Contains(process->GetID()))
714 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30715
[email protected]a8d851f82011-12-21 00:32:37716 PrefService* prefs = profile->GetPrefs();
717 // Currently this pref is only registered if applied via a policy.
718 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
719 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
720 // Turn this policy into a command line switch.
721 command_line->AppendSwitch(switches::kDisable3DAPIs);
722 }
[email protected]718eab62011-10-05 21:16:52723
[email protected]a8d851f82011-12-21 00:32:37724 // Disable client-side phishing detection in the renderer if it is
725 // disabled in the Profile preferences or the browser process.
726 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
727 !g_browser_process->safe_browsing_detection_service()) {
728 command_line->AppendSwitch(
729 switches::kDisableClientSidePhishingDetection);
730 }
[email protected]8c40da62011-07-13 22:58:46731 }
[email protected]47c7ec82012-01-18 03:29:21732 {
733 PrefService* local_state = g_browser_process->local_state();
734 if (local_state &&
735 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
736 command_line->AppendSwitch(switches::kRendererPrintPreview);
737 }
738 }
[email protected]4287a3d2011-06-13 23:56:51739
[email protected]47c7ec82012-01-18 03:29:21740 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51741 static const char* const kSwitchNames[] = {
742 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48743 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51744 switches::kAllowScriptingGallery,
745 switches::kAppsCheckoutURL,
746 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31747 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51748 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50749 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51750 switches::kDumpHistogramsOnExit,
[email protected]b7e44ff2012-02-16 03:37:34751 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21752 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13753 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51754 switches::kEnableCrxlessWebApps,
755 switches::kEnableExperimentalExtensionApis,
756 switches::kEnableInBrowserThumbnailing,
757 switches::kEnableIPCFuzzing,
758 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:48759 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53760 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51761 switches::kEnableWatchdog,
762 switches::kExperimentalSpellcheckerFeatures,
763 switches::kMemoryProfiling,
764 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04765 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51766 switches::kPpapiFlashArgs,
767 switches::kPpapiFlashInProcess,
768 switches::kPpapiFlashPath,
769 switches::kPpapiFlashVersion,
770 switches::kProfilingAtStart,
771 switches::kProfilingFile,
772 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51773 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38774 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51775 };
776
777 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
778 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17779 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38780 static const char* const kSwitchNames[] = {
781 switches::kEnableExperimentalExtensionApis,
782 switches::kWhitelistedExtensionID,
783 };
784
785 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
786 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51787 } else if (process_type == switches::kPluginProcess) {
788 static const char* const kSwitchNames[] = {
789 #if defined(OS_CHROMEOS)
790 switches::kLoginProfile,
791 #endif
792 switches::kMemoryProfiling,
793 switches::kSilentDumpOnDCHECK,
794 switches::kUserDataDir,
795 };
796
797 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
798 arraysize(kSwitchNames));
799 } else if (process_type == switches::kZygoteProcess) {
800 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51801 switches::kUserDataDir, // Make logs go to the right file.
802 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50803 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13804 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51805 switches::kPpapiFlashInProcess,
806 switches::kPpapiFlashPath,
807 switches::kPpapiFlashVersion,
808 };
809
810 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
811 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11812 } else if (process_type == switches::kGpuProcess) {
813 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
814 // because GPU is expected to be unreliable.
815 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
816 !command_line->HasSwitch(switches::kDisableBreakpad))
817 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30818 }
[email protected]6f08af82011-09-15 01:19:03819
820 // The command line switch kEnableBenchmarking needs to be specified along
821 // with the kEnableStatsTable switch to ensure that the stats table global
822 // is initialized correctly.
823 if (command_line->HasSwitch(switches::kEnableBenchmarking))
824 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30825}
826
827std::string ChromeContentBrowserClient::GetApplicationLocale() {
828 return g_browser_process->GetApplicationLocale();
829}
830
[email protected]597a867b2011-11-18 18:31:20831std::string ChromeContentBrowserClient::GetAcceptLangs(
832 content::BrowserContext* context) {
833 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37834 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08835}
836
[email protected]ac55e292011-06-24 05:16:08837SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22838 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08839 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
840}
841
[email protected]a2176792011-05-08 19:30:49842bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09843 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19844 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20845 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32846 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20847 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05848 return io_data->GetCookieSettings()->
849 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49850}
851
[email protected]ed24fad2011-05-10 22:44:01852bool ChromeContentBrowserClient::AllowGetCookie(
853 const GURL& url,
854 const GURL& first_party,
855 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20856 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01857 int render_process_id,
858 int render_view_id) {
859 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20860 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05861 bool allow = io_data->GetCookieSettings()->
862 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01863
[email protected]8093a542011-05-13 07:29:32864 BrowserThread::PostTask(
865 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03866 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
867 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01868 return allow;
869}
870
871bool ChromeContentBrowserClient::AllowSetCookie(
872 const GURL& url,
873 const GURL& first_party,
874 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20875 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01876 int render_process_id,
877 int render_view_id,
878 net::CookieOptions* options) {
879 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20880 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05881 CookieSettings* cookie_settings = io_data->GetCookieSettings();
882 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
883
884 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09885 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01886
[email protected]8093a542011-05-13 07:29:32887 BrowserThread::PostTask(
888 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03889 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
890 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01891 return allow;
892}
893
[email protected]d5a19162011-06-30 18:51:54894bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20895 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54896 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20897 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26898
899 if (!io_data->clear_local_state_on_exit()->GetValue())
900 return true;
901
[email protected]068b7b52012-02-27 12:41:44902 // Disable clearing the local state on exit if the browsing session is going
[email protected]1848cdc2012-02-17 10:48:26903 // to be restored on the next startup.
904 SessionStartupPref::Type startup_pref =
905 SessionStartupPref::PrefValueToType(
906 io_data->session_startup_pref()->GetValue());
907 return (startup_pref == SessionStartupPref::LAST &&
[email protected]068b7b52012-02-27 12:41:44908 !CommandLine::ForCurrentProcess()->HasSwitch(
909 switches::kDisableRestoreSessionState));
[email protected]d5a19162011-06-30 18:51:54910}
911
[email protected]5c5a88e2011-11-12 00:45:35912bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35913 const GURL& url,
914 const string16& name,
915 const string16& display_name,
916 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20917 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48918 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20920 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35921 CookieSettings* cookie_settings = io_data->GetCookieSettings();
922 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
923
[email protected]62151052012-02-01 18:40:48924 // Record access to database for potential display in UI.
925 std::vector<std::pair<int, int> >::const_iterator i;
926 for (i = render_views.begin(); i != render_views.end(); ++i) {
927 BrowserThread::PostTask(
928 BrowserThread::UI, FROM_HERE,
929 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
930 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35931 }
932
933 return allow;
934}
935
936bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35937 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20938 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48939 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35940 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20941 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35942 CookieSettings* cookie_settings = io_data->GetCookieSettings();
943 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
944
[email protected]62151052012-02-01 18:40:48945 // Record access to file system for potential display in UI.
946 std::vector<std::pair<int, int> >::const_iterator i;
947 for (i = render_views.begin(); i != render_views.end(); ++i) {
948 BrowserThread::PostTask(
949 BrowserThread::UI, FROM_HERE,
950 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
951 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35952 }
953
954 return allow;
955}
956
[email protected]7c5ff9a2012-03-02 07:42:49957bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
958 const GURL& url,
959 const string16& name,
960 content::ResourceContext* context,
961 const std::vector<std::pair<int, int> >& render_views) {
962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
963 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
964 CookieSettings* cookie_settings = io_data->GetCookieSettings();
965 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
966
967 // Record access to IndexedDB for potential display in UI.
968 std::vector<std::pair<int, int> >::const_iterator i;
969 for (i = render_views.begin(); i != render_views.end(); ++i) {
970 BrowserThread::PostTask(
971 BrowserThread::UI, FROM_HERE,
972 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
973 i->first, i->second, url, name, !allow));
974 }
975
976 return allow;
977}
978
[email protected]6133f922011-07-01 21:34:34979net::URLRequestContext*
980ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20981 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34982 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
983 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20984 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34985 return io_data->extensions_request_context();
986 }
987
988 return NULL;
989}
990
[email protected]317f96c92011-05-31 06:53:41991QuotaPermissionContext*
992ChromeContentBrowserClient::CreateQuotaPermissionContext() {
993 return new ChromeQuotaPermissionContext();
994}
995
[email protected]a0ce3282011-08-19 20:49:52996void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42997 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42998}
999
[email protected]a0ce3282011-08-19 20:49:521000void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521001 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521002}
1003
[email protected]848dd042011-06-04 18:24:031004void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171005 int render_process_id,
1006 int render_view_id,
1007 int cert_error,
1008 const net::SSLInfo& ssl_info,
1009 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031010 bool overridable,
[email protected]4cf611e32012-02-13 16:06:171011 const base::Callback<void(bool)>& callback,
1012 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411013 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131014 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171015 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411016 if (!tab) {
1017 NOTREACHED();
1018 return;
1019 }
1020 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501021 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301022 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091023 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411024 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171025 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411026 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171027 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411028 return;
1029 }
1030 }
1031
1032 // Otherwise, display an SSL blocking page.
[email protected]4cf611e32012-02-13 16:06:171033 new SSLBlockingPage(
1034 tab, cert_error, ssl_info, request_url, overridable, callback);
[email protected]848dd042011-06-04 18:24:031035}
1036
[email protected]c99c442e2011-08-24 11:37:301037void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451038 int render_process_id,
1039 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401040 const net::HttpNetworkSession* network_session,
1041 net::SSLCertRequestInfo* cert_request_info,
1042 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131043 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451044 render_process_id, render_view_id);
1045 if (!tab) {
1046 NOTREACHED();
1047 return;
1048 }
1049
[email protected]6786bf402011-12-03 15:19:451050 GURL requesting_url("https://" + cert_request_info->host_and_port);
1051 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1052 << cert_request_info->host_and_port;
1053
[email protected]627e0512011-12-21 22:55:301054 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451055 scoped_ptr<Value> filter(
1056 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1057 requesting_url,
1058 requesting_url,
1059 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1060 std::string(), NULL));
1061
1062 if (filter.get()) {
1063 // Try to automatically select a client certificate.
1064 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1065 DictionaryValue* filter_dict =
1066 static_cast<DictionaryValue*>(filter.get());
1067
1068 const std::vector<scoped_refptr<net::X509Certificate> >&
1069 all_client_certs = cert_request_info->client_certs;
1070 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1071 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1072 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401073 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451074 return;
1075 }
1076 }
1077 } else {
1078 NOTREACHED();
1079 }
1080 }
1081
[email protected]8ec26472011-06-06 16:52:451082 TabContentsWrapper* wrapper =
1083 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451084 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131085 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451086 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141087 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401088 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451089 return;
1090 }
[email protected]7a593db2012-02-13 21:19:401091 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1092 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451093}
1094
1095void ChromeContentBrowserClient::AddNewCertificate(
1096 net::URLRequest* request,
1097 net::X509Certificate* cert,
1098 int render_process_id,
1099 int render_view_id) {
1100 // The handler will run the UI and delete itself when it's finished.
1101 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1102}
1103
[email protected]a93670ab2012-02-24 03:46:391104void ChromeContentBrowserClient::RequestMediaAccessPermission(
1105 const content::MediaStreamRequest* request,
1106 const content::MediaResponseCallback& callback) {
1107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1108
[email protected]117b6b42012-02-29 09:11:081109 WebContents* contents = tab_util::GetWebContentsByID(
1110 request->render_process_id, request->render_view_id);
1111 if (!contents) {
1112 // Abort, if the tab was closed after the request was made but before we
1113 // got to this point.
1114 callback.Run(content::MediaStreamDevices());
1115 return;
1116 }
1117
1118 TabContentsWrapper* tab =
1119 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1120 DCHECK(tab);
1121
1122 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1123 InfoBarDelegate* old_infobar = NULL;
1124 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1125 old_infobar =
1126 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfobarDelegate();
1127 }
1128
[email protected]3bc518b2012-03-09 03:01:501129#if defined(TOOLKIT_VIEWS) || defined(OS_LINUX)
[email protected]117b6b42012-02-29 09:11:081130 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1131 request,
1132 callback);
1133 if (old_infobar)
1134 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1135 else
1136 infobar_helper->AddInfoBar(infobar);
[email protected]3bc518b2012-03-09 03:01:501137#elif defined(OS_MACOSX)
1138 // TODO(macourteau): UI is not implemented yet for OS X. Fallback to
[email protected]117b6b42012-02-29 09:11:081139 // the default behaviour and allow access to the first device of each
1140 // requested type.
1141 content::MediaStreamDevices devices;
[email protected]a93670ab2012-02-24 03:46:391142 for (content::MediaStreamDeviceMap::const_iterator it =
1143 request->devices.begin(); it != request->devices.end(); ++it) {
[email protected]6c6415a2012-03-01 17:17:281144 if (!it->second.empty())
1145 devices.push_back(*it->second.begin());
[email protected]a93670ab2012-02-24 03:46:391146 }
1147
[email protected]a93670ab2012-02-24 03:46:391148 callback.Run(devices);
[email protected]3bc518b2012-03-09 03:01:501149#endif // TOOLKIT_VIEWS || OS_LINUX
[email protected]a93670ab2012-02-24 03:46:391150}
1151
[email protected]941623e2011-06-07 23:06:041152void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1153 const GURL& source_origin,
1154 int callback_context,
1155 int render_process_id,
1156 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111157#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041158 RenderViewHost* rvh = RenderViewHost::FromID(
1159 render_process_id, render_view_id);
1160 if (!rvh) {
1161 NOTREACHED();
1162 return;
1163 }
1164
[email protected]9f76c1e2012-03-05 15:15:581165 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301166 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041167 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371168 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041169 service->RequestPermission(
1170 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131171 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111172#else
1173 NOTIMPLEMENTED();
1174#endif
[email protected]941623e2011-06-07 23:06:041175}
1176
1177WebKit::WebNotificationPresenter::Permission
1178 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021179 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201180 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021181 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111182#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201184 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021185 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1186 source_origin, render_process_id,
1187 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041188 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041189
1190 // Fall back to the regular notification preferences, which works on an
1191 // origin basis.
1192 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371193 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041194 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111195#else
1196 return WebKit::WebNotificationPresenter::PermissionAllowed;
1197#endif
[email protected]941623e2011-06-07 23:06:041198}
1199
1200void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171201 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041202 int render_process_id,
1203 int render_view_id,
1204 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111205#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041206 RenderViewHost* rvh = RenderViewHost::FromID(
1207 render_process_id, render_view_id);
1208 if (!rvh) {
1209 NOTREACHED();
1210 return;
1211 }
1212
[email protected]9f76c1e2012-03-05 15:15:581213 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301214 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041215 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371216 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041217 service->ShowDesktopNotification(
1218 params, render_process_id, render_view_id,
1219 worker ? DesktopNotificationService::WorkerNotification :
1220 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111221#else
1222 NOTIMPLEMENTED();
1223#endif
[email protected]941623e2011-06-07 23:06:041224}
1225
1226void ChromeContentBrowserClient::CancelDesktopNotification(
1227 int render_process_id,
1228 int render_view_id,
1229 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111230#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041231 RenderViewHost* rvh = RenderViewHost::FromID(
1232 render_process_id, render_view_id);
1233 if (!rvh) {
1234 NOTREACHED();
1235 return;
1236 }
1237
[email protected]9f76c1e2012-03-05 15:15:581238 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301239 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041240 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371241 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041242 service->CancelDesktopNotification(
1243 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111244#else
1245 NOTIMPLEMENTED();
1246#endif
[email protected]941623e2011-06-07 23:06:041247}
1248
[email protected]9f3fba52011-06-08 20:37:191249bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351250 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021251 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191252 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201253 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021254 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1256 // If the opener is trying to create a background window but doesn't have
1257 // the appropriate permission, fail the attempt.
1258 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201259 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531260 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1261
1262 // If the opener is not allowed to script its background window, then return
1263 // false so that the window.open call returns null. In this case, only
1264 // the manifest is permitted to create a background window.
1265 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1266 // return a recently installed Extension even if this CanCreateWindow call
1267 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]2b751a12012-03-06 03:00:351268 // because the permission check below will still fail. We must use the
1269 // full URL to find hosted apps, though, and not just the origin.
[email protected]7b54ca02012-03-02 18:06:531270 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351271 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531272 if (extension && !extension->allow_background_js_access())
1273 return false;
1274
1275 return map->SecurityOriginHasAPIPermission(
[email protected]34eec7ffe32011-11-02 23:49:021276 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191277 }
1278 return true;
1279}
1280
1281std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201282 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1284 // Check if it's an extension-created worker, in which case we want to use
1285 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201286 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191287 const Extension* extension =
1288 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1289 return extension ? extension->name() : std::string();
1290}
1291
[email protected]99907362012-01-11 05:41:401292void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1293 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171294}
1295
[email protected]c52b2892012-03-07 11:01:021296content::SpeechRecognitionManagerDelegate*
1297 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321298#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021299 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321300#else
1301 return NULL;
1302#endif
[email protected]66cfec62012-02-24 17:57:511303}
1304
[email protected]3cb054e62011-06-13 05:21:171305ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1306 return g_browser_process->clipboard();
1307}
1308
[email protected]ae6e9912011-07-27 01:18:281309net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1310 return g_browser_process->net_log();
1311}
1312
[email protected]32538d92011-08-25 00:09:231313AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1314 return new ChromeAccessTokenStore();
1315}
1316
[email protected]dbae6b02011-06-29 23:51:411317bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1318 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1319 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1320}
1321
[email protected]64d69de42012-02-06 00:19:541322void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321323 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061324 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581325 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061326 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061327
[email protected]64d69de42012-02-06 00:19:541328 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061329 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541330 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061331 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541332 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061333 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541334 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061335 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541336 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061337 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541338 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061339 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1340
1341 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541342 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061343 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541344 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061345 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541346 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061347 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541348 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061349 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541350 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061351 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541352 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061353
[email protected]64d69de42012-02-06 00:19:541354 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061355 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541356 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061357 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541358 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061359 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541360 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061361 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1362
[email protected]64d69de42012-02-06 00:19:541363 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061364
[email protected]64d69de42012-02-06 00:19:541365 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061366 prefs->GetBoolean(
1367 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541368 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061369 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541370 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061371 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1372 const DictionaryValue* inspector_settings =
1373 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1374 if (inspector_settings) {
1375 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1376 iter != inspector_settings->end_keys(); ++iter) {
1377 std::string value;
1378 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541379 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061380 std::make_pair(*iter, value));
1381 }
1382 }
[email protected]64d69de42012-02-06 00:19:541383 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061384
[email protected]64d69de42012-02-06 00:19:541385 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1386 web_prefs->javascript_enabled = false;
1387 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1388 web_prefs->web_security_enabled = false;
1389 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1390 web_prefs->plugins_enabled = false;
1391 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1392 web_prefs->java_enabled = false;
1393 web_prefs->loads_images_automatically =
1394 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061395
[email protected]64d69de42012-02-06 00:19:541396 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1397 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061398
[email protected]64d69de42012-02-06 00:19:541399 web_prefs->memory_info_enabled =
1400 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1401 web_prefs->allow_displaying_insecure_content =
1402 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1403 web_prefs->allow_running_insecure_content =
1404 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081405 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061406
[email protected]64d69de42012-02-06 00:19:541407 // The user stylesheet watcher may not exist in a testing profile.
1408 if (profile->GetUserStyleSheetWatcher()) {
1409 web_prefs->user_style_sheet_enabled = true;
1410 web_prefs->user_style_sheet_location =
1411 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1412 } else {
1413 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061414 }
1415
[email protected]b7e44ff2012-02-16 03:37:341416 web_prefs->asynchronous_spell_checking_enabled =
1417 CommandLine::ForCurrentProcess()->
1418 HasSwitch(switches::kEnableAsynchronousSpellChecking);
1419 web_prefs->unified_textchecker_enabled =
1420 web_prefs->asynchronous_spell_checking_enabled ||
1421 CommandLine::ForCurrentProcess()->
1422 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571423
[email protected]64d69de42012-02-06 00:19:541424 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061425 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541426 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061427 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541428 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061429 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1430
1431 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541432 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061433 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541434 web_prefs->default_encoding);
1435 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061436 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541437 web_prefs->default_encoding =
1438 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061439 }
[email protected]64d69de42012-02-06 00:19:541440 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061441
1442 ExtensionService* service = profile->GetExtensionService();
1443 if (service) {
1444 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581445 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061446 extension_webkit_preferences::SetPreferences(
[email protected]9f76c1e2012-03-05 15:15:581447 extension, rvh->GetDelegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061448 }
1449
[email protected]9f76c1e2012-03-05 15:15:581450 if (rvh->GetDelegate()->GetRenderViewType() ==
1451 chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541452 web_prefs->allow_scripts_to_close_windows = true;
[email protected]9f76c1e2012-03-05 15:15:581453 } else if (rvh->GetDelegate()->GetRenderViewType() ==
[email protected]f3986f82012-01-03 20:00:061454 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1455 // Disable all kinds of acceleration for background pages.
1456 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541457 web_prefs->force_compositing_mode = false;
1458 web_prefs->accelerated_compositing_enabled = false;
1459 web_prefs->accelerated_2d_canvas_enabled = false;
1460 web_prefs->accelerated_video_enabled = false;
1461 web_prefs->accelerated_painting_enabled = false;
1462 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061463 }
[email protected]2e21fe292012-03-02 22:52:321464
1465#if defined(FILE_MANAGER_EXTENSION)
1466 // Override the default of suppressing HW compositing for WebUI pages for the
1467 // file manager, which is implemented using WebUI but wants HW acceleration
1468 // for video decode & render.
1469 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1470 web_prefs->accelerated_compositing_enabled = true;
1471 web_prefs->accelerated_2d_canvas_enabled = true;
1472 }
1473#endif
[email protected]181a95ee2011-07-12 19:26:361474}
1475
1476void ChromeContentBrowserClient::UpdateInspectorSetting(
1477 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061478 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581479 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061480 DictionaryPrefUpdate update(
1481 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1482 prefs::kWebKitInspectorSettings);
1483 DictionaryValue* inspector_settings = update.Get();
1484 inspector_settings->SetWithoutPathExpansion(key,
1485 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361486}
1487
1488void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061489 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581490 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061491 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1492 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361493}
1494
[email protected]b8148ac2011-07-13 22:03:251495void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1496 BrowserURLHandler* handler) {
1497 // Add the default URL handlers.
1498 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1499 BrowserURLHandler::null_handler());
1500 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1501 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1502
[email protected]b3adbd02011-11-30 22:23:271503 // about: handler. Must come before chrome: handler, since it will
1504 // rewrite about: urls to chrome: URLs and then expect chrome: to
1505 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251506 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1507 BrowserURLHandler::null_handler());
1508 // chrome: & friends.
1509 handler->AddHandlerPair(&HandleWebUI,
1510 BrowserURLHandler::null_handler());
1511}
1512
1513void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371514 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581515 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251516 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1517 BrowsingDataRemover::EVERYTHING,
1518 base::Time());
1519 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1520 // BrowsingDataRemover takes care of deleting itself when done.
1521}
1522
1523void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371524 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581525 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251526 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1527 BrowsingDataRemover::EVERYTHING,
1528 base::Time());
[email protected]dceaa912011-09-06 17:17:231529 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251530 remover->Remove(remove_mask);
1531 // BrowsingDataRemover takes care of deleting itself when done.
1532}
1533
[email protected]e1d16eb92011-08-18 23:19:321534FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1535 return download_util::GetDefaultDownloadDirectory();
1536}
1537
[email protected]c9b6eb62011-10-18 20:49:391538std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1539 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1540}
1541
[email protected]a658d452012-03-02 12:45:291542bool ChromeContentBrowserClient::AllowSocketAPI(
1543 content::BrowserContext* browser_context, const GURL& url) {
1544 if (!url.is_valid())
1545 return false;
1546
1547 std::string host = url.host();
1548 if (allowed_socket_origins_.count(host))
1549 return true;
1550
[email protected]f237c0f2012-03-10 07:49:101551 // Need to check this now and not on construction because otherwise it won't
1552 // work with browser_tests.
1553 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1554 std::string allowed_list =
1555 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
1556 if (!allowed_list.empty()) {
1557 StringTokenizer t(allowed_list, ",");
1558 while (t.GetNext()) {
1559 if (t.token() == host)
1560 return true;
1561 }
1562 }
1563
[email protected]a658d452012-03-02 12:45:291564 Profile* profile = Profile::FromBrowserContext(browser_context);
1565 if (!profile || !profile->GetExtensionService())
1566 return false;
1567
1568 const Extension* extension = profile->GetExtensionService()->extensions()->
1569 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1570 if (!extension)
1571 return false;
1572
1573 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1574 return true;
1575
1576 return false;
[email protected]e461da2f2012-02-16 19:06:401577}
1578
[email protected]e60c0232011-11-11 19:56:351579#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301580int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521581 const CommandLine& command_line) {
[email protected]6e677a342012-02-11 01:21:141582#if defined(OS_ANDROID)
1583 // TODO(carlosvaldivia): Upstream breakpad code for Android and remove this
1584 // fork. http://crbug.com/113560
1585 NOTIMPLEMENTED();
1586#else
[email protected]718eab62011-10-05 21:16:521587 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071588 ExtensionCrashHandlerHostLinux* crash_handler =
1589 ExtensionCrashHandlerHostLinux::GetInstance();
1590 return crash_handler->GetDeathSignalSocket();
1591 }
1592
[email protected]718eab62011-10-05 21:16:521593 std::string process_type =
1594 command_line.GetSwitchValueASCII(switches::kProcessType);
1595
1596 if (process_type == switches::kRendererProcess)
1597 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1598
[email protected]b80f68432011-05-02 17:22:301599 if (process_type == switches::kPluginProcess)
1600 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1601
1602 if (process_type == switches::kPpapiPluginProcess)
1603 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1604
1605 if (process_type == switches::kGpuProcess)
1606 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
[email protected]6e677a342012-02-11 01:21:141607#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:301608
1609 return -1;
1610}
[email protected]e60c0232011-11-11 19:56:351611#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301612
[email protected]4a65826d2011-08-25 16:04:011613#if defined(OS_WIN)
1614const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1615 return chrome::kBrowserResourcesDll;
1616}
1617#endif
1618
[email protected]37a72af2011-06-13 05:42:011619#if defined(USE_NSS)
1620crypto::CryptoModuleBlockingPasswordDelegate*
1621 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1622 const GURL& url) {
1623 return browser::NewCryptoModuleBlockingDialogDelegate(
1624 browser::kCryptoModulePasswordKeygen, url.host());
1625}
1626#endif
1627
[email protected]d977f9c2011-03-14 16:10:261628} // namespace chrome