blob: 707ca7a728ece6ba7db8f73bcf40918523c5a4de [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]31d8f5f22012-04-02 15:22:0834#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2535#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0636#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]32538d92011-08-25 00:09:2337#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1238#include "chrome/browser/google/google_util.h"
[email protected]117b6b42012-02-29 09:11:0839#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]dc73a7b2012-03-25 15:27:1840#include "chrome/browser/media/media_internals.h"
[email protected]ae6e9912011-07-27 01:18:2841#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0442#include "chrome/browser/notifications/desktop_notification_service.h"
43#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]e0ada9c2012-03-20 03:54:4344#include "chrome/browser/pepper_gtalk_message_filter.h"
[email protected]0609b17f2011-05-31 20:13:4245#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1246#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0647#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4148#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5049#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4150#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1451#include "chrome/browser/printing/printing_message_filter.h"
52#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3253#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0654#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1455#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3356#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4257#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1458#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0259#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4660#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4561#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0362#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4563#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
64#include "chrome/browser/tab_contents/tab_util.h"
[email protected]117b6b42012-02-29 09:11:0865#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]8ec26472011-06-06 16:52:4566#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]863f70a2012-01-27 02:05:5067#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0668#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1569#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]b80f68432011-05-02 17:22:3070#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0171#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3072#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0473#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4474#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3475#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1276#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3877#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0978#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4379#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3080#include "content/public/browser/browser_main_parts.h"
[email protected]825b1662012-03-12 19:07:3181#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5982#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3083#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3384#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0585#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3386#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1987#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1088#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4389#include "content/public/common/child_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3990#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3491#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4092#include "net/base/ssl_cert_request_info.h"
[email protected]aa84a7e2012-03-15 21:29:0693#include "net/cookies/cookie_monster.h"
94#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3995#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0896#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3697#include "webkit/glue/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:2698
[email protected]b48c9182011-10-26 18:03:3099#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38100#include "chrome/browser/chrome_browser_main_win.h"
101#elif defined(OS_MACOSX)
102#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56103#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]38b098f2012-03-14 21:11:57104#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h"
[email protected]b48c9182011-10-26 18:03:30105#elif defined(OS_CHROMEOS)
106#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49107#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26108#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30109#include "chrome/browser/chrome_browser_main_linux.h"
110#elif defined(OS_POSIX)
111#include "chrome/browser/chrome_browser_main_posix.h"
112#endif
113
[email protected]c0d7f792012-04-18 19:16:00114#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13115#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_views.h"
[email protected]61e69822012-03-14 22:08:57116#endif
117
[email protected]a13283cc2012-04-05 00:21:22118#if defined(TOOLKIT_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]c7480942011-11-08 19:18:27124#endif
125
126#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31127#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
128#endif
129
[email protected]dc04be7c2012-03-15 23:57:49130#if defined(USE_ASH)
131#include "chrome/browser/chrome_browser_main_extra_parts_ash.h"
132#endif
133
[email protected]6653c192012-04-10 22:52:44134#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30135#include "base/linux_util.h"
[email protected]6653c192012-04-10 22:52:44136#include "chrome/browser/crash_handler_host_linuxish.h"
[email protected]1fd5302c2011-05-28 04:06:43137#endif
[email protected]b80f68432011-05-02 17:22:30138
[email protected]38b098f2012-03-14 21:11:57139#if defined(TOOLKIT_GTK)
140#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_gtk.h"
[email protected]74313b42011-08-24 16:51:32141#endif
[email protected]37a72af2011-06-13 05:42:01142#if defined(USE_NSS)
143#include "chrome/browser/ui/crypto_module_password_dialog.h"
144#endif
145
[email protected]c8c77182011-12-21 15:04:47146using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39147using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31148using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59149using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00150using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11151using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33152using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13153using content::WebContents;
[email protected]631bb742011-11-02 11:29:39154
[email protected]c5dbef02011-05-13 05:06:09155namespace {
156
[email protected]e461da2f2012-02-16 19:06:40157const char* kPredefinedAllowedSocketOrigins[] = {
158 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18159 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
160 "bglhmjfplikpjnfoegeomebmfnkjomhe" // see crbug.com/122126
[email protected]e461da2f2012-02-16 19:06:40161};
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]a13283cc2012-04-05 00:21:22343#if defined(TOOLKIT_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]38b098f2012-03-14 21:11:57365 return NULL;
366}
367
368content::WebContentsViewDelegate*
369 ChromeContentBrowserClient::GetWebContentsViewDelegate(
370 content::WebContents* web_contents) {
[email protected]c0d7f792012-04-18 19:16:00371#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13372 return new ChromeWebContentsViewDelegateViews(web_contents);
[email protected]38b098f2012-03-14 21:11:57373#elif defined(TOOLKIT_GTK)
374 return new ChromeWebContentsViewDelegateGtk(web_contents);
[email protected]74313b42011-08-24 16:51:32375#elif defined(OS_MACOSX)
[email protected]38b098f2012-03-14 21:11:57376 return
377 chrome_web_contents_view_delegate_mac::CreateWebContentsViewDelegateMac(
378 web_contents);
[email protected]74313b42011-08-24 16:51:32379#else
[email protected]38b098f2012-03-14 21:11:57380 return NULL;
[email protected]74313b42011-08-24 16:51:32381#endif
382}
383
[email protected]f364d1392011-04-08 21:03:10384void ChromeContentBrowserClient::RenderViewHostCreated(
385 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46386
[email protected]9f76c1e2012-03-05 15:15:58387 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46388 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02389 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46390
391 new ChromeRenderViewHostObserver(render_view_host,
392 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10393 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26394}
395
[email protected]f3b1a082011-11-18 00:34:30396void ChromeContentBrowserClient::RenderProcessHostCreated(
397 content::RenderProcessHost* host) {
398 int id = host->GetID();
399 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
400 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02401 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30402 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03403#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30404 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03405#endif
[email protected]f3b1a082011-11-18 00:34:30406 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02407 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30408 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56409#if defined(OS_MACOSX)
410 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
411#endif
[email protected]f3b1a082011-11-18 00:34:30412 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03413 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38414
[email protected]2ccf45c2011-08-19 23:35:50415 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
416 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07417
418 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56419
420 RendererContentSettingRules rules;
421 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
422 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14423}
424
[email protected]e0ada9c2012-03-20 03:54:43425void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
426 content::BrowserChildProcessHost* host) {
427 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
428}
429
[email protected]863f70a2012-01-27 02:05:50430content::WebUIControllerFactory*
431 ChromeContentBrowserClient::GetWebUIControllerFactory() {
432 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56433}
434
[email protected]3d7474ff2011-07-27 17:47:37435GURL ChromeContentBrowserClient::GetEffectiveURL(
436 content::BrowserContext* browser_context, const GURL& url) {
437 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08438 // Get the effective URL for the given actual URL. If the URL is part of an
439 // installed app, the effective URL is an extension URL with the ID of that
440 // extension as the host. This has the effect of grouping apps together in
441 // a common SiteInstance.
442 if (!profile || !profile->GetExtensionService())
443 return url;
444
[email protected]615d88f2011-12-13 01:47:44445 const Extension* extension = profile->GetExtensionService()->extensions()->
446 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08447 if (!extension)
448 return url;
449
[email protected]15877ca2011-11-18 22:40:52450 // Bookmark apps do not use the hosted app process model, and should be
451 // treated as normal URLs.
452 if (extension->from_bookmark())
453 return url;
454
[email protected]36fb2c7c2011-04-04 15:49:08455 // If the URL is part of an extension's web extent, convert it to an
456 // extension URL.
457 return extension->GetResourceURL(url.path());
458}
459
[email protected]056ad2a2011-07-12 02:13:55460bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37461 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55462 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52463 // Because we expect to use the effective URL, URLs for hosted apps (apart
464 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55465 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
466 return false;
467
[email protected]3d7474ff2011-07-27 17:47:37468 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55469 if (!profile || !profile->GetExtensionService())
470 return false;
471
[email protected]615d88f2011-12-13 01:47:44472 const Extension* extension = profile->GetExtensionService()->extensions()->
473 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55474 if (!extension)
475 return false;
476
477 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53478 // permission, or that does not allow JavaScript access to the background
479 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55480 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53481 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
482 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
483 !extension->allow_background_js_access()) {
484 return false;
485 }
486 }
[email protected]056ad2a2011-07-12 02:13:55487
[email protected]7b54ca02012-03-02 18:06:53488 // Hosted apps that have script access to their background page must use
489 // process per site, since all instances can make synchronous calls to the
490 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55491 return true;
492}
493
[email protected]46fb9442011-12-09 17:57:47494bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
495 return ProfileIOData::IsHandledURL(url);
496}
497
[email protected]2a5221b2011-09-27 23:07:31498bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30499 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31500 const GURL& site_url) {
501 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30502 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42503 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46504 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31505
[email protected]ffa97602011-11-17 17:55:52506 // Don't allow the Task Manager to share a process with anything else.
507 // Otherwise it can affect the renderers it is observing.
508 // Note: we could create another RenderProcessHostPrivilege bucket for
509 // this to allow multiple chrome://tasks instances to share, but that's
510 // a very unlikely case without serious consequences.
511 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
512 return false;
513
[email protected]8d3132f62011-10-12 07:13:42514 // These may be NULL during tests. In that case, just assume any site can
515 // share any host.
[email protected]6f371442011-11-09 06:45:46516 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31517 return true;
518
[email protected]a8c269a2011-10-25 20:17:22519 // Experimental:
520 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
521 // to share a renderer process. (We could allow pages from the same site or
522 // extensions of the same type to share, if we knew what the given process
523 // was dedicated to. Allowing no sharing is simpler for now.) This may
524 // cause resource exhaustion issues if too many sites are open at once.
525 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
526 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
527 return false;
528
[email protected]eec0b33c2011-12-05 22:09:45529 // An isolated app is only allowed to share with the exact same app in order
530 // to provide complete renderer process isolation. This also works around
531 // issue http://crbug.com/85588, where different isolated apps in the same
532 // process would end up using the first app's storage contexts.
533 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42534 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45535 if (privilege_required == PRIV_ISOLATED)
536 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
537
538 // Otherwise, just make sure the process privilege matches the privilege
539 // required by the site.
540 return GetProcessPrivilege(process_host, process_map, service) ==
541 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31542}
543
[email protected]76411f412012-02-22 18:56:06544// This function is trying to limit the amount of processes used by extensions
545// with background pages. It uses a globally set percentage of processes to
546// run such extensions and if the limit is exceeded, it returns true, to
547// indicate to the content module to group extensions together.
548bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
549 content::BrowserContext* browser_context, const GURL& url) {
550 // It has to be a valid URL for us to check for an extension.
551 if (!url.is_valid())
552 return false;
553
554 Profile* profile = Profile::FromBrowserContext(browser_context);
555 ExtensionService* service = profile->GetExtensionService();
556 if (!service)
557 return false;
558
559 // We have to have a valid extension with background page to proceed.
560 const Extension* extension =
561 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
562 if (!extension)
563 return false;
564 if (!extension->has_background_page())
565 return false;
566
567 std::set<int> process_ids;
568 size_t max_process_count =
569 content::RenderProcessHost::GetMaxRendererProcessCount();
570
571 // Go through all profiles to ensure we have total count of extension
572 // processes containing background pages, otherwise one profile can
573 // starve the other.
574 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
575 GetLoadedProfiles();
576 for (size_t i = 0; i < profiles.size(); ++i) {
577 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
578 for (ExtensionProcessManager::const_iterator iter = epm->begin();
579 iter != epm->end();
580 ++iter) {
581 ExtensionHost* host = *iter;
582 if (host->extension()->has_background_page()) {
583 process_ids.insert(host->render_process_host()->GetID());
584 }
585 }
586 }
587
588 if (process_ids.size() >
589 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
590 return true;
591 }
592
593 return false;
594}
595
[email protected]6f371442011-11-09 06:45:46596void ChromeContentBrowserClient::SiteInstanceGotProcess(
597 SiteInstance* site_instance) {
598 CHECK(site_instance->HasProcess());
599
600 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02601 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46602 ExtensionService* service = profile->GetExtensionService();
603 if (!service)
604 return;
605
606 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44607 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33608 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46609 if (!extension)
610 return;
611
[email protected]6bc04fd82011-12-04 02:29:35612 service->process_map()->Insert(extension->id(),
613 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33614 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46615 BrowserThread::PostTask(
616 BrowserThread::IO, FROM_HERE,
617 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24618 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46619 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35620 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33621 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46622}
623
624void ChromeContentBrowserClient::SiteInstanceDeleting(
625 SiteInstance* site_instance) {
626 if (!site_instance->HasProcess())
627 return;
628
629 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02630 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46631 ExtensionService* service = profile->GetExtensionService();
632 if (!service)
633 return;
634
635 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44636 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33637 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46638 if (!extension)
639 return;
640
[email protected]6bc04fd82011-12-04 02:29:35641 service->process_map()->Remove(extension->id(),
642 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33643 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46644 BrowserThread::PostTask(
645 BrowserThread::IO, FROM_HERE,
646 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24647 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46648 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35649 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33650 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46651}
652
[email protected]e3daf3c2011-10-05 21:17:08653bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
654 const GURL& current_url,
655 const GURL& new_url) {
656 if (current_url.is_empty()) {
657 // Always choose a new process when navigating to extension URLs. The
658 // process grouping logic will combine all of a given extension's pages
659 // into the same process.
660 if (new_url.SchemeIs(chrome::kExtensionScheme))
661 return true;
662
663 return false;
664 }
665
666 // Also, we must switch if one is an extension and the other is not the exact
667 // same extension.
668 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
669 new_url.SchemeIs(chrome::kExtensionScheme)) {
670 if (current_url.GetOrigin() != new_url.GetOrigin())
671 return true;
672 }
673
674 return false;
675}
676
[email protected]763ec4ca2011-04-29 15:48:12677std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
678 const std::string& alias_name) {
679 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
680}
681
[email protected]b80f68432011-05-02 17:22:30682void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
683 CommandLine* command_line, int child_process_id) {
684#if defined(USE_LINUX_BREAKPAD)
685 if (IsCrashReporterEnabled()) {
686 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
687 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
688 }
689#elif defined(OS_MACOSX)
690 if (IsCrashReporterEnabled()) {
691 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
692 child_process_logging::GetClientId());
693 }
694#endif // OS_MACOSX
695
[email protected]f1933792011-06-14 00:49:34696 if (logging::DialogsAreSuppressed())
697 command_line->AppendSwitch(switches::kNoErrorDialogs);
698
[email protected]b80f68432011-05-02 17:22:30699 std::string process_type =
700 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17701 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52702 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30703 FilePath user_data_dir =
704 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
705 if (!user_data_dir.empty())
706 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
707#if defined(OS_CHROMEOS)
708 const std::string& login_profile =
709 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
710 if (!login_profile.empty())
711 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
712#endif
713
[email protected]f3b1a082011-11-18 00:34:30714 content::RenderProcessHost* process =
715 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37716 if (process) {
717 Profile* profile = Profile::FromBrowserContext(
718 process->GetBrowserContext());
719 extensions::ProcessMap* process_map =
720 profile->GetExtensionService()->process_map();
721 if (process_map && process_map->Contains(process->GetID()))
722 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30723
[email protected]a8d851f82011-12-21 00:32:37724 PrefService* prefs = profile->GetPrefs();
725 // Currently this pref is only registered if applied via a policy.
726 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
727 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
728 // Turn this policy into a command line switch.
729 command_line->AppendSwitch(switches::kDisable3DAPIs);
730 }
[email protected]718eab62011-10-05 21:16:52731
[email protected]a8d851f82011-12-21 00:32:37732 // Disable client-side phishing detection in the renderer if it is
733 // disabled in the Profile preferences or the browser process.
734 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
735 !g_browser_process->safe_browsing_detection_service()) {
736 command_line->AppendSwitch(
737 switches::kDisableClientSidePhishingDetection);
738 }
[email protected]8c40da62011-07-13 22:58:46739 }
[email protected]47c7ec82012-01-18 03:29:21740 {
741 PrefService* local_state = g_browser_process->local_state();
742 if (local_state &&
743 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
744 command_line->AppendSwitch(switches::kRendererPrintPreview);
745 }
746 }
[email protected]4287a3d2011-06-13 23:56:51747
[email protected]47c7ec82012-01-18 03:29:21748 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51749 static const char* const kSwitchNames[] = {
750 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48751 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51752 switches::kAllowScriptingGallery,
753 switches::kAppsCheckoutURL,
754 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31755 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51756 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50757 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51758 switches::kDumpHistogramsOnExit,
[email protected]b7e44ff2012-02-16 03:37:34759 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21760 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13761 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51762 switches::kEnableCrxlessWebApps,
763 switches::kEnableExperimentalExtensionApis,
764 switches::kEnableInBrowserThumbnailing,
765 switches::kEnableIPCFuzzing,
766 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:48767 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53768 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51769 switches::kEnableWatchdog,
770 switches::kExperimentalSpellcheckerFeatures,
771 switches::kMemoryProfiling,
772 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04773 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51774 switches::kPpapiFlashArgs,
775 switches::kPpapiFlashInProcess,
776 switches::kPpapiFlashPath,
777 switches::kPpapiFlashVersion,
778 switches::kProfilingAtStart,
779 switches::kProfilingFile,
780 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51781 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38782 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51783 };
784
785 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
786 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17787 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38788 static const char* const kSwitchNames[] = {
789 switches::kEnableExperimentalExtensionApis,
[email protected]ee14cad2012-03-29 01:59:37790 switches::kEnablePlatformApps,
[email protected]a446534d2012-02-09 00:07:38791 switches::kWhitelistedExtensionID,
792 };
793
794 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
795 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51796 } else if (process_type == switches::kPluginProcess) {
797 static const char* const kSwitchNames[] = {
798 #if defined(OS_CHROMEOS)
799 switches::kLoginProfile,
800 #endif
801 switches::kMemoryProfiling,
802 switches::kSilentDumpOnDCHECK,
803 switches::kUserDataDir,
804 };
805
806 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
807 arraysize(kSwitchNames));
808 } else if (process_type == switches::kZygoteProcess) {
809 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51810 switches::kUserDataDir, // Make logs go to the right file.
811 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50812 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13813 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51814 switches::kPpapiFlashInProcess,
815 switches::kPpapiFlashPath,
816 switches::kPpapiFlashVersion,
817 };
818
819 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
820 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11821 } else if (process_type == switches::kGpuProcess) {
822 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
823 // because GPU is expected to be unreliable.
824 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
825 !command_line->HasSwitch(switches::kDisableBreakpad))
826 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30827 }
[email protected]6f08af82011-09-15 01:19:03828
829 // The command line switch kEnableBenchmarking needs to be specified along
830 // with the kEnableStatsTable switch to ensure that the stats table global
831 // is initialized correctly.
832 if (command_line->HasSwitch(switches::kEnableBenchmarking))
833 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30834}
835
836std::string ChromeContentBrowserClient::GetApplicationLocale() {
837 return g_browser_process->GetApplicationLocale();
838}
839
[email protected]597a867b2011-11-18 18:31:20840std::string ChromeContentBrowserClient::GetAcceptLangs(
841 content::BrowserContext* context) {
842 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37843 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08844}
845
[email protected]ac55e292011-06-24 05:16:08846SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22847 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08848 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
849}
850
[email protected]a2176792011-05-08 19:30:49851bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09852 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19853 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20854 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32855 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20856 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05857 return io_data->GetCookieSettings()->
858 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49859}
860
[email protected]ed24fad2011-05-10 22:44:01861bool ChromeContentBrowserClient::AllowGetCookie(
862 const GURL& url,
863 const GURL& first_party,
864 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20865 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01866 int render_process_id,
867 int render_view_id) {
868 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20869 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05870 bool allow = io_data->GetCookieSettings()->
871 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01872
[email protected]8093a542011-05-13 07:29:32873 BrowserThread::PostTask(
874 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03875 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43876 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01877 return allow;
878}
879
880bool ChromeContentBrowserClient::AllowSetCookie(
881 const GURL& url,
882 const GURL& first_party,
883 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20884 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01885 int render_process_id,
886 int render_view_id,
887 net::CookieOptions* options) {
888 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20889 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05890 CookieSettings* cookie_settings = io_data->GetCookieSettings();
891 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
892
893 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09894 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01895
[email protected]8093a542011-05-13 07:29:32896 BrowserThread::PostTask(
897 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03898 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43899 render_view_id, url, first_party, cookie_line, *options,
900 !allow));
[email protected]ed24fad2011-05-10 22:44:01901 return allow;
902}
903
[email protected]d5a19162011-06-30 18:51:54904bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20905 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20907 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26908
[email protected]f24bd172012-03-31 01:54:59909 return !io_data->clear_local_state_on_exit()->GetValue();
[email protected]d5a19162011-06-30 18:51:54910}
911
[email protected]5c5a88e2011-11-12 00:45:35912bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35913 const GURL& url,
914 const string16& name,
915 const string16& display_name,
916 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20917 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48918 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20920 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35921 CookieSettings* cookie_settings = io_data->GetCookieSettings();
922 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
923
[email protected]62151052012-02-01 18:40:48924 // Record access to database for potential display in UI.
925 std::vector<std::pair<int, int> >::const_iterator i;
926 for (i = render_views.begin(); i != render_views.end(); ++i) {
927 BrowserThread::PostTask(
928 BrowserThread::UI, FROM_HERE,
929 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
930 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35931 }
932
933 return allow;
934}
935
936bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35937 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20938 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48939 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35940 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20941 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35942 CookieSettings* cookie_settings = io_data->GetCookieSettings();
943 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
944
[email protected]62151052012-02-01 18:40:48945 // Record access to file system for potential display in UI.
946 std::vector<std::pair<int, int> >::const_iterator i;
947 for (i = render_views.begin(); i != render_views.end(); ++i) {
948 BrowserThread::PostTask(
949 BrowserThread::UI, FROM_HERE,
950 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
951 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35952 }
953
954 return allow;
955}
956
[email protected]7c5ff9a2012-03-02 07:42:49957bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
958 const GURL& url,
959 const string16& name,
960 content::ResourceContext* context,
961 const std::vector<std::pair<int, int> >& render_views) {
962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
963 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
964 CookieSettings* cookie_settings = io_data->GetCookieSettings();
965 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
966
967 // Record access to IndexedDB for potential display in UI.
968 std::vector<std::pair<int, int> >::const_iterator i;
969 for (i = render_views.begin(); i != render_views.end(); ++i) {
970 BrowserThread::PostTask(
971 BrowserThread::UI, FROM_HERE,
972 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
973 i->first, i->second, url, name, !allow));
974 }
975
976 return allow;
977}
978
[email protected]6133f922011-07-01 21:34:34979net::URLRequestContext*
980ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20981 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34982 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
983 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20984 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34985 return io_data->extensions_request_context();
986 }
987
988 return NULL;
989}
990
[email protected]317f96c92011-05-31 06:53:41991QuotaPermissionContext*
992ChromeContentBrowserClient::CreateQuotaPermissionContext() {
993 return new ChromeQuotaPermissionContext();
994}
995
[email protected]a0ce3282011-08-19 20:49:52996void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42997 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42998}
999
[email protected]a0ce3282011-08-19 20:49:521000void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521001 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521002}
1003
[email protected]848dd042011-06-04 18:24:031004void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171005 int render_process_id,
1006 int render_view_id,
1007 int cert_error,
1008 const net::SSLInfo& ssl_info,
1009 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031010 bool overridable,
[email protected]4cf611e32012-02-13 16:06:171011 const base::Callback<void(bool)>& callback,
1012 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411013 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131014 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171015 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411016 if (!tab) {
1017 NOTREACHED();
1018 return;
1019 }
1020 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501021 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301022 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091023 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411024 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171025 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411026 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171027 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411028 return;
1029 }
1030 }
1031
1032 // Otherwise, display an SSL blocking page.
[email protected]4cf611e32012-02-13 16:06:171033 new SSLBlockingPage(
1034 tab, cert_error, ssl_info, request_url, overridable, callback);
[email protected]848dd042011-06-04 18:24:031035}
1036
[email protected]c99c442e2011-08-24 11:37:301037void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451038 int render_process_id,
1039 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401040 const net::HttpNetworkSession* network_session,
1041 net::SSLCertRequestInfo* cert_request_info,
1042 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131043 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451044 render_process_id, render_view_id);
1045 if (!tab) {
1046 NOTREACHED();
1047 return;
1048 }
1049
[email protected]6786bf402011-12-03 15:19:451050 GURL requesting_url("https://" + cert_request_info->host_and_port);
1051 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1052 << cert_request_info->host_and_port;
1053
[email protected]627e0512011-12-21 22:55:301054 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451055 scoped_ptr<Value> filter(
1056 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1057 requesting_url,
1058 requesting_url,
1059 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1060 std::string(), NULL));
1061
1062 if (filter.get()) {
1063 // Try to automatically select a client certificate.
1064 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1065 DictionaryValue* filter_dict =
1066 static_cast<DictionaryValue*>(filter.get());
1067
1068 const std::vector<scoped_refptr<net::X509Certificate> >&
1069 all_client_certs = cert_request_info->client_certs;
1070 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1071 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1072 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401073 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451074 return;
1075 }
1076 }
1077 } else {
1078 NOTREACHED();
1079 }
1080 }
1081
[email protected]8ec26472011-06-06 16:52:451082 TabContentsWrapper* wrapper =
1083 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451084 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131085 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451086 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141087 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401088 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451089 return;
1090 }
[email protected]7a593db2012-02-13 21:19:401091 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1092 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451093}
1094
1095void ChromeContentBrowserClient::AddNewCertificate(
1096 net::URLRequest* request,
1097 net::X509Certificate* cert,
1098 int render_process_id,
1099 int render_view_id) {
1100 // The handler will run the UI and delete itself when it's finished.
1101 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1102}
1103
[email protected]a93670ab2012-02-24 03:46:391104void ChromeContentBrowserClient::RequestMediaAccessPermission(
1105 const content::MediaStreamRequest* request,
1106 const content::MediaResponseCallback& callback) {
1107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1108
[email protected]117b6b42012-02-29 09:11:081109 WebContents* contents = tab_util::GetWebContentsByID(
1110 request->render_process_id, request->render_view_id);
1111 if (!contents) {
1112 // Abort, if the tab was closed after the request was made but before we
1113 // got to this point.
1114 callback.Run(content::MediaStreamDevices());
1115 return;
1116 }
1117
1118 TabContentsWrapper* tab =
1119 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1120 DCHECK(tab);
1121
1122 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1123 InfoBarDelegate* old_infobar = NULL;
1124 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1125 old_infobar =
1126 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfobarDelegate();
1127 }
1128
[email protected]3bc518b2012-03-09 03:01:501129#if defined(TOOLKIT_VIEWS) || defined(OS_LINUX)
[email protected]117b6b42012-02-29 09:11:081130 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1131 request,
1132 callback);
1133 if (old_infobar)
1134 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1135 else
1136 infobar_helper->AddInfoBar(infobar);
[email protected]3bc518b2012-03-09 03:01:501137#elif defined(OS_MACOSX)
1138 // TODO(macourteau): UI is not implemented yet for OS X. Fallback to
[email protected]117b6b42012-02-29 09:11:081139 // the default behaviour and allow access to the first device of each
1140 // requested type.
1141 content::MediaStreamDevices devices;
[email protected]a93670ab2012-02-24 03:46:391142 for (content::MediaStreamDeviceMap::const_iterator it =
1143 request->devices.begin(); it != request->devices.end(); ++it) {
[email protected]6c6415a2012-03-01 17:17:281144 if (!it->second.empty())
1145 devices.push_back(*it->second.begin());
[email protected]a93670ab2012-02-24 03:46:391146 }
1147
[email protected]a93670ab2012-02-24 03:46:391148 callback.Run(devices);
[email protected]3bc518b2012-03-09 03:01:501149#endif // TOOLKIT_VIEWS || OS_LINUX
[email protected]a93670ab2012-02-24 03:46:391150}
1151
[email protected]dc73a7b2012-03-25 15:27:181152content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1153 return MediaInternals::GetInstance();
1154}
1155
[email protected]941623e2011-06-07 23:06:041156void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1157 const GURL& source_origin,
1158 int callback_context,
1159 int render_process_id,
1160 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111161#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041162 RenderViewHost* rvh = RenderViewHost::FromID(
1163 render_process_id, render_view_id);
1164 if (!rvh) {
1165 NOTREACHED();
1166 return;
1167 }
1168
[email protected]9f76c1e2012-03-05 15:15:581169 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301170 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041171 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371172 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041173 service->RequestPermission(
1174 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131175 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111176#else
1177 NOTIMPLEMENTED();
1178#endif
[email protected]941623e2011-06-07 23:06:041179}
1180
1181WebKit::WebNotificationPresenter::Permission
1182 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021183 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201184 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021185 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111186#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201188 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021189 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1190 source_origin, render_process_id,
1191 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041192 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041193
1194 // Fall back to the regular notification preferences, which works on an
1195 // origin basis.
1196 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371197 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041198 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111199#else
1200 return WebKit::WebNotificationPresenter::PermissionAllowed;
1201#endif
[email protected]941623e2011-06-07 23:06:041202}
1203
1204void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171205 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041206 int render_process_id,
1207 int render_view_id,
1208 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111209#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041210 RenderViewHost* rvh = RenderViewHost::FromID(
1211 render_process_id, render_view_id);
1212 if (!rvh) {
1213 NOTREACHED();
1214 return;
1215 }
1216
[email protected]9f76c1e2012-03-05 15:15:581217 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301218 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041219 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371220 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041221 service->ShowDesktopNotification(
1222 params, render_process_id, render_view_id,
1223 worker ? DesktopNotificationService::WorkerNotification :
1224 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111225#else
1226 NOTIMPLEMENTED();
1227#endif
[email protected]941623e2011-06-07 23:06:041228}
1229
1230void ChromeContentBrowserClient::CancelDesktopNotification(
1231 int render_process_id,
1232 int render_view_id,
1233 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111234#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041235 RenderViewHost* rvh = RenderViewHost::FromID(
1236 render_process_id, render_view_id);
1237 if (!rvh) {
1238 NOTREACHED();
1239 return;
1240 }
1241
[email protected]9f76c1e2012-03-05 15:15:581242 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301243 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041244 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371245 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041246 service->CancelDesktopNotification(
1247 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111248#else
1249 NOTIMPLEMENTED();
1250#endif
[email protected]941623e2011-06-07 23:06:041251}
1252
[email protected]9f3fba52011-06-08 20:37:191253bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351254 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021255 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191256 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201257 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011258 int render_process_id,
1259 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011261
1262 *no_javascript_access = false;
1263
[email protected]9f3fba52011-06-08 20:37:191264 // If the opener is trying to create a background window but doesn't have
1265 // the appropriate permission, fail the attempt.
1266 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201267 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531268 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1269
[email protected]03b6d552012-03-29 04:03:011270 if (!map->SecurityOriginHasAPIPermission(
1271 source_origin,
1272 render_process_id,
1273 ExtensionAPIPermission::kBackground)) {
1274 return false;
1275 }
1276
[email protected]7b54ca02012-03-02 18:06:531277 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1278 // return a recently installed Extension even if this CanCreateWindow call
1279 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011280 // because the permission check above would have caused an early return
1281 // already. We must use the full URL to find hosted apps, though, and not
1282 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531283 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351284 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531285 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011286 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191287 }
1288 return true;
1289}
1290
1291std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201292 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1294 // Check if it's an extension-created worker, in which case we want to use
1295 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201296 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191297 const Extension* extension =
1298 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1299 return extension ? extension->name() : std::string();
1300}
1301
[email protected]99907362012-01-11 05:41:401302void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1303 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171304}
1305
[email protected]c52b2892012-03-07 11:01:021306content::SpeechRecognitionManagerDelegate*
1307 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321308#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021309 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321310#else
1311 return NULL;
1312#endif
[email protected]66cfec62012-02-24 17:57:511313}
1314
[email protected]3cb054e62011-06-13 05:21:171315ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1316 return g_browser_process->clipboard();
1317}
1318
[email protected]ae6e9912011-07-27 01:18:281319net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1320 return g_browser_process->net_log();
1321}
1322
[email protected]32538d92011-08-25 00:09:231323AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1324 return new ChromeAccessTokenStore();
1325}
1326
[email protected]dbae6b02011-06-29 23:51:411327bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1328 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1329 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1330}
1331
[email protected]64d69de42012-02-06 00:19:541332void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321333 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061334 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581335 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061336 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061337
[email protected]64d69de42012-02-06 00:19:541338 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061339 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541340 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061341 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541342 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061343 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541344 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061345 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541346 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061347 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541348 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061349 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1350
1351 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541352 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061353 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541354 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061355 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541356 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061357 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541358 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061359 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541360 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061361 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541362 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061363
[email protected]64d69de42012-02-06 00:19:541364 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061365 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541366 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061367 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541368 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061369 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541370 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061371 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1372
[email protected]64d69de42012-02-06 00:19:541373 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061374
[email protected]64d69de42012-02-06 00:19:541375 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061376 prefs->GetBoolean(
1377 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541378 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061379 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541380 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061381 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1382 const DictionaryValue* inspector_settings =
1383 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1384 if (inspector_settings) {
1385 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1386 iter != inspector_settings->end_keys(); ++iter) {
1387 std::string value;
1388 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541389 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061390 std::make_pair(*iter, value));
1391 }
1392 }
[email protected]64d69de42012-02-06 00:19:541393 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061394
[email protected]64d69de42012-02-06 00:19:541395 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1396 web_prefs->javascript_enabled = false;
1397 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1398 web_prefs->web_security_enabled = false;
1399 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1400 web_prefs->plugins_enabled = false;
1401 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1402 web_prefs->java_enabled = false;
1403 web_prefs->loads_images_automatically =
1404 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061405
[email protected]64d69de42012-02-06 00:19:541406 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1407 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061408
[email protected]64d69de42012-02-06 00:19:541409 web_prefs->memory_info_enabled =
1410 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1411 web_prefs->allow_displaying_insecure_content =
1412 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1413 web_prefs->allow_running_insecure_content =
1414 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081415 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061416
[email protected]64d69de42012-02-06 00:19:541417 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151418 UserStyleSheetWatcher* user_style_sheet_watcher =
1419 UserStyleSheetWatcherFactory::GetForProfile(profile);
1420 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541421 web_prefs->user_style_sheet_enabled = true;
1422 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151423 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541424 } else {
1425 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061426 }
1427
[email protected]b7e44ff2012-02-16 03:37:341428 web_prefs->asynchronous_spell_checking_enabled =
1429 CommandLine::ForCurrentProcess()->
1430 HasSwitch(switches::kEnableAsynchronousSpellChecking);
1431 web_prefs->unified_textchecker_enabled =
1432 web_prefs->asynchronous_spell_checking_enabled ||
1433 CommandLine::ForCurrentProcess()->
1434 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571435
[email protected]64d69de42012-02-06 00:19:541436 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061437 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541438 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061439 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541440 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061441 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1442
1443 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541444 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061445 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541446 web_prefs->default_encoding);
1447 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061448 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541449 web_prefs->default_encoding =
1450 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061451 }
[email protected]64d69de42012-02-06 00:19:541452 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061453
1454 ExtensionService* service = profile->GetExtensionService();
1455 if (service) {
1456 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581457 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061458 extension_webkit_preferences::SetPreferences(
[email protected]9f76c1e2012-03-05 15:15:581459 extension, rvh->GetDelegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061460 }
1461
[email protected]9f76c1e2012-03-05 15:15:581462 if (rvh->GetDelegate()->GetRenderViewType() ==
1463 chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541464 web_prefs->allow_scripts_to_close_windows = true;
[email protected]9f76c1e2012-03-05 15:15:581465 } else if (rvh->GetDelegate()->GetRenderViewType() ==
[email protected]f3986f82012-01-03 20:00:061466 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1467 // Disable all kinds of acceleration for background pages.
1468 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541469 web_prefs->force_compositing_mode = false;
1470 web_prefs->accelerated_compositing_enabled = false;
1471 web_prefs->accelerated_2d_canvas_enabled = false;
1472 web_prefs->accelerated_video_enabled = false;
1473 web_prefs->accelerated_painting_enabled = false;
1474 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061475 }
[email protected]2e21fe292012-03-02 22:52:321476
1477#if defined(FILE_MANAGER_EXTENSION)
1478 // Override the default of suppressing HW compositing for WebUI pages for the
1479 // file manager, which is implemented using WebUI but wants HW acceleration
1480 // for video decode & render.
1481 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1482 web_prefs->accelerated_compositing_enabled = true;
1483 web_prefs->accelerated_2d_canvas_enabled = true;
1484 }
1485#endif
[email protected]181a95ee2011-07-12 19:26:361486}
1487
1488void ChromeContentBrowserClient::UpdateInspectorSetting(
1489 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061490 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581491 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061492 DictionaryPrefUpdate update(
1493 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1494 prefs::kWebKitInspectorSettings);
1495 DictionaryValue* inspector_settings = update.Get();
1496 inspector_settings->SetWithoutPathExpansion(key,
1497 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361498}
1499
1500void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061501 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581502 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061503 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1504 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361505}
1506
[email protected]b8148ac2011-07-13 22:03:251507void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1508 BrowserURLHandler* handler) {
1509 // Add the default URL handlers.
1510 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1511 BrowserURLHandler::null_handler());
1512 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1513 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1514
[email protected]b3adbd02011-11-30 22:23:271515 // about: handler. Must come before chrome: handler, since it will
1516 // rewrite about: urls to chrome: URLs and then expect chrome: to
1517 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251518 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1519 BrowserURLHandler::null_handler());
1520 // chrome: & friends.
1521 handler->AddHandlerPair(&HandleWebUI,
1522 BrowserURLHandler::null_handler());
1523}
1524
1525void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371526 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581527 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251528 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1529 BrowsingDataRemover::EVERYTHING,
1530 base::Time());
1531 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1532 // BrowsingDataRemover takes care of deleting itself when done.
1533}
1534
1535void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371536 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581537 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251538 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1539 BrowsingDataRemover::EVERYTHING,
1540 base::Time());
[email protected]dceaa912011-09-06 17:17:231541 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251542 remover->Remove(remove_mask);
1543 // BrowsingDataRemover takes care of deleting itself when done.
1544}
1545
[email protected]e1d16eb92011-08-18 23:19:321546FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1547 return download_util::GetDefaultDownloadDirectory();
1548}
1549
[email protected]c9b6eb62011-10-18 20:49:391550std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1551 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1552}
1553
[email protected]a658d452012-03-02 12:45:291554bool ChromeContentBrowserClient::AllowSocketAPI(
1555 content::BrowserContext* browser_context, const GURL& url) {
1556 if (!url.is_valid())
1557 return false;
1558
1559 std::string host = url.host();
1560 if (allowed_socket_origins_.count(host))
1561 return true;
1562
[email protected]f237c0f2012-03-10 07:49:101563 // Need to check this now and not on construction because otherwise it won't
1564 // work with browser_tests.
1565 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1566 std::string allowed_list =
1567 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
1568 if (!allowed_list.empty()) {
1569 StringTokenizer t(allowed_list, ",");
1570 while (t.GetNext()) {
1571 if (t.token() == host)
1572 return true;
1573 }
1574 }
1575
[email protected]a658d452012-03-02 12:45:291576 Profile* profile = Profile::FromBrowserContext(browser_context);
1577 if (!profile || !profile->GetExtensionService())
1578 return false;
1579
1580 const Extension* extension = profile->GetExtensionService()->extensions()->
1581 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1582 if (!extension)
1583 return false;
1584
1585 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1586 return true;
1587
1588 return false;
[email protected]e461da2f2012-02-16 19:06:401589}
1590
[email protected]e60c0232011-11-11 19:56:351591#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301592int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521593 const CommandLine& command_line) {
1594 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071595 ExtensionCrashHandlerHostLinux* crash_handler =
1596 ExtensionCrashHandlerHostLinux::GetInstance();
1597 return crash_handler->GetDeathSignalSocket();
1598 }
1599
[email protected]718eab62011-10-05 21:16:521600 std::string process_type =
1601 command_line.GetSwitchValueASCII(switches::kProcessType);
1602
1603 if (process_type == switches::kRendererProcess)
1604 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1605
[email protected]b80f68432011-05-02 17:22:301606 if (process_type == switches::kPluginProcess)
1607 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1608
1609 if (process_type == switches::kPpapiPluginProcess)
1610 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1611
1612 if (process_type == switches::kGpuProcess)
1613 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1614
1615 return -1;
1616}
[email protected]e60c0232011-11-11 19:56:351617#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301618
[email protected]4a65826d2011-08-25 16:04:011619#if defined(OS_WIN)
1620const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1621 return chrome::kBrowserResourcesDll;
1622}
1623#endif
1624
[email protected]37a72af2011-06-13 05:42:011625#if defined(USE_NSS)
1626crypto::CryptoModuleBlockingPasswordDelegate*
1627 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1628 const GURL& url) {
1629 return browser::NewCryptoModuleBlockingDialogDelegate(
1630 browser::kCryptoModulePasswordKeygen, url.host());
1631}
1632#endif
1633
[email protected]d977f9c2011-03-14 16:10:261634} // namespace chrome