blob: 2b5694a0147c8d3ecba5d44563aeb30e0cb72a77 [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]e461da2f2012-02-16 19:06:4013#include "base/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0614#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3015#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2516#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3017#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2318#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1219#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0320#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4121#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5622#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0523#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4524#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3225#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0826#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3227#include "chrome/browser/download/download_util.h"
[email protected]6e672df2012-01-25 10:39:4728#include "chrome/browser/extensions/api/webrequest/webrequest_api.h"
[email protected]76411f412012-02-22 18:56:0629#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0430#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1031#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]9c1662b2012-03-06 15:44:3332#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2633#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2534#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0635#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]32538d92011-08-25 00:09:2336#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1237#include "chrome/browser/google/google_util.h"
[email protected]117b6b42012-02-29 09:11:0838#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]ae6e9912011-07-27 01:18:2839#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0440#include "chrome/browser/notifications/desktop_notification_service.h"
41#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4242#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1243#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0644#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4145#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5046#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4147#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1448#include "chrome/browser/printing/printing_message_filter.h"
49#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3250#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0651#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1452#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3353#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4254#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1455#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0256#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4657#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4558#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0359#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4560#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
61#include "chrome/browser/tab_contents/tab_util.h"
[email protected]117b6b42012-02-29 09:11:0862#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]8ec26472011-06-06 16:52:4563#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]863f70a2012-01-27 02:05:5064#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0665#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]b80f68432011-05-02 17:22:3066#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0167#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3068#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0469#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4470#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3471#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1272#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3873#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0974#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2575#include "content/browser/browser_url_handler.h"
[email protected]b48c9182011-10-26 18:03:3076#include "content/public/browser/browser_main_parts.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]ed24fad2011-05-10 22:44:0186#include "net/base/cookie_monster.h"
87#include "net/base/cookie_options.h"
[email protected]7a593db2012-02-13 21:19:4088#include "net/base/ssl_cert_request_info.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"
[email protected]9ad527c2012-03-07 16:39:3495#include "chrome/browser/tab_contents/chrome_web_contents_view_win_delegate.h"
96#include "content/browser/tab_contents/tab_contents_view_win.h"
[email protected]199fc7a2011-09-28 22:45:3897#elif defined(OS_MACOSX)
98#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:5699#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:30100#elif defined(OS_CHROMEOS)
101#include "chrome/browser/chromeos/chrome_browser_main_chromeos.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]b48c9182011-10-26 18:03:30108#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31109#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38110#endif
111
[email protected]c7480942011-11-08 19:18:27112#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31113#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27114#endif
115
116#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31117#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
118#endif
119
[email protected]e60c0232011-11-11 19:56:35120#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30121#include "base/linux_util.h"
122#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43123#endif
[email protected]b80f68432011-05-02 17:22:30124
[email protected]080f34f2011-09-20 05:39:26125#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32126#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21127#elif defined(TOOLKIT_USES_GTK)
[email protected]1c05b7c2012-03-02 18:53:43128#include "chrome/browser/tab_contents/chrome_web_contents_view_gtk_delegate.h"
[email protected]90580422012-01-12 00:26:22129#include "content/browser/tab_contents/tab_contents_view_gtk.h"
[email protected]74313b42011-08-24 16:51:32130#elif defined(OS_MACOSX)
[email protected]cce3ab72012-02-04 18:05:16131#include "chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.h"
[email protected]eb668c92012-02-06 15:35:29132#include "content/browser/tab_contents/web_contents_view_mac.h"
[email protected]6e677a342012-02-11 01:21:14133#elif defined(OS_ANDROID)
[email protected]82c9f44b2012-02-14 21:02:52134#include "content/browser/tab_contents/web_contents_view_android.h"
[email protected]74313b42011-08-24 16:51:32135#endif
136
[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]b9535422012-02-09 01:47:59143using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00144using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11145using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33146using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13147using content::WebContents;
[email protected]631bb742011-11-02 11:29:39148
[email protected]c5dbef02011-05-13 05:06:09149namespace {
150
[email protected]e461da2f2012-02-16 19:06:40151const char* kPredefinedAllowedSocketOrigins[] = {
152 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
153 "pnhechapfaindjhompbnflcldabbghjo" // HTerm App (SSH Client)
154};
155
[email protected]b8148ac2011-07-13 22:03:25156// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42157bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50158 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
159 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25160 return false;
161
162 // Special case the new tab page. In older versions of Chrome, the new tab
163 // page was hosted at chrome-internal:<blah>. This might be in people's saved
164 // sessions or bookmarks, so we say any URL with that scheme triggers the new
165 // tab page.
166 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
167 // Rewrite it with the proper new tab URL.
168 *url = GURL(chrome::kChromeUINewTabURL);
169 }
170
171 return true;
172}
173
[email protected]8d3132f62011-10-12 07:13:42174// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
175// below. Extension, and isolated apps require different privileges to be
176// granted to their RenderProcessHosts. This classification allows us to make
177// sure URLs are served by hosts with the right set of privileges.
178enum RenderProcessHostPrivilege {
179 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45180 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42181 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45182 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42183};
184
185RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
186 const GURL& url,
187 ExtensionService* service) {
188 // Default to a normal renderer cause it is lower privileged. This should only
189 // occur if the URL on a site instance is either malformed, or uninitialized.
190 // If it is malformed, then there is no need for better privileges anyways.
191 // If it is uninitialized, but eventually settles on being an a scheme other
192 // than normal webrenderer, the navigation logic will correct us out of band
193 // anyways.
194 if (!url.is_valid())
195 return PRIV_NORMAL;
196
197 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44198 const Extension* extension =
199 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45200 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42201 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45202 if (extension && extension->is_hosted_app())
203 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42204
205 return PRIV_EXTENSION;
206 }
207
208 return PRIV_NORMAL;
209}
210
211RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30212 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46213 extensions::ProcessMap* process_map,
214 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46215 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30216 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46217 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21218 return PRIV_NORMAL;
219
[email protected]6f371442011-11-09 06:45:46220 for (std::set<std::string>::iterator iter = extension_ids.begin();
221 iter != extension_ids.end(); ++iter) {
222 const Extension* extension = service->GetExtensionById(*iter, false);
223 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42224 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45225 if (extension && extension->is_hosted_app())
226 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42227 }
228
[email protected]676f6ab2011-10-19 20:23:21229 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42230}
231
[email protected]eec0b33c2011-12-05 22:09:45232bool IsIsolatedAppInProcess(const GURL& site_url,
233 content::RenderProcessHost* process_host,
234 extensions::ProcessMap* process_map,
235 ExtensionService* service) {
236 std::set<std::string> extension_ids =
237 process_map->GetExtensionsInProcess(process_host->GetID());
238 if (extension_ids.empty())
239 return false;
240
241 for (std::set<std::string>::iterator iter = extension_ids.begin();
242 iter != extension_ids.end(); ++iter) {
243 const Extension* extension = service->GetExtensionById(*iter, false);
244 if (extension &&
245 extension->is_storage_isolated() &&
246 extension->url() == site_url)
247 return true;
248 }
249
250 return false;
251}
252
[email protected]6786bf402011-12-03 15:19:45253bool CertMatchesFilter(const net::X509Certificate& cert,
254 const base::DictionaryValue& filter) {
255 // TODO(markusheintz): This is the minimal required filter implementation.
256 // Implement a better matcher.
257
258 // An empty filter matches any client certificate since no requirements are
259 // specified at all.
260 if (filter.empty())
261 return true;
262
263 std::string common_name;
264 if (filter.GetString("ISSUER.CN", &common_name) &&
265 (cert.issuer().common_name == common_name)) {
266 return true;
267 }
268 return false;
269}
270
[email protected]f3986f82012-01-03 20:00:06271// Fills |map| with the per-script font prefs under path |map_name|.
272void FillFontFamilyMap(const PrefService* prefs,
273 const char* map_name,
274 WebPreferences::ScriptFontFamilyMap* map) {
275 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
276 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
277 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
278 std::string font_family = prefs->GetString(pref_name.c_str());
279 if (!font_family.empty())
280 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
281 }
282}
283
[email protected]9dbfff12011-07-01 19:37:07284} // namespace
[email protected]c5dbef02011-05-13 05:06:09285
[email protected]d977f9c2011-03-14 16:10:26286namespace chrome {
287
[email protected]e461da2f2012-02-16 19:06:40288ChromeContentBrowserClient::ChromeContentBrowserClient() {
289 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
290 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
291
292 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
293 std::string allowed_list =
294 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
295 if (!allowed_list.empty()) {
296 StringTokenizer t(allowed_list, ",");
297 while (t.GetNext()) {
298 allowed_socket_origins_.insert(t.token());
299 }
300 }
301}
302
303ChromeContentBrowserClient::~ChromeContentBrowserClient() {
304}
305
[email protected]50462bf02011-11-21 19:13:31306content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
307 const content::MainFunctionParams& parameters) {
308 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30309 // Construct the Main browser parts based on the OS type.
310#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31311 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04312#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31313 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30314#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31315 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35316#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31317 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14318#elif defined(OS_ANDROID)
319 // Do nothing for Android.
320 // TODO(klobag): Android initialization should use the
321 // *BrowserMainParts class-hierarchy for setting up custom initialization.
322 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30323#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31324 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04325#else
[email protected]b48c9182011-10-26 18:03:30326 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31327 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30328#endif
329
[email protected]c7480942011-11-08 19:18:27330 // Construct additional browser parts. Stages are called in the order in
331 // which they are added.
[email protected]b48c9182011-10-26 18:03:30332#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31333 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04334#endif
[email protected]c7480942011-11-08 19:18:27335
336#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31337 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27338#endif
339
340#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31341 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27342#endif
343
[email protected]50462bf02011-11-21 19:13:31344 return main_parts;
[email protected]f967b722011-09-07 00:58:04345}
346
[email protected]8643e6d2012-01-18 20:26:10347content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView(
[email protected]8dad546b2012-01-17 21:47:35348 WebContents* web_contents) {
[email protected]9ad527c2012-03-07 16:39:34349#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]2f8edfc2012-03-08 02:05:25350 // TODO(jam): turn on by default.
351 if (false) {
352 return new TabContentsViewWin(
353 web_contents, new ChromeWebContentsViewWinDelegate(web_contents));
354 } else {
355 return new TabContentsViewViews(web_contents);
356 }
[email protected]9ad527c2012-03-07 16:39:34357#elif defined(TOOLKIT_VIEWS)
[email protected]8dad546b2012-01-17 21:47:35358 return new TabContentsViewViews(web_contents);
[email protected]c92f4ed2011-10-21 19:50:21359#elif defined(TOOLKIT_USES_GTK)
[email protected]8dad546b2012-01-17 21:47:35360 return new content::TabContentsViewGtk(web_contents,
[email protected]1c05b7c2012-03-02 18:53:43361 new ChromeWebContentsViewGtkDelegate);
[email protected]74313b42011-08-24 16:51:32362#elif defined(OS_MACOSX)
[email protected]eb668c92012-02-06 15:35:29363 return web_contents_view_mac::CreateWebContentsView(
[email protected]cce3ab72012-02-04 18:05:16364 web_contents,
365 chrome_web_contents_view_mac_delegate::CreateWebContentsViewMacDelegate(
366 web_contents));
[email protected]6e677a342012-02-11 01:21:14367#elif defined(OS_ANDROID)
[email protected]82c9f44b2012-02-14 21:02:52368 return new WebContentsViewAndroid(web_contents);
[email protected]74313b42011-08-24 16:51:32369#else
[email protected]8643e6d2012-01-18 20:26:10370#error Need to create your platform WebContentsView here.
[email protected]74313b42011-08-24 16:51:32371#endif
372}
373
[email protected]f364d1392011-04-08 21:03:10374void ChromeContentBrowserClient::RenderViewHostCreated(
375 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46376
[email protected]9f76c1e2012-03-05 15:15:58377 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46378 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02379 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46380
381 new ChromeRenderViewHostObserver(render_view_host,
382 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10383 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26384}
385
[email protected]f3b1a082011-11-18 00:34:30386void ChromeContentBrowserClient::RenderProcessHostCreated(
387 content::RenderProcessHost* host) {
388 int id = host->GetID();
389 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
390 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02391 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30392 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03393#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30394 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03395#endif
[email protected]f3b1a082011-11-18 00:34:30396 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02397 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30398 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56399#if defined(OS_MACOSX)
400 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
401#endif
[email protected]f3b1a082011-11-18 00:34:30402 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03403 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38404
[email protected]2ccf45c2011-08-19 23:35:50405 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
406 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07407
408 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56409
410 RendererContentSettingRules rules;
411 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
412 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14413}
414
[email protected]863f70a2012-01-27 02:05:50415content::WebUIControllerFactory*
416 ChromeContentBrowserClient::GetWebUIControllerFactory() {
417 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56418}
419
[email protected]3d7474ff2011-07-27 17:47:37420GURL ChromeContentBrowserClient::GetEffectiveURL(
421 content::BrowserContext* browser_context, const GURL& url) {
422 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08423 // Get the effective URL for the given actual URL. If the URL is part of an
424 // installed app, the effective URL is an extension URL with the ID of that
425 // extension as the host. This has the effect of grouping apps together in
426 // a common SiteInstance.
427 if (!profile || !profile->GetExtensionService())
428 return url;
429
[email protected]615d88f2011-12-13 01:47:44430 const Extension* extension = profile->GetExtensionService()->extensions()->
431 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08432 if (!extension)
433 return url;
434
[email protected]15877ca2011-11-18 22:40:52435 // Bookmark apps do not use the hosted app process model, and should be
436 // treated as normal URLs.
437 if (extension->from_bookmark())
438 return url;
439
[email protected]36fb2c7c2011-04-04 15:49:08440 // If the URL is part of an extension's web extent, convert it to an
441 // extension URL.
442 return extension->GetResourceURL(url.path());
443}
444
[email protected]056ad2a2011-07-12 02:13:55445bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37446 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55447 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52448 // Because we expect to use the effective URL, URLs for hosted apps (apart
449 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55450 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
451 return false;
452
[email protected]3d7474ff2011-07-27 17:47:37453 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55454 if (!profile || !profile->GetExtensionService())
455 return false;
456
[email protected]615d88f2011-12-13 01:47:44457 const Extension* extension = profile->GetExtensionService()->extensions()->
458 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55459 if (!extension)
460 return false;
461
462 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53463 // permission, or that does not allow JavaScript access to the background
464 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55465 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53466 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
467 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
468 !extension->allow_background_js_access()) {
469 return false;
470 }
471 }
[email protected]056ad2a2011-07-12 02:13:55472
[email protected]7b54ca02012-03-02 18:06:53473 // Hosted apps that have script access to their background page must use
474 // process per site, since all instances can make synchronous calls to the
475 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55476 return true;
477}
478
[email protected]46fb9442011-12-09 17:57:47479bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
480 return ProfileIOData::IsHandledURL(url);
481}
482
[email protected]2a5221b2011-09-27 23:07:31483bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30484 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31485 const GURL& site_url) {
486 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30487 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42488 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46489 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31490
[email protected]ffa97602011-11-17 17:55:52491 // Don't allow the Task Manager to share a process with anything else.
492 // Otherwise it can affect the renderers it is observing.
493 // Note: we could create another RenderProcessHostPrivilege bucket for
494 // this to allow multiple chrome://tasks instances to share, but that's
495 // a very unlikely case without serious consequences.
496 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
497 return false;
498
[email protected]8d3132f62011-10-12 07:13:42499 // These may be NULL during tests. In that case, just assume any site can
500 // share any host.
[email protected]6f371442011-11-09 06:45:46501 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31502 return true;
503
[email protected]a8c269a2011-10-25 20:17:22504 // Experimental:
505 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
506 // to share a renderer process. (We could allow pages from the same site or
507 // extensions of the same type to share, if we knew what the given process
508 // was dedicated to. Allowing no sharing is simpler for now.) This may
509 // cause resource exhaustion issues if too many sites are open at once.
510 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
511 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
512 return false;
513
[email protected]eec0b33c2011-12-05 22:09:45514 // An isolated app is only allowed to share with the exact same app in order
515 // to provide complete renderer process isolation. This also works around
516 // issue http://crbug.com/85588, where different isolated apps in the same
517 // process would end up using the first app's storage contexts.
518 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42519 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45520 if (privilege_required == PRIV_ISOLATED)
521 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
522
523 // Otherwise, just make sure the process privilege matches the privilege
524 // required by the site.
525 return GetProcessPrivilege(process_host, process_map, service) ==
526 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31527}
528
[email protected]76411f412012-02-22 18:56:06529// This function is trying to limit the amount of processes used by extensions
530// with background pages. It uses a globally set percentage of processes to
531// run such extensions and if the limit is exceeded, it returns true, to
532// indicate to the content module to group extensions together.
533bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
534 content::BrowserContext* browser_context, const GURL& url) {
535 // It has to be a valid URL for us to check for an extension.
536 if (!url.is_valid())
537 return false;
538
539 Profile* profile = Profile::FromBrowserContext(browser_context);
540 ExtensionService* service = profile->GetExtensionService();
541 if (!service)
542 return false;
543
544 // We have to have a valid extension with background page to proceed.
545 const Extension* extension =
546 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
547 if (!extension)
548 return false;
549 if (!extension->has_background_page())
550 return false;
551
552 std::set<int> process_ids;
553 size_t max_process_count =
554 content::RenderProcessHost::GetMaxRendererProcessCount();
555
556 // Go through all profiles to ensure we have total count of extension
557 // processes containing background pages, otherwise one profile can
558 // starve the other.
559 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
560 GetLoadedProfiles();
561 for (size_t i = 0; i < profiles.size(); ++i) {
562 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
563 for (ExtensionProcessManager::const_iterator iter = epm->begin();
564 iter != epm->end();
565 ++iter) {
566 ExtensionHost* host = *iter;
567 if (host->extension()->has_background_page()) {
568 process_ids.insert(host->render_process_host()->GetID());
569 }
570 }
571 }
572
573 if (process_ids.size() >
574 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
575 return true;
576 }
577
578 return false;
579}
580
[email protected]6f371442011-11-09 06:45:46581void ChromeContentBrowserClient::SiteInstanceGotProcess(
582 SiteInstance* site_instance) {
583 CHECK(site_instance->HasProcess());
584
585 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02586 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46587 ExtensionService* service = profile->GetExtensionService();
588 if (!service)
589 return;
590
591 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44592 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33593 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46594 if (!extension)
595 return;
596
[email protected]6bc04fd82011-12-04 02:29:35597 service->process_map()->Insert(extension->id(),
598 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33599 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46600 BrowserThread::PostTask(
601 BrowserThread::IO, FROM_HERE,
602 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]e15be2b2012-03-09 08:42:11603 profile->GetExtensionInfoMap(),
[email protected]6f371442011-11-09 06:45:46604 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35605 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33606 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46607}
608
609void ChromeContentBrowserClient::SiteInstanceDeleting(
610 SiteInstance* site_instance) {
611 if (!site_instance->HasProcess())
612 return;
613
614 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02615 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46616 ExtensionService* service = profile->GetExtensionService();
617 if (!service)
618 return;
619
620 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44621 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33622 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46623 if (!extension)
624 return;
625
[email protected]6bc04fd82011-12-04 02:29:35626 service->process_map()->Remove(extension->id(),
627 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33628 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46629 BrowserThread::PostTask(
630 BrowserThread::IO, FROM_HERE,
631 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]e15be2b2012-03-09 08:42:11632 profile->GetExtensionInfoMap(),
[email protected]6f371442011-11-09 06:45:46633 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35634 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33635 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46636}
637
[email protected]e3daf3c2011-10-05 21:17:08638bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
639 const GURL& current_url,
640 const GURL& new_url) {
641 if (current_url.is_empty()) {
642 // Always choose a new process when navigating to extension URLs. The
643 // process grouping logic will combine all of a given extension's pages
644 // into the same process.
645 if (new_url.SchemeIs(chrome::kExtensionScheme))
646 return true;
647
648 return false;
649 }
650
651 // Also, we must switch if one is an extension and the other is not the exact
652 // same extension.
653 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
654 new_url.SchemeIs(chrome::kExtensionScheme)) {
655 if (current_url.GetOrigin() != new_url.GetOrigin())
656 return true;
657 }
658
659 return false;
660}
661
[email protected]763ec4ca2011-04-29 15:48:12662std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
663 const std::string& alias_name) {
664 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
665}
666
[email protected]b80f68432011-05-02 17:22:30667void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
668 CommandLine* command_line, int child_process_id) {
669#if defined(USE_LINUX_BREAKPAD)
670 if (IsCrashReporterEnabled()) {
671 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
672 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
673 }
674#elif defined(OS_MACOSX)
675 if (IsCrashReporterEnabled()) {
676 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
677 child_process_logging::GetClientId());
678 }
679#endif // OS_MACOSX
680
[email protected]f1933792011-06-14 00:49:34681 if (logging::DialogsAreSuppressed())
682 command_line->AppendSwitch(switches::kNoErrorDialogs);
683
[email protected]b80f68432011-05-02 17:22:30684 std::string process_type =
685 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17686 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52687 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30688 FilePath user_data_dir =
689 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
690 if (!user_data_dir.empty())
691 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
692#if defined(OS_CHROMEOS)
693 const std::string& login_profile =
694 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
695 if (!login_profile.empty())
696 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
697#endif
698
[email protected]f3b1a082011-11-18 00:34:30699 content::RenderProcessHost* process =
700 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37701 if (process) {
702 Profile* profile = Profile::FromBrowserContext(
703 process->GetBrowserContext());
704 extensions::ProcessMap* process_map =
705 profile->GetExtensionService()->process_map();
706 if (process_map && process_map->Contains(process->GetID()))
707 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30708
[email protected]a8d851f82011-12-21 00:32:37709 PrefService* prefs = profile->GetPrefs();
710 // Currently this pref is only registered if applied via a policy.
711 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
712 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
713 // Turn this policy into a command line switch.
714 command_line->AppendSwitch(switches::kDisable3DAPIs);
715 }
[email protected]718eab62011-10-05 21:16:52716
[email protected]a8d851f82011-12-21 00:32:37717 // Disable client-side phishing detection in the renderer if it is
718 // disabled in the Profile preferences or the browser process.
719 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
720 !g_browser_process->safe_browsing_detection_service()) {
721 command_line->AppendSwitch(
722 switches::kDisableClientSidePhishingDetection);
723 }
[email protected]8c40da62011-07-13 22:58:46724 }
[email protected]47c7ec82012-01-18 03:29:21725 {
726 PrefService* local_state = g_browser_process->local_state();
727 if (local_state &&
728 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
729 command_line->AppendSwitch(switches::kRendererPrintPreview);
730 }
731 }
[email protected]4287a3d2011-06-13 23:56:51732
[email protected]47c7ec82012-01-18 03:29:21733 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51734 static const char* const kSwitchNames[] = {
735 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48736 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51737 switches::kAllowScriptingGallery,
738 switches::kAppsCheckoutURL,
739 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31740 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51741 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50742 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51743 switches::kDumpHistogramsOnExit,
[email protected]b7e44ff2012-02-16 03:37:34744 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21745 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13746 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51747 switches::kEnableCrxlessWebApps,
748 switches::kEnableExperimentalExtensionApis,
749 switches::kEnableInBrowserThumbnailing,
750 switches::kEnableIPCFuzzing,
751 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:48752 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53753 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51754 switches::kEnableWatchdog,
755 switches::kExperimentalSpellcheckerFeatures,
756 switches::kMemoryProfiling,
757 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04758 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51759 switches::kPpapiFlashArgs,
760 switches::kPpapiFlashInProcess,
761 switches::kPpapiFlashPath,
762 switches::kPpapiFlashVersion,
763 switches::kProfilingAtStart,
764 switches::kProfilingFile,
765 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51766 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38767 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51768 };
769
770 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
771 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17772 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38773 static const char* const kSwitchNames[] = {
774 switches::kEnableExperimentalExtensionApis,
775 switches::kWhitelistedExtensionID,
776 };
777
778 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
779 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51780 } else if (process_type == switches::kPluginProcess) {
781 static const char* const kSwitchNames[] = {
782 #if defined(OS_CHROMEOS)
783 switches::kLoginProfile,
784 #endif
785 switches::kMemoryProfiling,
786 switches::kSilentDumpOnDCHECK,
787 switches::kUserDataDir,
788 };
789
790 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
791 arraysize(kSwitchNames));
792 } else if (process_type == switches::kZygoteProcess) {
793 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51794 switches::kUserDataDir, // Make logs go to the right file.
795 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50796 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13797 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51798 switches::kPpapiFlashInProcess,
799 switches::kPpapiFlashPath,
800 switches::kPpapiFlashVersion,
801 };
802
803 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
804 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11805 } else if (process_type == switches::kGpuProcess) {
806 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
807 // because GPU is expected to be unreliable.
808 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
809 !command_line->HasSwitch(switches::kDisableBreakpad))
810 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30811 }
[email protected]6f08af82011-09-15 01:19:03812
813 // The command line switch kEnableBenchmarking needs to be specified along
814 // with the kEnableStatsTable switch to ensure that the stats table global
815 // is initialized correctly.
816 if (command_line->HasSwitch(switches::kEnableBenchmarking))
817 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30818}
819
820std::string ChromeContentBrowserClient::GetApplicationLocale() {
821 return g_browser_process->GetApplicationLocale();
822}
823
[email protected]597a867b2011-11-18 18:31:20824std::string ChromeContentBrowserClient::GetAcceptLangs(
825 content::BrowserContext* context) {
826 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37827 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08828}
829
[email protected]ac55e292011-06-24 05:16:08830SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22831 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08832 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
833}
834
[email protected]a2176792011-05-08 19:30:49835bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09836 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19837 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20838 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32839 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20840 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05841 return io_data->GetCookieSettings()->
842 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49843}
844
[email protected]ed24fad2011-05-10 22:44:01845bool ChromeContentBrowserClient::AllowGetCookie(
846 const GURL& url,
847 const GURL& first_party,
848 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20849 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01850 int render_process_id,
851 int render_view_id) {
852 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20853 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05854 bool allow = io_data->GetCookieSettings()->
855 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01856
[email protected]8093a542011-05-13 07:29:32857 BrowserThread::PostTask(
858 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03859 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
860 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01861 return allow;
862}
863
864bool ChromeContentBrowserClient::AllowSetCookie(
865 const GURL& url,
866 const GURL& first_party,
867 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20868 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01869 int render_process_id,
870 int render_view_id,
871 net::CookieOptions* options) {
872 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20873 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05874 CookieSettings* cookie_settings = io_data->GetCookieSettings();
875 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
876
877 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09878 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01879
[email protected]8093a542011-05-13 07:29:32880 BrowserThread::PostTask(
881 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03882 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
883 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01884 return allow;
885}
886
[email protected]d5a19162011-06-30 18:51:54887bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20888 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54889 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20890 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26891
892 if (!io_data->clear_local_state_on_exit()->GetValue())
893 return true;
894
[email protected]068b7b52012-02-27 12:41:44895 // Disable clearing the local state on exit if the browsing session is going
[email protected]1848cdc2012-02-17 10:48:26896 // to be restored on the next startup.
897 SessionStartupPref::Type startup_pref =
898 SessionStartupPref::PrefValueToType(
899 io_data->session_startup_pref()->GetValue());
900 return (startup_pref == SessionStartupPref::LAST &&
[email protected]068b7b52012-02-27 12:41:44901 !CommandLine::ForCurrentProcess()->HasSwitch(
902 switches::kDisableRestoreSessionState));
[email protected]d5a19162011-06-30 18:51:54903}
904
[email protected]5c5a88e2011-11-12 00:45:35905bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35906 const GURL& url,
907 const string16& name,
908 const string16& display_name,
909 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20910 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48911 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35912 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20913 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35914 CookieSettings* cookie_settings = io_data->GetCookieSettings();
915 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
916
[email protected]62151052012-02-01 18:40:48917 // Record access to database for potential display in UI.
918 std::vector<std::pair<int, int> >::const_iterator i;
919 for (i = render_views.begin(); i != render_views.end(); ++i) {
920 BrowserThread::PostTask(
921 BrowserThread::UI, FROM_HERE,
922 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
923 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35924 }
925
926 return allow;
927}
928
929bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35930 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20931 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48932 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35933 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20934 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35935 CookieSettings* cookie_settings = io_data->GetCookieSettings();
936 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
937
[email protected]62151052012-02-01 18:40:48938 // Record access to file system for potential display in UI.
939 std::vector<std::pair<int, int> >::const_iterator i;
940 for (i = render_views.begin(); i != render_views.end(); ++i) {
941 BrowserThread::PostTask(
942 BrowserThread::UI, FROM_HERE,
943 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
944 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35945 }
946
947 return allow;
948}
949
[email protected]7c5ff9a2012-03-02 07:42:49950bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
951 const GURL& url,
952 const string16& name,
953 content::ResourceContext* context,
954 const std::vector<std::pair<int, int> >& render_views) {
955 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
956 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
957 CookieSettings* cookie_settings = io_data->GetCookieSettings();
958 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
959
960 // Record access to IndexedDB for potential display in UI.
961 std::vector<std::pair<int, int> >::const_iterator i;
962 for (i = render_views.begin(); i != render_views.end(); ++i) {
963 BrowserThread::PostTask(
964 BrowserThread::UI, FROM_HERE,
965 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
966 i->first, i->second, url, name, !allow));
967 }
968
969 return allow;
970}
971
[email protected]6133f922011-07-01 21:34:34972net::URLRequestContext*
973ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20974 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34975 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
976 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20977 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34978 return io_data->extensions_request_context();
979 }
980
981 return NULL;
982}
983
[email protected]317f96c92011-05-31 06:53:41984QuotaPermissionContext*
985ChromeContentBrowserClient::CreateQuotaPermissionContext() {
986 return new ChromeQuotaPermissionContext();
987}
988
[email protected]a0ce3282011-08-19 20:49:52989void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42990 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42991}
992
[email protected]a0ce3282011-08-19 20:49:52993void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52994 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52995}
996
[email protected]848dd042011-06-04 18:24:03997void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:17998 int render_process_id,
999 int render_view_id,
1000 int cert_error,
1001 const net::SSLInfo& ssl_info,
1002 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031003 bool overridable,
[email protected]4cf611e32012-02-13 16:06:171004 const base::Callback<void(bool)>& callback,
1005 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411006 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131007 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171008 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411009 if (!tab) {
1010 NOTREACHED();
1011 return;
1012 }
1013 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501014 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301015 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091016 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411017 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171018 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411019 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171020 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411021 return;
1022 }
1023 }
1024
1025 // Otherwise, display an SSL blocking page.
[email protected]4cf611e32012-02-13 16:06:171026 new SSLBlockingPage(
1027 tab, cert_error, ssl_info, request_url, overridable, callback);
[email protected]848dd042011-06-04 18:24:031028}
1029
[email protected]c99c442e2011-08-24 11:37:301030void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451031 int render_process_id,
1032 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401033 const net::HttpNetworkSession* network_session,
1034 net::SSLCertRequestInfo* cert_request_info,
1035 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131036 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451037 render_process_id, render_view_id);
1038 if (!tab) {
1039 NOTREACHED();
1040 return;
1041 }
1042
[email protected]6786bf402011-12-03 15:19:451043 GURL requesting_url("https://" + cert_request_info->host_and_port);
1044 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1045 << cert_request_info->host_and_port;
1046
[email protected]627e0512011-12-21 22:55:301047 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451048 scoped_ptr<Value> filter(
1049 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1050 requesting_url,
1051 requesting_url,
1052 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1053 std::string(), NULL));
1054
1055 if (filter.get()) {
1056 // Try to automatically select a client certificate.
1057 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1058 DictionaryValue* filter_dict =
1059 static_cast<DictionaryValue*>(filter.get());
1060
1061 const std::vector<scoped_refptr<net::X509Certificate> >&
1062 all_client_certs = cert_request_info->client_certs;
1063 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1064 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1065 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401066 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451067 return;
1068 }
1069 }
1070 } else {
1071 NOTREACHED();
1072 }
1073 }
1074
[email protected]8ec26472011-06-06 16:52:451075 TabContentsWrapper* wrapper =
1076 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451077 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131078 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451079 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141080 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401081 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451082 return;
1083 }
[email protected]7a593db2012-02-13 21:19:401084 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1085 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451086}
1087
1088void ChromeContentBrowserClient::AddNewCertificate(
1089 net::URLRequest* request,
1090 net::X509Certificate* cert,
1091 int render_process_id,
1092 int render_view_id) {
1093 // The handler will run the UI and delete itself when it's finished.
1094 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1095}
1096
[email protected]a93670ab2012-02-24 03:46:391097void ChromeContentBrowserClient::RequestMediaAccessPermission(
1098 const content::MediaStreamRequest* request,
1099 const content::MediaResponseCallback& callback) {
1100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1101
[email protected]117b6b42012-02-29 09:11:081102 WebContents* contents = tab_util::GetWebContentsByID(
1103 request->render_process_id, request->render_view_id);
1104 if (!contents) {
1105 // Abort, if the tab was closed after the request was made but before we
1106 // got to this point.
1107 callback.Run(content::MediaStreamDevices());
1108 return;
1109 }
1110
1111 TabContentsWrapper* tab =
1112 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1113 DCHECK(tab);
1114
1115 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1116 InfoBarDelegate* old_infobar = NULL;
1117 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1118 old_infobar =
1119 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfobarDelegate();
1120 }
1121
[email protected]3bc518b2012-03-09 03:01:501122#if defined(TOOLKIT_VIEWS) || defined(OS_LINUX)
[email protected]117b6b42012-02-29 09:11:081123 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1124 request,
1125 callback);
1126 if (old_infobar)
1127 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1128 else
1129 infobar_helper->AddInfoBar(infobar);
[email protected]3bc518b2012-03-09 03:01:501130#elif defined(OS_MACOSX)
1131 // TODO(macourteau): UI is not implemented yet for OS X. Fallback to
[email protected]117b6b42012-02-29 09:11:081132 // the default behaviour and allow access to the first device of each
1133 // requested type.
1134 content::MediaStreamDevices devices;
[email protected]a93670ab2012-02-24 03:46:391135 for (content::MediaStreamDeviceMap::const_iterator it =
1136 request->devices.begin(); it != request->devices.end(); ++it) {
[email protected]6c6415a2012-03-01 17:17:281137 if (!it->second.empty())
1138 devices.push_back(*it->second.begin());
[email protected]a93670ab2012-02-24 03:46:391139 }
1140
[email protected]a93670ab2012-02-24 03:46:391141 callback.Run(devices);
[email protected]3bc518b2012-03-09 03:01:501142#endif // TOOLKIT_VIEWS || OS_LINUX
[email protected]a93670ab2012-02-24 03:46:391143}
1144
[email protected]941623e2011-06-07 23:06:041145void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1146 const GURL& source_origin,
1147 int callback_context,
1148 int render_process_id,
1149 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111150#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041151 RenderViewHost* rvh = RenderViewHost::FromID(
1152 render_process_id, render_view_id);
1153 if (!rvh) {
1154 NOTREACHED();
1155 return;
1156 }
1157
[email protected]9f76c1e2012-03-05 15:15:581158 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301159 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041160 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371161 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041162 service->RequestPermission(
1163 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131164 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111165#else
1166 NOTIMPLEMENTED();
1167#endif
[email protected]941623e2011-06-07 23:06:041168}
1169
1170WebKit::WebNotificationPresenter::Permission
1171 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021172 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201173 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021174 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111175#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201177 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021178 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1179 source_origin, render_process_id,
1180 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041181 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041182
1183 // Fall back to the regular notification preferences, which works on an
1184 // origin basis.
1185 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371186 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041187 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111188#else
1189 return WebKit::WebNotificationPresenter::PermissionAllowed;
1190#endif
[email protected]941623e2011-06-07 23:06:041191}
1192
1193void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171194 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041195 int render_process_id,
1196 int render_view_id,
1197 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111198#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041199 RenderViewHost* rvh = RenderViewHost::FromID(
1200 render_process_id, render_view_id);
1201 if (!rvh) {
1202 NOTREACHED();
1203 return;
1204 }
1205
[email protected]9f76c1e2012-03-05 15:15:581206 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301207 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041208 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371209 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041210 service->ShowDesktopNotification(
1211 params, render_process_id, render_view_id,
1212 worker ? DesktopNotificationService::WorkerNotification :
1213 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111214#else
1215 NOTIMPLEMENTED();
1216#endif
[email protected]941623e2011-06-07 23:06:041217}
1218
1219void ChromeContentBrowserClient::CancelDesktopNotification(
1220 int render_process_id,
1221 int render_view_id,
1222 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111223#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041224 RenderViewHost* rvh = RenderViewHost::FromID(
1225 render_process_id, render_view_id);
1226 if (!rvh) {
1227 NOTREACHED();
1228 return;
1229 }
1230
[email protected]9f76c1e2012-03-05 15:15:581231 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301232 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041233 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371234 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041235 service->CancelDesktopNotification(
1236 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111237#else
1238 NOTIMPLEMENTED();
1239#endif
[email protected]941623e2011-06-07 23:06:041240}
1241
[email protected]9f3fba52011-06-08 20:37:191242bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351243 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021244 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191245 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201246 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021247 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1249 // If the opener is trying to create a background window but doesn't have
1250 // the appropriate permission, fail the attempt.
1251 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201252 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531253 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1254
1255 // If the opener is not allowed to script its background window, then return
1256 // false so that the window.open call returns null. In this case, only
1257 // the manifest is permitted to create a background window.
1258 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1259 // return a recently installed Extension even if this CanCreateWindow call
1260 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]2b751a12012-03-06 03:00:351261 // because the permission check below will still fail. We must use the
1262 // full URL to find hosted apps, though, and not just the origin.
[email protected]7b54ca02012-03-02 18:06:531263 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351264 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531265 if (extension && !extension->allow_background_js_access())
1266 return false;
1267
1268 return map->SecurityOriginHasAPIPermission(
[email protected]34eec7ffe32011-11-02 23:49:021269 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191270 }
1271 return true;
1272}
1273
1274std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201275 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1277 // Check if it's an extension-created worker, in which case we want to use
1278 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201279 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191280 const Extension* extension =
1281 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1282 return extension ? extension->name() : std::string();
1283}
1284
[email protected]99907362012-01-11 05:41:401285void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1286 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171287}
1288
[email protected]c52b2892012-03-07 11:01:021289content::SpeechRecognitionManagerDelegate*
1290 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
1291 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:511292}
1293
[email protected]3cb054e62011-06-13 05:21:171294ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1295 return g_browser_process->clipboard();
1296}
1297
[email protected]ae6e9912011-07-27 01:18:281298net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1299 return g_browser_process->net_log();
1300}
1301
[email protected]32538d92011-08-25 00:09:231302AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1303 return new ChromeAccessTokenStore();
1304}
1305
[email protected]dbae6b02011-06-29 23:51:411306bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1307 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1308 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1309}
1310
[email protected]64d69de42012-02-06 00:19:541311void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321312 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061313 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581314 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061315 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061316
[email protected]64d69de42012-02-06 00:19:541317 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061318 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541319 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061320 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541321 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061322 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541323 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061324 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541325 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061326 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541327 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061328 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1329
1330 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541331 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061332 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541333 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061334 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541335 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061336 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541337 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061338 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541339 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061340 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541341 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061342
[email protected]64d69de42012-02-06 00:19:541343 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061344 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541345 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061346 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541347 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061348 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541349 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061350 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1351
[email protected]64d69de42012-02-06 00:19:541352 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061353
[email protected]64d69de42012-02-06 00:19:541354 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061355 prefs->GetBoolean(
1356 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541357 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061358 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541359 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061360 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1361 const DictionaryValue* inspector_settings =
1362 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1363 if (inspector_settings) {
1364 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1365 iter != inspector_settings->end_keys(); ++iter) {
1366 std::string value;
1367 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541368 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061369 std::make_pair(*iter, value));
1370 }
1371 }
[email protected]64d69de42012-02-06 00:19:541372 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061373
[email protected]64d69de42012-02-06 00:19:541374 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1375 web_prefs->javascript_enabled = false;
1376 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1377 web_prefs->web_security_enabled = false;
1378 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1379 web_prefs->plugins_enabled = false;
1380 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1381 web_prefs->java_enabled = false;
1382 web_prefs->loads_images_automatically =
1383 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061384
[email protected]64d69de42012-02-06 00:19:541385 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1386 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061387
[email protected]64d69de42012-02-06 00:19:541388 web_prefs->memory_info_enabled =
1389 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1390 web_prefs->allow_displaying_insecure_content =
1391 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1392 web_prefs->allow_running_insecure_content =
1393 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081394 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061395
[email protected]64d69de42012-02-06 00:19:541396 // The user stylesheet watcher may not exist in a testing profile.
1397 if (profile->GetUserStyleSheetWatcher()) {
1398 web_prefs->user_style_sheet_enabled = true;
1399 web_prefs->user_style_sheet_location =
1400 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1401 } else {
1402 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061403 }
1404
[email protected]b7e44ff2012-02-16 03:37:341405 web_prefs->asynchronous_spell_checking_enabled =
1406 CommandLine::ForCurrentProcess()->
1407 HasSwitch(switches::kEnableAsynchronousSpellChecking);
1408 web_prefs->unified_textchecker_enabled =
1409 web_prefs->asynchronous_spell_checking_enabled ||
1410 CommandLine::ForCurrentProcess()->
1411 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571412
[email protected]64d69de42012-02-06 00:19:541413 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061414 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541415 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061416 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541417 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061418 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1419
1420 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541421 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061422 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541423 web_prefs->default_encoding);
1424 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061425 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541426 web_prefs->default_encoding =
1427 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061428 }
[email protected]64d69de42012-02-06 00:19:541429 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061430
1431 ExtensionService* service = profile->GetExtensionService();
1432 if (service) {
1433 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581434 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061435 extension_webkit_preferences::SetPreferences(
[email protected]9f76c1e2012-03-05 15:15:581436 extension, rvh->GetDelegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061437 }
1438
[email protected]9f76c1e2012-03-05 15:15:581439 if (rvh->GetDelegate()->GetRenderViewType() ==
1440 chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541441 web_prefs->allow_scripts_to_close_windows = true;
[email protected]9f76c1e2012-03-05 15:15:581442 } else if (rvh->GetDelegate()->GetRenderViewType() ==
[email protected]f3986f82012-01-03 20:00:061443 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1444 // Disable all kinds of acceleration for background pages.
1445 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541446 web_prefs->force_compositing_mode = false;
1447 web_prefs->accelerated_compositing_enabled = false;
1448 web_prefs->accelerated_2d_canvas_enabled = false;
1449 web_prefs->accelerated_video_enabled = false;
1450 web_prefs->accelerated_painting_enabled = false;
1451 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061452 }
[email protected]2e21fe292012-03-02 22:52:321453
1454#if defined(FILE_MANAGER_EXTENSION)
1455 // Override the default of suppressing HW compositing for WebUI pages for the
1456 // file manager, which is implemented using WebUI but wants HW acceleration
1457 // for video decode & render.
1458 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1459 web_prefs->accelerated_compositing_enabled = true;
1460 web_prefs->accelerated_2d_canvas_enabled = true;
1461 }
1462#endif
[email protected]181a95ee2011-07-12 19:26:361463}
1464
1465void ChromeContentBrowserClient::UpdateInspectorSetting(
1466 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061467 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581468 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061469 DictionaryPrefUpdate update(
1470 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1471 prefs::kWebKitInspectorSettings);
1472 DictionaryValue* inspector_settings = update.Get();
1473 inspector_settings->SetWithoutPathExpansion(key,
1474 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361475}
1476
1477void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[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 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1481 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361482}
1483
[email protected]b8148ac2011-07-13 22:03:251484void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1485 BrowserURLHandler* handler) {
1486 // Add the default URL handlers.
1487 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1488 BrowserURLHandler::null_handler());
1489 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1490 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1491
[email protected]b3adbd02011-11-30 22:23:271492 // about: handler. Must come before chrome: handler, since it will
1493 // rewrite about: urls to chrome: URLs and then expect chrome: to
1494 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251495 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1496 BrowserURLHandler::null_handler());
1497 // chrome: & friends.
1498 handler->AddHandlerPair(&HandleWebUI,
1499 BrowserURLHandler::null_handler());
1500}
1501
1502void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371503 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581504 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251505 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1506 BrowsingDataRemover::EVERYTHING,
1507 base::Time());
1508 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1509 // BrowsingDataRemover takes care of deleting itself when done.
1510}
1511
1512void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371513 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581514 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251515 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1516 BrowsingDataRemover::EVERYTHING,
1517 base::Time());
[email protected]dceaa912011-09-06 17:17:231518 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251519 remover->Remove(remove_mask);
1520 // BrowsingDataRemover takes care of deleting itself when done.
1521}
1522
[email protected]e1d16eb92011-08-18 23:19:321523FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1524 return download_util::GetDefaultDownloadDirectory();
1525}
1526
[email protected]c9b6eb62011-10-18 20:49:391527std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1528 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1529}
1530
[email protected]a658d452012-03-02 12:45:291531bool ChromeContentBrowserClient::AllowSocketAPI(
1532 content::BrowserContext* browser_context, const GURL& url) {
1533 if (!url.is_valid())
1534 return false;
1535
1536 std::string host = url.host();
1537 if (allowed_socket_origins_.count(host))
1538 return true;
1539
1540 Profile* profile = Profile::FromBrowserContext(browser_context);
1541 if (!profile || !profile->GetExtensionService())
1542 return false;
1543
1544 const Extension* extension = profile->GetExtensionService()->extensions()->
1545 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1546 if (!extension)
1547 return false;
1548
1549 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1550 return true;
1551
1552 return false;
[email protected]e461da2f2012-02-16 19:06:401553}
1554
[email protected]e60c0232011-11-11 19:56:351555#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301556int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521557 const CommandLine& command_line) {
[email protected]6e677a342012-02-11 01:21:141558#if defined(OS_ANDROID)
1559 // TODO(carlosvaldivia): Upstream breakpad code for Android and remove this
1560 // fork. http://crbug.com/113560
1561 NOTIMPLEMENTED();
1562#else
[email protected]718eab62011-10-05 21:16:521563 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071564 ExtensionCrashHandlerHostLinux* crash_handler =
1565 ExtensionCrashHandlerHostLinux::GetInstance();
1566 return crash_handler->GetDeathSignalSocket();
1567 }
1568
[email protected]718eab62011-10-05 21:16:521569 std::string process_type =
1570 command_line.GetSwitchValueASCII(switches::kProcessType);
1571
1572 if (process_type == switches::kRendererProcess)
1573 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1574
[email protected]b80f68432011-05-02 17:22:301575 if (process_type == switches::kPluginProcess)
1576 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1577
1578 if (process_type == switches::kPpapiPluginProcess)
1579 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1580
1581 if (process_type == switches::kGpuProcess)
1582 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
[email protected]6e677a342012-02-11 01:21:141583#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:301584
1585 return -1;
1586}
[email protected]e60c0232011-11-11 19:56:351587#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301588
[email protected]4a65826d2011-08-25 16:04:011589#if defined(OS_WIN)
1590const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1591 return chrome::kBrowserResourcesDll;
1592}
1593#endif
1594
[email protected]37a72af2011-06-13 05:42:011595#if defined(USE_NSS)
1596crypto::CryptoModuleBlockingPasswordDelegate*
1597 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1598 const GURL& url) {
1599 return browser::NewCryptoModuleBlockingDialogDelegate(
1600 browser::kCryptoModulePasswordKeygen, url.host());
1601}
1602#endif
1603
[email protected]d977f9c2011-03-14 16:10:261604} // namespace chrome