blob: 40df6d2465de1e7e9b2563ae9d9870dd05c7b4de [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]dc73a7b2012-03-25 15:27:1839#include "chrome/browser/media/media_internals.h"
[email protected]ae6e9912011-07-27 01:18:2840#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0441#include "chrome/browser/notifications/desktop_notification_service.h"
42#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]e0ada9c2012-03-20 03:54:4343#include "chrome/browser/pepper_gtalk_message_filter.h"
[email protected]0609b17f2011-05-31 20:13:4244#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1245#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0646#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4147#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5048#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4149#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1450#include "chrome/browser/printing/printing_message_filter.h"
51#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3252#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0653#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1454#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3355#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4256#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1457#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0258#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4659#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4560#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0361#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4562#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
63#include "chrome/browser/tab_contents/tab_util.h"
[email protected]117b6b42012-02-29 09:11:0864#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]8ec26472011-06-06 16:52:4565#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]863f70a2012-01-27 02:05:5066#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0667#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]b80f68432011-05-02 17:22:3068#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0169#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3070#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0471#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4472#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3473#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1274#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3875#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0976#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4377#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3078#include "content/public/browser/browser_main_parts.h"
[email protected]825b1662012-03-12 19:07:3179#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5980#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3081#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3382#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0583#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3384#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1985#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1086#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4387#include "content/public/common/child_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3988#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3489#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4090#include "net/base/ssl_cert_request_info.h"
[email protected]aa84a7e2012-03-15 21:29:0691#include "net/cookies/cookie_monster.h"
92#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3993#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0894#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3695#include "webkit/glue/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:2696
[email protected]b48c9182011-10-26 18:03:3097#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3898#include "chrome/browser/chrome_browser_main_win.h"
99#elif defined(OS_MACOSX)
100#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56101#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]38b098f2012-03-14 21:11:57102#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h"
[email protected]b48c9182011-10-26 18:03:30103#elif defined(OS_CHROMEOS)
104#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49105#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26106#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30107#include "chrome/browser/chrome_browser_main_linux.h"
108#elif defined(OS_POSIX)
109#include "chrome/browser/chrome_browser_main_posix.h"
110#endif
111
[email protected]159d5142012-03-22 18:16:24112#if defined(USE_AURA)
113#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_aura.h"
114#elif defined(OS_WIN)
[email protected]61e69822012-03-14 22:08:57115#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_win.h"
116#endif
117
[email protected]b48c9182011-10-26 18:03:30118#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31119#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38120#endif
121
[email protected]c7480942011-11-08 19:18:27122#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31123#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]38b098f2012-03-14 21:11:57124#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c7480942011-11-08 19:18:27125#endif
126
127#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31128#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
129#endif
130
[email protected]dc04be7c2012-03-15 23:57:49131#if defined(USE_ASH)
132#include "chrome/browser/chrome_browser_main_extra_parts_ash.h"
133#endif
134
[email protected]e60c0232011-11-11 19:56:35135#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30136#include "base/linux_util.h"
137#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43138#endif
[email protected]b80f68432011-05-02 17:22:30139
[email protected]38b098f2012-03-14 21:11:57140#if defined(TOOLKIT_GTK)
141#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_gtk.h"
[email protected]74313b42011-08-24 16:51:32142#endif
[email protected]37a72af2011-06-13 05:42:01143#if defined(USE_NSS)
144#include "chrome/browser/ui/crypto_module_password_dialog.h"
145#endif
146
[email protected]c8c77182011-12-21 15:04:47147using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39148using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31149using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59150using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00151using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11152using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33153using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13154using content::WebContents;
[email protected]631bb742011-11-02 11:29:39155
[email protected]c5dbef02011-05-13 05:06:09156namespace {
157
[email protected]e461da2f2012-02-16 19:06:40158const char* kPredefinedAllowedSocketOrigins[] = {
159 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
160 "pnhechapfaindjhompbnflcldabbghjo" // HTerm App (SSH Client)
161};
162
[email protected]b8148ac2011-07-13 22:03:25163// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42164bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50165 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
166 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25167 return false;
168
[email protected]fe69558d2012-03-12 11:34:49169#if defined(OS_CHROMEOS)
170 // Special case : in ChromeOS in Guest mode bookmarks and history are
171 // disabled for security reasons. New tab page explains the reasons, so
172 // we redirect user to new tab page.
173 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
174 if (url->SchemeIs(chrome::kChromeUIScheme) &&
175 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
176 url->DomainIs(chrome::kChromeUIHistoryHost))) {
177 // Rewrite with new tab URL
178 *url = GURL(chrome::kChromeUINewTabURL);
179 }
180 }
181#endif
182
[email protected]b8148ac2011-07-13 22:03:25183 // Special case the new tab page. In older versions of Chrome, the new tab
184 // page was hosted at chrome-internal:<blah>. This might be in people's saved
185 // sessions or bookmarks, so we say any URL with that scheme triggers the new
186 // tab page.
187 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
188 // Rewrite it with the proper new tab URL.
189 *url = GURL(chrome::kChromeUINewTabURL);
190 }
191
192 return true;
193}
194
[email protected]8d3132f62011-10-12 07:13:42195// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
196// below. Extension, and isolated apps require different privileges to be
197// granted to their RenderProcessHosts. This classification allows us to make
198// sure URLs are served by hosts with the right set of privileges.
199enum RenderProcessHostPrivilege {
200 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45201 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42202 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45203 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42204};
205
206RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
207 const GURL& url,
208 ExtensionService* service) {
209 // Default to a normal renderer cause it is lower privileged. This should only
210 // occur if the URL on a site instance is either malformed, or uninitialized.
211 // If it is malformed, then there is no need for better privileges anyways.
212 // If it is uninitialized, but eventually settles on being an a scheme other
213 // than normal webrenderer, the navigation logic will correct us out of band
214 // anyways.
215 if (!url.is_valid())
216 return PRIV_NORMAL;
217
218 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44219 const Extension* extension =
220 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45221 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42222 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45223 if (extension && extension->is_hosted_app())
224 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42225
226 return PRIV_EXTENSION;
227 }
228
229 return PRIV_NORMAL;
230}
231
232RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30233 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46234 extensions::ProcessMap* process_map,
235 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46236 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30237 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46238 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21239 return PRIV_NORMAL;
240
[email protected]6f371442011-11-09 06:45:46241 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 && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42245 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45246 if (extension && extension->is_hosted_app())
247 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42248 }
249
[email protected]676f6ab2011-10-19 20:23:21250 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42251}
252
[email protected]eec0b33c2011-12-05 22:09:45253bool IsIsolatedAppInProcess(const GURL& site_url,
254 content::RenderProcessHost* process_host,
255 extensions::ProcessMap* process_map,
256 ExtensionService* service) {
257 std::set<std::string> extension_ids =
258 process_map->GetExtensionsInProcess(process_host->GetID());
259 if (extension_ids.empty())
260 return false;
261
262 for (std::set<std::string>::iterator iter = extension_ids.begin();
263 iter != extension_ids.end(); ++iter) {
264 const Extension* extension = service->GetExtensionById(*iter, false);
265 if (extension &&
266 extension->is_storage_isolated() &&
267 extension->url() == site_url)
268 return true;
269 }
270
271 return false;
272}
273
[email protected]6786bf402011-12-03 15:19:45274bool CertMatchesFilter(const net::X509Certificate& cert,
275 const base::DictionaryValue& filter) {
276 // TODO(markusheintz): This is the minimal required filter implementation.
277 // Implement a better matcher.
278
279 // An empty filter matches any client certificate since no requirements are
280 // specified at all.
281 if (filter.empty())
282 return true;
283
284 std::string common_name;
285 if (filter.GetString("ISSUER.CN", &common_name) &&
286 (cert.issuer().common_name == common_name)) {
287 return true;
288 }
289 return false;
290}
291
[email protected]f3986f82012-01-03 20:00:06292// Fills |map| with the per-script font prefs under path |map_name|.
293void FillFontFamilyMap(const PrefService* prefs,
294 const char* map_name,
295 WebPreferences::ScriptFontFamilyMap* map) {
296 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
297 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
298 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
299 std::string font_family = prefs->GetString(pref_name.c_str());
300 if (!font_family.empty())
301 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
302 }
303}
304
[email protected]9dbfff12011-07-01 19:37:07305} // namespace
[email protected]c5dbef02011-05-13 05:06:09306
[email protected]d977f9c2011-03-14 16:10:26307namespace chrome {
308
[email protected]e461da2f2012-02-16 19:06:40309ChromeContentBrowserClient::ChromeContentBrowserClient() {
310 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
311 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40312}
313
314ChromeContentBrowserClient::~ChromeContentBrowserClient() {
315}
316
[email protected]50462bf02011-11-21 19:13:31317content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
318 const content::MainFunctionParams& parameters) {
319 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30320 // Construct the Main browser parts based on the OS type.
321#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31322 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04323#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31324 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30325#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31326 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26327#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31328 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14329#elif defined(OS_ANDROID)
330 // Do nothing for Android.
331 // TODO(klobag): Android initialization should use the
332 // *BrowserMainParts class-hierarchy for setting up custom initialization.
333 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30334#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31335 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04336#else
[email protected]b48c9182011-10-26 18:03:30337 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31338 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30339#endif
340
[email protected]c7480942011-11-08 19:18:27341 // Construct additional browser parts. Stages are called in the order in
342 // which they are added.
[email protected]b48c9182011-10-26 18:03:30343#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31344 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04345#endif
[email protected]c7480942011-11-08 19:18:27346
347#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31348 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27349#endif
350
[email protected]dc04be7c2012-03-15 23:57:49351#if defined(USE_ASH)
352 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
353#endif
354
[email protected]e050ef142012-03-21 01:04:24355#if defined(USE_AURA)
356 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
357#endif
358
[email protected]50462bf02011-11-21 19:13:31359 return main_parts;
[email protected]f967b722011-09-07 00:58:04360}
361
[email protected]38b098f2012-03-14 21:11:57362content::WebContentsView*
363 ChromeContentBrowserClient::OverrideCreateWebContentsView(
364 WebContents* web_contents) {
[email protected]104e60f2012-03-26 17:58:28365#if defined(TOOLKIT_VIEWS) && (!defined(OS_WIN) || defined(USE_AURA))
[email protected]159d5142012-03-22 18:16:24366 return new TabContentsViewViews(web_contents,
367 GetWebContentsViewDelegate(web_contents));
[email protected]38b098f2012-03-14 21:11:57368#endif
369 return NULL;
370}
371
372content::WebContentsViewDelegate*
373 ChromeContentBrowserClient::GetWebContentsViewDelegate(
374 content::WebContents* web_contents) {
375#if defined(OS_WIN) && !defined(USE_AURA)
376 return new ChromeWebContentsViewDelegateWin(web_contents);
377#elif defined(TOOLKIT_GTK)
378 return new ChromeWebContentsViewDelegateGtk(web_contents);
[email protected]74313b42011-08-24 16:51:32379#elif defined(OS_MACOSX)
[email protected]38b098f2012-03-14 21:11:57380 return
381 chrome_web_contents_view_delegate_mac::CreateWebContentsViewDelegateMac(
382 web_contents);
[email protected]159d5142012-03-22 18:16:24383#elif defined(USE_AURA)
384 return new ChromeWebContentsViewDelegateAura(web_contents);
[email protected]74313b42011-08-24 16:51:32385#else
[email protected]38b098f2012-03-14 21:11:57386 return NULL;
[email protected]74313b42011-08-24 16:51:32387#endif
388}
389
[email protected]f364d1392011-04-08 21:03:10390void ChromeContentBrowserClient::RenderViewHostCreated(
391 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46392
[email protected]9f76c1e2012-03-05 15:15:58393 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46394 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02395 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46396
397 new ChromeRenderViewHostObserver(render_view_host,
398 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10399 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26400}
401
[email protected]f3b1a082011-11-18 00:34:30402void ChromeContentBrowserClient::RenderProcessHostCreated(
403 content::RenderProcessHost* host) {
404 int id = host->GetID();
405 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
406 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02407 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30408 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03409#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30410 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03411#endif
[email protected]f3b1a082011-11-18 00:34:30412 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02413 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30414 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56415#if defined(OS_MACOSX)
416 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
417#endif
[email protected]f3b1a082011-11-18 00:34:30418 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03419 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38420
[email protected]2ccf45c2011-08-19 23:35:50421 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
422 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07423
424 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56425
426 RendererContentSettingRules rules;
427 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
428 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14429}
430
[email protected]e0ada9c2012-03-20 03:54:43431void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
432 content::BrowserChildProcessHost* host) {
433 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
434}
435
[email protected]863f70a2012-01-27 02:05:50436content::WebUIControllerFactory*
437 ChromeContentBrowserClient::GetWebUIControllerFactory() {
438 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56439}
440
[email protected]3d7474ff2011-07-27 17:47:37441GURL ChromeContentBrowserClient::GetEffectiveURL(
442 content::BrowserContext* browser_context, const GURL& url) {
443 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08444 // Get the effective URL for the given actual URL. If the URL is part of an
445 // installed app, the effective URL is an extension URL with the ID of that
446 // extension as the host. This has the effect of grouping apps together in
447 // a common SiteInstance.
448 if (!profile || !profile->GetExtensionService())
449 return url;
450
[email protected]615d88f2011-12-13 01:47:44451 const Extension* extension = profile->GetExtensionService()->extensions()->
452 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08453 if (!extension)
454 return url;
455
[email protected]15877ca2011-11-18 22:40:52456 // Bookmark apps do not use the hosted app process model, and should be
457 // treated as normal URLs.
458 if (extension->from_bookmark())
459 return url;
460
[email protected]36fb2c7c2011-04-04 15:49:08461 // If the URL is part of an extension's web extent, convert it to an
462 // extension URL.
463 return extension->GetResourceURL(url.path());
464}
465
[email protected]056ad2a2011-07-12 02:13:55466bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37467 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55468 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52469 // Because we expect to use the effective URL, URLs for hosted apps (apart
470 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55471 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
472 return false;
473
[email protected]3d7474ff2011-07-27 17:47:37474 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55475 if (!profile || !profile->GetExtensionService())
476 return false;
477
[email protected]615d88f2011-12-13 01:47:44478 const Extension* extension = profile->GetExtensionService()->extensions()->
479 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55480 if (!extension)
481 return false;
482
483 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53484 // permission, or that does not allow JavaScript access to the background
485 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55486 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53487 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
488 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
489 !extension->allow_background_js_access()) {
490 return false;
491 }
492 }
[email protected]056ad2a2011-07-12 02:13:55493
[email protected]7b54ca02012-03-02 18:06:53494 // Hosted apps that have script access to their background page must use
495 // process per site, since all instances can make synchronous calls to the
496 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55497 return true;
498}
499
[email protected]46fb9442011-12-09 17:57:47500bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
501 return ProfileIOData::IsHandledURL(url);
502}
503
[email protected]2a5221b2011-09-27 23:07:31504bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30505 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31506 const GURL& site_url) {
507 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30508 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42509 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46510 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31511
[email protected]ffa97602011-11-17 17:55:52512 // Don't allow the Task Manager to share a process with anything else.
513 // Otherwise it can affect the renderers it is observing.
514 // Note: we could create another RenderProcessHostPrivilege bucket for
515 // this to allow multiple chrome://tasks instances to share, but that's
516 // a very unlikely case without serious consequences.
517 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
518 return false;
519
[email protected]8d3132f62011-10-12 07:13:42520 // These may be NULL during tests. In that case, just assume any site can
521 // share any host.
[email protected]6f371442011-11-09 06:45:46522 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31523 return true;
524
[email protected]a8c269a2011-10-25 20:17:22525 // Experimental:
526 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
527 // to share a renderer process. (We could allow pages from the same site or
528 // extensions of the same type to share, if we knew what the given process
529 // was dedicated to. Allowing no sharing is simpler for now.) This may
530 // cause resource exhaustion issues if too many sites are open at once.
531 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
532 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
533 return false;
534
[email protected]eec0b33c2011-12-05 22:09:45535 // An isolated app is only allowed to share with the exact same app in order
536 // to provide complete renderer process isolation. This also works around
537 // issue http://crbug.com/85588, where different isolated apps in the same
538 // process would end up using the first app's storage contexts.
539 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42540 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45541 if (privilege_required == PRIV_ISOLATED)
542 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
543
544 // Otherwise, just make sure the process privilege matches the privilege
545 // required by the site.
546 return GetProcessPrivilege(process_host, process_map, service) ==
547 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31548}
549
[email protected]76411f412012-02-22 18:56:06550// This function is trying to limit the amount of processes used by extensions
551// with background pages. It uses a globally set percentage of processes to
552// run such extensions and if the limit is exceeded, it returns true, to
553// indicate to the content module to group extensions together.
554bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
555 content::BrowserContext* browser_context, const GURL& url) {
556 // It has to be a valid URL for us to check for an extension.
557 if (!url.is_valid())
558 return false;
559
560 Profile* profile = Profile::FromBrowserContext(browser_context);
561 ExtensionService* service = profile->GetExtensionService();
562 if (!service)
563 return false;
564
565 // We have to have a valid extension with background page to proceed.
566 const Extension* extension =
567 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
568 if (!extension)
569 return false;
570 if (!extension->has_background_page())
571 return false;
572
573 std::set<int> process_ids;
574 size_t max_process_count =
575 content::RenderProcessHost::GetMaxRendererProcessCount();
576
577 // Go through all profiles to ensure we have total count of extension
578 // processes containing background pages, otherwise one profile can
579 // starve the other.
580 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
581 GetLoadedProfiles();
582 for (size_t i = 0; i < profiles.size(); ++i) {
583 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
584 for (ExtensionProcessManager::const_iterator iter = epm->begin();
585 iter != epm->end();
586 ++iter) {
587 ExtensionHost* host = *iter;
588 if (host->extension()->has_background_page()) {
589 process_ids.insert(host->render_process_host()->GetID());
590 }
591 }
592 }
593
594 if (process_ids.size() >
595 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
596 return true;
597 }
598
599 return false;
600}
601
[email protected]6f371442011-11-09 06:45:46602void ChromeContentBrowserClient::SiteInstanceGotProcess(
603 SiteInstance* site_instance) {
604 CHECK(site_instance->HasProcess());
605
606 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02607 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46608 ExtensionService* service = profile->GetExtensionService();
609 if (!service)
610 return;
611
612 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44613 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33614 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46615 if (!extension)
616 return;
617
[email protected]6bc04fd82011-12-04 02:29:35618 service->process_map()->Insert(extension->id(),
619 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33620 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46621 BrowserThread::PostTask(
622 BrowserThread::IO, FROM_HERE,
623 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]e15be2b2012-03-09 08:42:11624 profile->GetExtensionInfoMap(),
[email protected]6f371442011-11-09 06:45:46625 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35626 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33627 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46628}
629
630void ChromeContentBrowserClient::SiteInstanceDeleting(
631 SiteInstance* site_instance) {
632 if (!site_instance->HasProcess())
633 return;
634
635 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02636 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46637 ExtensionService* service = profile->GetExtensionService();
638 if (!service)
639 return;
640
641 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44642 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33643 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46644 if (!extension)
645 return;
646
[email protected]6bc04fd82011-12-04 02:29:35647 service->process_map()->Remove(extension->id(),
648 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33649 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46650 BrowserThread::PostTask(
651 BrowserThread::IO, FROM_HERE,
652 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]e15be2b2012-03-09 08:42:11653 profile->GetExtensionInfoMap(),
[email protected]6f371442011-11-09 06:45:46654 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35655 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33656 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46657}
658
[email protected]e3daf3c2011-10-05 21:17:08659bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
660 const GURL& current_url,
661 const GURL& new_url) {
662 if (current_url.is_empty()) {
663 // Always choose a new process when navigating to extension URLs. The
664 // process grouping logic will combine all of a given extension's pages
665 // into the same process.
666 if (new_url.SchemeIs(chrome::kExtensionScheme))
667 return true;
668
669 return false;
670 }
671
672 // Also, we must switch if one is an extension and the other is not the exact
673 // same extension.
674 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
675 new_url.SchemeIs(chrome::kExtensionScheme)) {
676 if (current_url.GetOrigin() != new_url.GetOrigin())
677 return true;
678 }
679
680 return false;
681}
682
[email protected]763ec4ca2011-04-29 15:48:12683std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
684 const std::string& alias_name) {
685 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
686}
687
[email protected]b80f68432011-05-02 17:22:30688void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
689 CommandLine* command_line, int child_process_id) {
690#if defined(USE_LINUX_BREAKPAD)
691 if (IsCrashReporterEnabled()) {
692 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
693 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
694 }
695#elif defined(OS_MACOSX)
696 if (IsCrashReporterEnabled()) {
697 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
698 child_process_logging::GetClientId());
699 }
700#endif // OS_MACOSX
701
[email protected]f1933792011-06-14 00:49:34702 if (logging::DialogsAreSuppressed())
703 command_line->AppendSwitch(switches::kNoErrorDialogs);
704
[email protected]b80f68432011-05-02 17:22:30705 std::string process_type =
706 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17707 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52708 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30709 FilePath user_data_dir =
710 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
711 if (!user_data_dir.empty())
712 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
713#if defined(OS_CHROMEOS)
714 const std::string& login_profile =
715 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
716 if (!login_profile.empty())
717 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
718#endif
719
[email protected]f3b1a082011-11-18 00:34:30720 content::RenderProcessHost* process =
721 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37722 if (process) {
723 Profile* profile = Profile::FromBrowserContext(
724 process->GetBrowserContext());
725 extensions::ProcessMap* process_map =
726 profile->GetExtensionService()->process_map();
727 if (process_map && process_map->Contains(process->GetID()))
728 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30729
[email protected]a8d851f82011-12-21 00:32:37730 PrefService* prefs = profile->GetPrefs();
731 // Currently this pref is only registered if applied via a policy.
732 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
733 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
734 // Turn this policy into a command line switch.
735 command_line->AppendSwitch(switches::kDisable3DAPIs);
736 }
[email protected]718eab62011-10-05 21:16:52737
[email protected]a8d851f82011-12-21 00:32:37738 // Disable client-side phishing detection in the renderer if it is
739 // disabled in the Profile preferences or the browser process.
740 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
741 !g_browser_process->safe_browsing_detection_service()) {
742 command_line->AppendSwitch(
743 switches::kDisableClientSidePhishingDetection);
744 }
[email protected]8c40da62011-07-13 22:58:46745 }
[email protected]47c7ec82012-01-18 03:29:21746 {
747 PrefService* local_state = g_browser_process->local_state();
748 if (local_state &&
749 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
750 command_line->AppendSwitch(switches::kRendererPrintPreview);
751 }
752 }
[email protected]4287a3d2011-06-13 23:56:51753
[email protected]47c7ec82012-01-18 03:29:21754 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51755 static const char* const kSwitchNames[] = {
756 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48757 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51758 switches::kAllowScriptingGallery,
759 switches::kAppsCheckoutURL,
760 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31761 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51762 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50763 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51764 switches::kDumpHistogramsOnExit,
[email protected]b7e44ff2012-02-16 03:37:34765 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21766 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13767 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51768 switches::kEnableCrxlessWebApps,
769 switches::kEnableExperimentalExtensionApis,
770 switches::kEnableInBrowserThumbnailing,
771 switches::kEnableIPCFuzzing,
772 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:48773 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53774 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51775 switches::kEnableWatchdog,
776 switches::kExperimentalSpellcheckerFeatures,
777 switches::kMemoryProfiling,
778 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04779 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51780 switches::kPpapiFlashArgs,
781 switches::kPpapiFlashInProcess,
782 switches::kPpapiFlashPath,
783 switches::kPpapiFlashVersion,
784 switches::kProfilingAtStart,
785 switches::kProfilingFile,
786 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51787 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38788 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51789 };
790
791 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
792 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17793 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38794 static const char* const kSwitchNames[] = {
795 switches::kEnableExperimentalExtensionApis,
[email protected]ee14cad2012-03-29 01:59:37796 switches::kEnablePlatformApps,
[email protected]a446534d2012-02-09 00:07:38797 switches::kWhitelistedExtensionID,
798 };
799
800 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
801 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51802 } else if (process_type == switches::kPluginProcess) {
803 static const char* const kSwitchNames[] = {
804 #if defined(OS_CHROMEOS)
805 switches::kLoginProfile,
806 #endif
807 switches::kMemoryProfiling,
808 switches::kSilentDumpOnDCHECK,
809 switches::kUserDataDir,
810 };
811
812 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
813 arraysize(kSwitchNames));
814 } else if (process_type == switches::kZygoteProcess) {
815 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51816 switches::kUserDataDir, // Make logs go to the right file.
817 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50818 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13819 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51820 switches::kPpapiFlashInProcess,
821 switches::kPpapiFlashPath,
822 switches::kPpapiFlashVersion,
823 };
824
825 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
826 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11827 } else if (process_type == switches::kGpuProcess) {
828 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
829 // because GPU is expected to be unreliable.
830 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
831 !command_line->HasSwitch(switches::kDisableBreakpad))
832 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30833 }
[email protected]6f08af82011-09-15 01:19:03834
835 // The command line switch kEnableBenchmarking needs to be specified along
836 // with the kEnableStatsTable switch to ensure that the stats table global
837 // is initialized correctly.
838 if (command_line->HasSwitch(switches::kEnableBenchmarking))
839 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30840}
841
842std::string ChromeContentBrowserClient::GetApplicationLocale() {
843 return g_browser_process->GetApplicationLocale();
844}
845
[email protected]597a867b2011-11-18 18:31:20846std::string ChromeContentBrowserClient::GetAcceptLangs(
847 content::BrowserContext* context) {
848 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37849 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08850}
851
[email protected]ac55e292011-06-24 05:16:08852SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22853 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08854 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
855}
856
[email protected]a2176792011-05-08 19:30:49857bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09858 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19859 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20860 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32861 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20862 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05863 return io_data->GetCookieSettings()->
864 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49865}
866
[email protected]ed24fad2011-05-10 22:44:01867bool ChromeContentBrowserClient::AllowGetCookie(
868 const GURL& url,
869 const GURL& first_party,
870 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20871 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01872 int render_process_id,
873 int render_view_id) {
874 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20875 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05876 bool allow = io_data->GetCookieSettings()->
877 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01878
[email protected]8093a542011-05-13 07:29:32879 BrowserThread::PostTask(
880 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03881 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
882 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01883 return allow;
884}
885
886bool ChromeContentBrowserClient::AllowSetCookie(
887 const GURL& url,
888 const GURL& first_party,
889 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20890 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01891 int render_process_id,
892 int render_view_id,
893 net::CookieOptions* options) {
894 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20895 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05896 CookieSettings* cookie_settings = io_data->GetCookieSettings();
897 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
898
899 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09900 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01901
[email protected]8093a542011-05-13 07:29:32902 BrowserThread::PostTask(
903 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03904 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
905 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01906 return allow;
907}
908
[email protected]d5a19162011-06-30 18:51:54909bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20910 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54911 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20912 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26913
[email protected]f24bd172012-03-31 01:54:59914 return !io_data->clear_local_state_on_exit()->GetValue();
[email protected]d5a19162011-06-30 18:51:54915}
916
[email protected]5c5a88e2011-11-12 00:45:35917bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35918 const GURL& url,
919 const string16& name,
920 const string16& display_name,
921 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20922 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48923 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35924 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20925 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35926 CookieSettings* cookie_settings = io_data->GetCookieSettings();
927 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
928
[email protected]62151052012-02-01 18:40:48929 // Record access to database for potential display in UI.
930 std::vector<std::pair<int, int> >::const_iterator i;
931 for (i = render_views.begin(); i != render_views.end(); ++i) {
932 BrowserThread::PostTask(
933 BrowserThread::UI, FROM_HERE,
934 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
935 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35936 }
937
938 return allow;
939}
940
941bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35942 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20943 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48944 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35945 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20946 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35947 CookieSettings* cookie_settings = io_data->GetCookieSettings();
948 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
949
[email protected]62151052012-02-01 18:40:48950 // Record access to file system for potential display in UI.
951 std::vector<std::pair<int, int> >::const_iterator i;
952 for (i = render_views.begin(); i != render_views.end(); ++i) {
953 BrowserThread::PostTask(
954 BrowserThread::UI, FROM_HERE,
955 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
956 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35957 }
958
959 return allow;
960}
961
[email protected]7c5ff9a2012-03-02 07:42:49962bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
963 const GURL& url,
964 const string16& name,
965 content::ResourceContext* context,
966 const std::vector<std::pair<int, int> >& render_views) {
967 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
968 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
969 CookieSettings* cookie_settings = io_data->GetCookieSettings();
970 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
971
972 // Record access to IndexedDB for potential display in UI.
973 std::vector<std::pair<int, int> >::const_iterator i;
974 for (i = render_views.begin(); i != render_views.end(); ++i) {
975 BrowserThread::PostTask(
976 BrowserThread::UI, FROM_HERE,
977 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
978 i->first, i->second, url, name, !allow));
979 }
980
981 return allow;
982}
983
[email protected]6133f922011-07-01 21:34:34984net::URLRequestContext*
985ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20986 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34987 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
988 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20989 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34990 return io_data->extensions_request_context();
991 }
992
993 return NULL;
994}
995
[email protected]317f96c92011-05-31 06:53:41996QuotaPermissionContext*
997ChromeContentBrowserClient::CreateQuotaPermissionContext() {
998 return new ChromeQuotaPermissionContext();
999}
1000
[email protected]a0ce3282011-08-19 20:49:521001void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421002 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421003}
1004
[email protected]a0ce3282011-08-19 20:49:521005void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521006 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521007}
1008
[email protected]848dd042011-06-04 18:24:031009void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171010 int render_process_id,
1011 int render_view_id,
1012 int cert_error,
1013 const net::SSLInfo& ssl_info,
1014 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031015 bool overridable,
[email protected]4cf611e32012-02-13 16:06:171016 const base::Callback<void(bool)>& callback,
1017 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411018 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131019 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171020 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411021 if (!tab) {
1022 NOTREACHED();
1023 return;
1024 }
1025 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501026 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301027 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091028 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411029 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171030 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411031 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171032 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411033 return;
1034 }
1035 }
1036
1037 // Otherwise, display an SSL blocking page.
[email protected]4cf611e32012-02-13 16:06:171038 new SSLBlockingPage(
1039 tab, cert_error, ssl_info, request_url, overridable, callback);
[email protected]848dd042011-06-04 18:24:031040}
1041
[email protected]c99c442e2011-08-24 11:37:301042void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451043 int render_process_id,
1044 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401045 const net::HttpNetworkSession* network_session,
1046 net::SSLCertRequestInfo* cert_request_info,
1047 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131048 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451049 render_process_id, render_view_id);
1050 if (!tab) {
1051 NOTREACHED();
1052 return;
1053 }
1054
[email protected]6786bf402011-12-03 15:19:451055 GURL requesting_url("https://" + cert_request_info->host_and_port);
1056 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1057 << cert_request_info->host_and_port;
1058
[email protected]627e0512011-12-21 22:55:301059 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451060 scoped_ptr<Value> filter(
1061 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1062 requesting_url,
1063 requesting_url,
1064 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1065 std::string(), NULL));
1066
1067 if (filter.get()) {
1068 // Try to automatically select a client certificate.
1069 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1070 DictionaryValue* filter_dict =
1071 static_cast<DictionaryValue*>(filter.get());
1072
1073 const std::vector<scoped_refptr<net::X509Certificate> >&
1074 all_client_certs = cert_request_info->client_certs;
1075 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1076 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1077 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401078 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451079 return;
1080 }
1081 }
1082 } else {
1083 NOTREACHED();
1084 }
1085 }
1086
[email protected]8ec26472011-06-06 16:52:451087 TabContentsWrapper* wrapper =
1088 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451089 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131090 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451091 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141092 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401093 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451094 return;
1095 }
[email protected]7a593db2012-02-13 21:19:401096 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1097 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451098}
1099
1100void ChromeContentBrowserClient::AddNewCertificate(
1101 net::URLRequest* request,
1102 net::X509Certificate* cert,
1103 int render_process_id,
1104 int render_view_id) {
1105 // The handler will run the UI and delete itself when it's finished.
1106 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1107}
1108
[email protected]a93670ab2012-02-24 03:46:391109void ChromeContentBrowserClient::RequestMediaAccessPermission(
1110 const content::MediaStreamRequest* request,
1111 const content::MediaResponseCallback& callback) {
1112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1113
[email protected]117b6b42012-02-29 09:11:081114 WebContents* contents = tab_util::GetWebContentsByID(
1115 request->render_process_id, request->render_view_id);
1116 if (!contents) {
1117 // Abort, if the tab was closed after the request was made but before we
1118 // got to this point.
1119 callback.Run(content::MediaStreamDevices());
1120 return;
1121 }
1122
1123 TabContentsWrapper* tab =
1124 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1125 DCHECK(tab);
1126
1127 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1128 InfoBarDelegate* old_infobar = NULL;
1129 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1130 old_infobar =
1131 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfobarDelegate();
1132 }
1133
[email protected]3bc518b2012-03-09 03:01:501134#if defined(TOOLKIT_VIEWS) || defined(OS_LINUX)
[email protected]117b6b42012-02-29 09:11:081135 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1136 request,
1137 callback);
1138 if (old_infobar)
1139 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1140 else
1141 infobar_helper->AddInfoBar(infobar);
[email protected]3bc518b2012-03-09 03:01:501142#elif defined(OS_MACOSX)
1143 // TODO(macourteau): UI is not implemented yet for OS X. Fallback to
[email protected]117b6b42012-02-29 09:11:081144 // the default behaviour and allow access to the first device of each
1145 // requested type.
1146 content::MediaStreamDevices devices;
[email protected]a93670ab2012-02-24 03:46:391147 for (content::MediaStreamDeviceMap::const_iterator it =
1148 request->devices.begin(); it != request->devices.end(); ++it) {
[email protected]6c6415a2012-03-01 17:17:281149 if (!it->second.empty())
1150 devices.push_back(*it->second.begin());
[email protected]a93670ab2012-02-24 03:46:391151 }
1152
[email protected]a93670ab2012-02-24 03:46:391153 callback.Run(devices);
[email protected]3bc518b2012-03-09 03:01:501154#endif // TOOLKIT_VIEWS || OS_LINUX
[email protected]a93670ab2012-02-24 03:46:391155}
1156
[email protected]dc73a7b2012-03-25 15:27:181157content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1158 return MediaInternals::GetInstance();
1159}
1160
[email protected]941623e2011-06-07 23:06:041161void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1162 const GURL& source_origin,
1163 int callback_context,
1164 int render_process_id,
1165 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111166#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041167 RenderViewHost* rvh = RenderViewHost::FromID(
1168 render_process_id, render_view_id);
1169 if (!rvh) {
1170 NOTREACHED();
1171 return;
1172 }
1173
[email protected]9f76c1e2012-03-05 15:15:581174 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301175 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041176 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371177 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041178 service->RequestPermission(
1179 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131180 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111181#else
1182 NOTIMPLEMENTED();
1183#endif
[email protected]941623e2011-06-07 23:06:041184}
1185
1186WebKit::WebNotificationPresenter::Permission
1187 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021188 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201189 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021190 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111191#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201193 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021194 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1195 source_origin, render_process_id,
1196 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041197 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041198
1199 // Fall back to the regular notification preferences, which works on an
1200 // origin basis.
1201 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371202 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041203 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111204#else
1205 return WebKit::WebNotificationPresenter::PermissionAllowed;
1206#endif
[email protected]941623e2011-06-07 23:06:041207}
1208
1209void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171210 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041211 int render_process_id,
1212 int render_view_id,
1213 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111214#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041215 RenderViewHost* rvh = RenderViewHost::FromID(
1216 render_process_id, render_view_id);
1217 if (!rvh) {
1218 NOTREACHED();
1219 return;
1220 }
1221
[email protected]9f76c1e2012-03-05 15:15:581222 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301223 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041224 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371225 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041226 service->ShowDesktopNotification(
1227 params, render_process_id, render_view_id,
1228 worker ? DesktopNotificationService::WorkerNotification :
1229 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111230#else
1231 NOTIMPLEMENTED();
1232#endif
[email protected]941623e2011-06-07 23:06:041233}
1234
1235void ChromeContentBrowserClient::CancelDesktopNotification(
1236 int render_process_id,
1237 int render_view_id,
1238 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111239#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041240 RenderViewHost* rvh = RenderViewHost::FromID(
1241 render_process_id, render_view_id);
1242 if (!rvh) {
1243 NOTREACHED();
1244 return;
1245 }
1246
[email protected]9f76c1e2012-03-05 15:15:581247 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301248 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041249 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371250 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041251 service->CancelDesktopNotification(
1252 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111253#else
1254 NOTIMPLEMENTED();
1255#endif
[email protected]941623e2011-06-07 23:06:041256}
1257
[email protected]9f3fba52011-06-08 20:37:191258bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351259 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021260 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191261 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201262 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011263 int render_process_id,
1264 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011266
1267 *no_javascript_access = false;
1268
[email protected]9f3fba52011-06-08 20:37:191269 // If the opener is trying to create a background window but doesn't have
1270 // the appropriate permission, fail the attempt.
1271 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201272 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531273 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1274
[email protected]03b6d552012-03-29 04:03:011275 if (!map->SecurityOriginHasAPIPermission(
1276 source_origin,
1277 render_process_id,
1278 ExtensionAPIPermission::kBackground)) {
1279 return false;
1280 }
1281
[email protected]7b54ca02012-03-02 18:06:531282 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1283 // return a recently installed Extension even if this CanCreateWindow call
1284 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011285 // because the permission check above would have caused an early return
1286 // already. We must use the full URL to find hosted apps, though, and not
1287 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531288 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351289 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531290 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011291 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191292 }
1293 return true;
1294}
1295
1296std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201297 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1299 // Check if it's an extension-created worker, in which case we want to use
1300 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201301 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191302 const Extension* extension =
1303 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1304 return extension ? extension->name() : std::string();
1305}
1306
[email protected]99907362012-01-11 05:41:401307void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1308 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171309}
1310
[email protected]c52b2892012-03-07 11:01:021311content::SpeechRecognitionManagerDelegate*
1312 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321313#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021314 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321315#else
1316 return NULL;
1317#endif
[email protected]66cfec62012-02-24 17:57:511318}
1319
[email protected]3cb054e62011-06-13 05:21:171320ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1321 return g_browser_process->clipboard();
1322}
1323
[email protected]ae6e9912011-07-27 01:18:281324net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1325 return g_browser_process->net_log();
1326}
1327
[email protected]32538d92011-08-25 00:09:231328AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1329 return new ChromeAccessTokenStore();
1330}
1331
[email protected]dbae6b02011-06-29 23:51:411332bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1333 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1334 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1335}
1336
[email protected]64d69de42012-02-06 00:19:541337void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321338 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061339 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581340 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061341 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061342
[email protected]64d69de42012-02-06 00:19:541343 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061344 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541345 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061346 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541347 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061348 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541349 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061350 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541351 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061352 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541353 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061354 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1355
1356 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541357 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061358 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541359 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061360 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541361 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061362 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541363 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061364 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541365 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061366 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541367 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061368
[email protected]64d69de42012-02-06 00:19:541369 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061370 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541371 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061372 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541373 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061374 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541375 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061376 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1377
[email protected]64d69de42012-02-06 00:19:541378 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061379
[email protected]64d69de42012-02-06 00:19:541380 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061381 prefs->GetBoolean(
1382 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541383 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061384 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541385 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061386 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1387 const DictionaryValue* inspector_settings =
1388 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1389 if (inspector_settings) {
1390 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1391 iter != inspector_settings->end_keys(); ++iter) {
1392 std::string value;
1393 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541394 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061395 std::make_pair(*iter, value));
1396 }
1397 }
[email protected]64d69de42012-02-06 00:19:541398 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061399
[email protected]64d69de42012-02-06 00:19:541400 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1401 web_prefs->javascript_enabled = false;
1402 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1403 web_prefs->web_security_enabled = false;
1404 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1405 web_prefs->plugins_enabled = false;
1406 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1407 web_prefs->java_enabled = false;
1408 web_prefs->loads_images_automatically =
1409 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061410
[email protected]64d69de42012-02-06 00:19:541411 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1412 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061413
[email protected]64d69de42012-02-06 00:19:541414 web_prefs->memory_info_enabled =
1415 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1416 web_prefs->allow_displaying_insecure_content =
1417 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1418 web_prefs->allow_running_insecure_content =
1419 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081420 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061421
[email protected]64d69de42012-02-06 00:19:541422 // The user stylesheet watcher may not exist in a testing profile.
1423 if (profile->GetUserStyleSheetWatcher()) {
1424 web_prefs->user_style_sheet_enabled = true;
1425 web_prefs->user_style_sheet_location =
1426 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1427 } else {
1428 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061429 }
1430
[email protected]b7e44ff2012-02-16 03:37:341431 web_prefs->asynchronous_spell_checking_enabled =
1432 CommandLine::ForCurrentProcess()->
1433 HasSwitch(switches::kEnableAsynchronousSpellChecking);
1434 web_prefs->unified_textchecker_enabled =
1435 web_prefs->asynchronous_spell_checking_enabled ||
1436 CommandLine::ForCurrentProcess()->
1437 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571438
[email protected]64d69de42012-02-06 00:19:541439 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061440 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541441 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061442 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541443 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061444 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1445
1446 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541447 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061448 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541449 web_prefs->default_encoding);
1450 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061451 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541452 web_prefs->default_encoding =
1453 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061454 }
[email protected]64d69de42012-02-06 00:19:541455 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061456
1457 ExtensionService* service = profile->GetExtensionService();
1458 if (service) {
1459 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581460 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061461 extension_webkit_preferences::SetPreferences(
[email protected]9f76c1e2012-03-05 15:15:581462 extension, rvh->GetDelegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061463 }
1464
[email protected]9f76c1e2012-03-05 15:15:581465 if (rvh->GetDelegate()->GetRenderViewType() ==
1466 chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541467 web_prefs->allow_scripts_to_close_windows = true;
[email protected]9f76c1e2012-03-05 15:15:581468 } else if (rvh->GetDelegate()->GetRenderViewType() ==
[email protected]f3986f82012-01-03 20:00:061469 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1470 // Disable all kinds of acceleration for background pages.
1471 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541472 web_prefs->force_compositing_mode = false;
1473 web_prefs->accelerated_compositing_enabled = false;
1474 web_prefs->accelerated_2d_canvas_enabled = false;
1475 web_prefs->accelerated_video_enabled = false;
1476 web_prefs->accelerated_painting_enabled = false;
1477 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061478 }
[email protected]2e21fe292012-03-02 22:52:321479
1480#if defined(FILE_MANAGER_EXTENSION)
1481 // Override the default of suppressing HW compositing for WebUI pages for the
1482 // file manager, which is implemented using WebUI but wants HW acceleration
1483 // for video decode & render.
1484 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1485 web_prefs->accelerated_compositing_enabled = true;
1486 web_prefs->accelerated_2d_canvas_enabled = true;
1487 }
1488#endif
[email protected]181a95ee2011-07-12 19:26:361489}
1490
1491void ChromeContentBrowserClient::UpdateInspectorSetting(
1492 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061493 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581494 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061495 DictionaryPrefUpdate update(
1496 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1497 prefs::kWebKitInspectorSettings);
1498 DictionaryValue* inspector_settings = update.Get();
1499 inspector_settings->SetWithoutPathExpansion(key,
1500 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361501}
1502
1503void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061504 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581505 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061506 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1507 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361508}
1509
[email protected]b8148ac2011-07-13 22:03:251510void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1511 BrowserURLHandler* handler) {
1512 // Add the default URL handlers.
1513 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1514 BrowserURLHandler::null_handler());
1515 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1516 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1517
[email protected]b3adbd02011-11-30 22:23:271518 // about: handler. Must come before chrome: handler, since it will
1519 // rewrite about: urls to chrome: URLs and then expect chrome: to
1520 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251521 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1522 BrowserURLHandler::null_handler());
1523 // chrome: & friends.
1524 handler->AddHandlerPair(&HandleWebUI,
1525 BrowserURLHandler::null_handler());
1526}
1527
1528void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371529 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581530 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251531 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1532 BrowsingDataRemover::EVERYTHING,
1533 base::Time());
1534 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1535 // BrowsingDataRemover takes care of deleting itself when done.
1536}
1537
1538void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371539 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581540 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251541 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1542 BrowsingDataRemover::EVERYTHING,
1543 base::Time());
[email protected]dceaa912011-09-06 17:17:231544 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251545 remover->Remove(remove_mask);
1546 // BrowsingDataRemover takes care of deleting itself when done.
1547}
1548
[email protected]e1d16eb92011-08-18 23:19:321549FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1550 return download_util::GetDefaultDownloadDirectory();
1551}
1552
[email protected]c9b6eb62011-10-18 20:49:391553std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1554 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1555}
1556
[email protected]a658d452012-03-02 12:45:291557bool ChromeContentBrowserClient::AllowSocketAPI(
1558 content::BrowserContext* browser_context, const GURL& url) {
1559 if (!url.is_valid())
1560 return false;
1561
1562 std::string host = url.host();
1563 if (allowed_socket_origins_.count(host))
1564 return true;
1565
[email protected]f237c0f2012-03-10 07:49:101566 // Need to check this now and not on construction because otherwise it won't
1567 // work with browser_tests.
1568 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1569 std::string allowed_list =
1570 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
1571 if (!allowed_list.empty()) {
1572 StringTokenizer t(allowed_list, ",");
1573 while (t.GetNext()) {
1574 if (t.token() == host)
1575 return true;
1576 }
1577 }
1578
[email protected]a658d452012-03-02 12:45:291579 Profile* profile = Profile::FromBrowserContext(browser_context);
1580 if (!profile || !profile->GetExtensionService())
1581 return false;
1582
1583 const Extension* extension = profile->GetExtensionService()->extensions()->
1584 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1585 if (!extension)
1586 return false;
1587
1588 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1589 return true;
1590
1591 return false;
[email protected]e461da2f2012-02-16 19:06:401592}
1593
[email protected]e60c0232011-11-11 19:56:351594#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301595int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521596 const CommandLine& command_line) {
[email protected]6e677a342012-02-11 01:21:141597#if defined(OS_ANDROID)
1598 // TODO(carlosvaldivia): Upstream breakpad code for Android and remove this
1599 // fork. http://crbug.com/113560
1600 NOTIMPLEMENTED();
1601#else
[email protected]718eab62011-10-05 21:16:521602 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071603 ExtensionCrashHandlerHostLinux* crash_handler =
1604 ExtensionCrashHandlerHostLinux::GetInstance();
1605 return crash_handler->GetDeathSignalSocket();
1606 }
1607
[email protected]718eab62011-10-05 21:16:521608 std::string process_type =
1609 command_line.GetSwitchValueASCII(switches::kProcessType);
1610
1611 if (process_type == switches::kRendererProcess)
1612 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1613
[email protected]b80f68432011-05-02 17:22:301614 if (process_type == switches::kPluginProcess)
1615 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1616
1617 if (process_type == switches::kPpapiPluginProcess)
1618 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1619
1620 if (process_type == switches::kGpuProcess)
1621 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
[email protected]6e677a342012-02-11 01:21:141622#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:301623
1624 return -1;
1625}
[email protected]e60c0232011-11-11 19:56:351626#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301627
[email protected]4a65826d2011-08-25 16:04:011628#if defined(OS_WIN)
1629const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1630 return chrome::kBrowserResourcesDll;
1631}
1632#endif
1633
[email protected]37a72af2011-06-13 05:42:011634#if defined(USE_NSS)
1635crypto::CryptoModuleBlockingPasswordDelegate*
1636 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1637 const GURL& url) {
1638 return browser::NewCryptoModuleBlockingDialogDelegate(
1639 browser::kCryptoModulePasswordKeygen, url.host());
1640}
1641#endif
1642
[email protected]d977f9c2011-03-14 16:10:261643} // namespace chrome