blob: 4e5e7e4ea88d82bc1008d2a3a52d6b0155dec8fb [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]b80f68432011-05-02 17:22:3069#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0170#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3071#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0472#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4473#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3474#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1275#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3876#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0977#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4378#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3079#include "content/public/browser/browser_main_parts.h"
[email protected]825b1662012-03-12 19:07:3180#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5981#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3082#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3383#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0584#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3385#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1986#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1087#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4388#include "content/public/common/child_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3989#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3490#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4091#include "net/base/ssl_cert_request_info.h"
[email protected]aa84a7e2012-03-15 21:29:0692#include "net/cookies/cookie_monster.h"
93#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3994#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0895#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3696#include "webkit/glue/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:2697
[email protected]b48c9182011-10-26 18:03:3098#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3899#include "chrome/browser/chrome_browser_main_win.h"
100#elif defined(OS_MACOSX)
101#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56102#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]38b098f2012-03-14 21:11:57103#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h"
[email protected]b48c9182011-10-26 18:03:30104#elif defined(OS_CHROMEOS)
105#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49106#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26107#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30108#include "chrome/browser/chrome_browser_main_linux.h"
109#elif defined(OS_POSIX)
110#include "chrome/browser/chrome_browser_main_posix.h"
111#endif
112
[email protected]159d5142012-03-22 18:16:24113#if defined(USE_AURA)
114#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_aura.h"
[email protected]68b52252012-04-04 19:26:13115#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_views.h"
[email protected]159d5142012-03-22 18:16:24116#elif defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13117#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_views.h"
[email protected]61e69822012-03-14 22:08:57118#endif
119
[email protected]a13283cc2012-04-05 00:21:22120#if defined(TOOLKIT_GTK)
[email protected]50462bf02011-11-21 19:13:31121#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38122#endif
123
[email protected]c7480942011-11-08 19:18:27124#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31125#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]38b098f2012-03-14 21:11:57126#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c7480942011-11-08 19:18:27127#endif
128
129#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31130#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
131#endif
132
[email protected]dc04be7c2012-03-15 23:57:49133#if defined(USE_ASH)
134#include "chrome/browser/chrome_browser_main_extra_parts_ash.h"
135#endif
136
[email protected]e60c0232011-11-11 19:56:35137#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30138#include "base/linux_util.h"
139#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43140#endif
[email protected]b80f68432011-05-02 17:22:30141
[email protected]38b098f2012-03-14 21:11:57142#if defined(TOOLKIT_GTK)
143#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_gtk.h"
[email protected]74313b42011-08-24 16:51:32144#endif
[email protected]37a72af2011-06-13 05:42:01145#if defined(USE_NSS)
146#include "chrome/browser/ui/crypto_module_password_dialog.h"
147#endif
148
[email protected]c8c77182011-12-21 15:04:47149using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39150using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31151using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59152using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00153using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11154using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33155using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13156using content::WebContents;
[email protected]631bb742011-11-02 11:29:39157
[email protected]c5dbef02011-05-13 05:06:09158namespace {
159
[email protected]e461da2f2012-02-16 19:06:40160const char* kPredefinedAllowedSocketOrigins[] = {
161 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18162 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
163 "bglhmjfplikpjnfoegeomebmfnkjomhe" // see crbug.com/122126
[email protected]e461da2f2012-02-16 19:06:40164};
165
[email protected]b8148ac2011-07-13 22:03:25166// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42167bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50168 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
169 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25170 return false;
171
[email protected]fe69558d2012-03-12 11:34:49172#if defined(OS_CHROMEOS)
173 // Special case : in ChromeOS in Guest mode bookmarks and history are
174 // disabled for security reasons. New tab page explains the reasons, so
175 // we redirect user to new tab page.
176 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
177 if (url->SchemeIs(chrome::kChromeUIScheme) &&
178 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
179 url->DomainIs(chrome::kChromeUIHistoryHost))) {
180 // Rewrite with new tab URL
181 *url = GURL(chrome::kChromeUINewTabURL);
182 }
183 }
184#endif
185
[email protected]b8148ac2011-07-13 22:03:25186 // Special case the new tab page. In older versions of Chrome, the new tab
187 // page was hosted at chrome-internal:<blah>. This might be in people's saved
188 // sessions or bookmarks, so we say any URL with that scheme triggers the new
189 // tab page.
190 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
191 // Rewrite it with the proper new tab URL.
192 *url = GURL(chrome::kChromeUINewTabURL);
193 }
194
195 return true;
196}
197
[email protected]8d3132f62011-10-12 07:13:42198// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
199// below. Extension, and isolated apps require different privileges to be
200// granted to their RenderProcessHosts. This classification allows us to make
201// sure URLs are served by hosts with the right set of privileges.
202enum RenderProcessHostPrivilege {
203 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45204 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42205 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45206 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42207};
208
209RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
210 const GURL& url,
211 ExtensionService* service) {
212 // Default to a normal renderer cause it is lower privileged. This should only
213 // occur if the URL on a site instance is either malformed, or uninitialized.
214 // If it is malformed, then there is no need for better privileges anyways.
215 // If it is uninitialized, but eventually settles on being an a scheme other
216 // than normal webrenderer, the navigation logic will correct us out of band
217 // anyways.
218 if (!url.is_valid())
219 return PRIV_NORMAL;
220
221 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44222 const Extension* extension =
223 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45224 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42225 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45226 if (extension && extension->is_hosted_app())
227 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42228
229 return PRIV_EXTENSION;
230 }
231
232 return PRIV_NORMAL;
233}
234
235RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30236 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46237 extensions::ProcessMap* process_map,
238 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46239 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30240 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46241 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21242 return PRIV_NORMAL;
243
[email protected]6f371442011-11-09 06:45:46244 for (std::set<std::string>::iterator iter = extension_ids.begin();
245 iter != extension_ids.end(); ++iter) {
246 const Extension* extension = service->GetExtensionById(*iter, false);
247 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42248 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45249 if (extension && extension->is_hosted_app())
250 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42251 }
252
[email protected]676f6ab2011-10-19 20:23:21253 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42254}
255
[email protected]eec0b33c2011-12-05 22:09:45256bool IsIsolatedAppInProcess(const GURL& site_url,
257 content::RenderProcessHost* process_host,
258 extensions::ProcessMap* process_map,
259 ExtensionService* service) {
260 std::set<std::string> extension_ids =
261 process_map->GetExtensionsInProcess(process_host->GetID());
262 if (extension_ids.empty())
263 return false;
264
265 for (std::set<std::string>::iterator iter = extension_ids.begin();
266 iter != extension_ids.end(); ++iter) {
267 const Extension* extension = service->GetExtensionById(*iter, false);
268 if (extension &&
269 extension->is_storage_isolated() &&
270 extension->url() == site_url)
271 return true;
272 }
273
274 return false;
275}
276
[email protected]6786bf402011-12-03 15:19:45277bool CertMatchesFilter(const net::X509Certificate& cert,
278 const base::DictionaryValue& filter) {
279 // TODO(markusheintz): This is the minimal required filter implementation.
280 // Implement a better matcher.
281
282 // An empty filter matches any client certificate since no requirements are
283 // specified at all.
284 if (filter.empty())
285 return true;
286
287 std::string common_name;
288 if (filter.GetString("ISSUER.CN", &common_name) &&
289 (cert.issuer().common_name == common_name)) {
290 return true;
291 }
292 return false;
293}
294
[email protected]f3986f82012-01-03 20:00:06295// Fills |map| with the per-script font prefs under path |map_name|.
296void FillFontFamilyMap(const PrefService* prefs,
297 const char* map_name,
298 WebPreferences::ScriptFontFamilyMap* map) {
299 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
300 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
301 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
302 std::string font_family = prefs->GetString(pref_name.c_str());
303 if (!font_family.empty())
304 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
305 }
306}
307
[email protected]9dbfff12011-07-01 19:37:07308} // namespace
[email protected]c5dbef02011-05-13 05:06:09309
[email protected]d977f9c2011-03-14 16:10:26310namespace chrome {
311
[email protected]e461da2f2012-02-16 19:06:40312ChromeContentBrowserClient::ChromeContentBrowserClient() {
313 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
314 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40315}
316
317ChromeContentBrowserClient::~ChromeContentBrowserClient() {
318}
319
[email protected]50462bf02011-11-21 19:13:31320content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
321 const content::MainFunctionParams& parameters) {
322 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30323 // Construct the Main browser parts based on the OS type.
324#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31325 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04326#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31327 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30328#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31329 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26330#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31331 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14332#elif defined(OS_ANDROID)
333 // Do nothing for Android.
334 // TODO(klobag): Android initialization should use the
335 // *BrowserMainParts class-hierarchy for setting up custom initialization.
336 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30337#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31338 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04339#else
[email protected]b48c9182011-10-26 18:03:30340 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31341 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30342#endif
343
[email protected]c7480942011-11-08 19:18:27344 // Construct additional browser parts. Stages are called in the order in
345 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22346#if defined(TOOLKIT_GTK)
[email protected]50462bf02011-11-21 19:13:31347 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04348#endif
[email protected]c7480942011-11-08 19:18:27349
350#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31351 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27352#endif
353
[email protected]dc04be7c2012-03-15 23:57:49354#if defined(USE_ASH)
355 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
356#endif
357
[email protected]e050ef142012-03-21 01:04:24358#if defined(USE_AURA)
359 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
360#endif
361
[email protected]50462bf02011-11-21 19:13:31362 return main_parts;
[email protected]f967b722011-09-07 00:58:04363}
364
[email protected]38b098f2012-03-14 21:11:57365content::WebContentsView*
366 ChromeContentBrowserClient::OverrideCreateWebContentsView(
367 WebContents* web_contents) {
[email protected]68b52252012-04-04 19:26:13368#if defined(USE_AURA)
369 // TODO(beng): remove this once TCVV is gone.
370 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
371 if (!command_line.HasSwitch(switches::kEnableTCVA)) {
372 return new TabContentsViewViews(web_contents,
373 GetWebContentsViewDelegate(web_contents));
374 }
[email protected]38b098f2012-03-14 21:11:57375#endif
376 return NULL;
377}
378
379content::WebContentsViewDelegate*
380 ChromeContentBrowserClient::GetWebContentsViewDelegate(
381 content::WebContents* web_contents) {
[email protected]68b52252012-04-04 19:26:13382#if defined(OS_WIN) || defined(USE_AURA)
383// TODO(beng): replace all of this once TCVV is removed.
384#if defined(OS_WIN)
385 return new ChromeWebContentsViewDelegateViews(web_contents);
386#elif defined(USE_AURA)
387 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
388 if (command_line.HasSwitch(switches::kEnableTCVA))
389 return new ChromeWebContentsViewDelegateViews(web_contents);
390 return new ChromeWebContentsViewDelegateAura(web_contents);
391#endif
[email protected]38b098f2012-03-14 21:11:57392#elif defined(TOOLKIT_GTK)
393 return new ChromeWebContentsViewDelegateGtk(web_contents);
[email protected]74313b42011-08-24 16:51:32394#elif defined(OS_MACOSX)
[email protected]38b098f2012-03-14 21:11:57395 return
396 chrome_web_contents_view_delegate_mac::CreateWebContentsViewDelegateMac(
397 web_contents);
[email protected]74313b42011-08-24 16:51:32398#else
[email protected]38b098f2012-03-14 21:11:57399 return NULL;
[email protected]74313b42011-08-24 16:51:32400#endif
401}
402
[email protected]f364d1392011-04-08 21:03:10403void ChromeContentBrowserClient::RenderViewHostCreated(
404 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46405
[email protected]9f76c1e2012-03-05 15:15:58406 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46407 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02408 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46409
410 new ChromeRenderViewHostObserver(render_view_host,
411 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10412 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26413}
414
[email protected]f3b1a082011-11-18 00:34:30415void ChromeContentBrowserClient::RenderProcessHostCreated(
416 content::RenderProcessHost* host) {
417 int id = host->GetID();
418 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
419 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02420 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30421 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03422#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30423 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03424#endif
[email protected]f3b1a082011-11-18 00:34:30425 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02426 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30427 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56428#if defined(OS_MACOSX)
429 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
430#endif
[email protected]f3b1a082011-11-18 00:34:30431 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03432 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38433
[email protected]2ccf45c2011-08-19 23:35:50434 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
435 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07436
437 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56438
439 RendererContentSettingRules rules;
440 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
441 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14442}
443
[email protected]e0ada9c2012-03-20 03:54:43444void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
445 content::BrowserChildProcessHost* host) {
446 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
447}
448
[email protected]863f70a2012-01-27 02:05:50449content::WebUIControllerFactory*
450 ChromeContentBrowserClient::GetWebUIControllerFactory() {
451 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56452}
453
[email protected]3d7474ff2011-07-27 17:47:37454GURL ChromeContentBrowserClient::GetEffectiveURL(
455 content::BrowserContext* browser_context, const GURL& url) {
456 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08457 // Get the effective URL for the given actual URL. If the URL is part of an
458 // installed app, the effective URL is an extension URL with the ID of that
459 // extension as the host. This has the effect of grouping apps together in
460 // a common SiteInstance.
461 if (!profile || !profile->GetExtensionService())
462 return url;
463
[email protected]615d88f2011-12-13 01:47:44464 const Extension* extension = profile->GetExtensionService()->extensions()->
465 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08466 if (!extension)
467 return url;
468
[email protected]15877ca2011-11-18 22:40:52469 // Bookmark apps do not use the hosted app process model, and should be
470 // treated as normal URLs.
471 if (extension->from_bookmark())
472 return url;
473
[email protected]36fb2c7c2011-04-04 15:49:08474 // If the URL is part of an extension's web extent, convert it to an
475 // extension URL.
476 return extension->GetResourceURL(url.path());
477}
478
[email protected]056ad2a2011-07-12 02:13:55479bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37480 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55481 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52482 // Because we expect to use the effective URL, URLs for hosted apps (apart
483 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55484 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
485 return false;
486
[email protected]3d7474ff2011-07-27 17:47:37487 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55488 if (!profile || !profile->GetExtensionService())
489 return false;
490
[email protected]615d88f2011-12-13 01:47:44491 const Extension* extension = profile->GetExtensionService()->extensions()->
492 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55493 if (!extension)
494 return false;
495
496 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53497 // permission, or that does not allow JavaScript access to the background
498 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55499 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53500 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
501 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
502 !extension->allow_background_js_access()) {
503 return false;
504 }
505 }
[email protected]056ad2a2011-07-12 02:13:55506
[email protected]7b54ca02012-03-02 18:06:53507 // Hosted apps that have script access to their background page must use
508 // process per site, since all instances can make synchronous calls to the
509 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55510 return true;
511}
512
[email protected]46fb9442011-12-09 17:57:47513bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
514 return ProfileIOData::IsHandledURL(url);
515}
516
[email protected]2a5221b2011-09-27 23:07:31517bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30518 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31519 const GURL& site_url) {
520 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30521 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42522 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46523 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31524
[email protected]ffa97602011-11-17 17:55:52525 // Don't allow the Task Manager to share a process with anything else.
526 // Otherwise it can affect the renderers it is observing.
527 // Note: we could create another RenderProcessHostPrivilege bucket for
528 // this to allow multiple chrome://tasks instances to share, but that's
529 // a very unlikely case without serious consequences.
530 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
531 return false;
532
[email protected]8d3132f62011-10-12 07:13:42533 // These may be NULL during tests. In that case, just assume any site can
534 // share any host.
[email protected]6f371442011-11-09 06:45:46535 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31536 return true;
537
[email protected]a8c269a2011-10-25 20:17:22538 // Experimental:
539 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
540 // to share a renderer process. (We could allow pages from the same site or
541 // extensions of the same type to share, if we knew what the given process
542 // was dedicated to. Allowing no sharing is simpler for now.) This may
543 // cause resource exhaustion issues if too many sites are open at once.
544 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
545 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
546 return false;
547
[email protected]eec0b33c2011-12-05 22:09:45548 // An isolated app is only allowed to share with the exact same app in order
549 // to provide complete renderer process isolation. This also works around
550 // issue http://crbug.com/85588, where different isolated apps in the same
551 // process would end up using the first app's storage contexts.
552 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42553 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45554 if (privilege_required == PRIV_ISOLATED)
555 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
556
557 // Otherwise, just make sure the process privilege matches the privilege
558 // required by the site.
559 return GetProcessPrivilege(process_host, process_map, service) ==
560 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31561}
562
[email protected]76411f412012-02-22 18:56:06563// This function is trying to limit the amount of processes used by extensions
564// with background pages. It uses a globally set percentage of processes to
565// run such extensions and if the limit is exceeded, it returns true, to
566// indicate to the content module to group extensions together.
567bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
568 content::BrowserContext* browser_context, const GURL& url) {
569 // It has to be a valid URL for us to check for an extension.
570 if (!url.is_valid())
571 return false;
572
573 Profile* profile = Profile::FromBrowserContext(browser_context);
574 ExtensionService* service = profile->GetExtensionService();
575 if (!service)
576 return false;
577
578 // We have to have a valid extension with background page to proceed.
579 const Extension* extension =
580 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
581 if (!extension)
582 return false;
583 if (!extension->has_background_page())
584 return false;
585
586 std::set<int> process_ids;
587 size_t max_process_count =
588 content::RenderProcessHost::GetMaxRendererProcessCount();
589
590 // Go through all profiles to ensure we have total count of extension
591 // processes containing background pages, otherwise one profile can
592 // starve the other.
593 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
594 GetLoadedProfiles();
595 for (size_t i = 0; i < profiles.size(); ++i) {
596 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
597 for (ExtensionProcessManager::const_iterator iter = epm->begin();
598 iter != epm->end();
599 ++iter) {
600 ExtensionHost* host = *iter;
601 if (host->extension()->has_background_page()) {
602 process_ids.insert(host->render_process_host()->GetID());
603 }
604 }
605 }
606
607 if (process_ids.size() >
608 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
609 return true;
610 }
611
612 return false;
613}
614
[email protected]6f371442011-11-09 06:45:46615void ChromeContentBrowserClient::SiteInstanceGotProcess(
616 SiteInstance* site_instance) {
617 CHECK(site_instance->HasProcess());
618
619 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02620 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46621 ExtensionService* service = profile->GetExtensionService();
622 if (!service)
623 return;
624
625 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44626 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33627 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46628 if (!extension)
629 return;
630
[email protected]6bc04fd82011-12-04 02:29:35631 service->process_map()->Insert(extension->id(),
632 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33633 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46634 BrowserThread::PostTask(
635 BrowserThread::IO, FROM_HERE,
636 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24637 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46638 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35639 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33640 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46641}
642
643void ChromeContentBrowserClient::SiteInstanceDeleting(
644 SiteInstance* site_instance) {
645 if (!site_instance->HasProcess())
646 return;
647
648 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02649 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46650 ExtensionService* service = profile->GetExtensionService();
651 if (!service)
652 return;
653
654 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44655 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33656 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46657 if (!extension)
658 return;
659
[email protected]6bc04fd82011-12-04 02:29:35660 service->process_map()->Remove(extension->id(),
661 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33662 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46663 BrowserThread::PostTask(
664 BrowserThread::IO, FROM_HERE,
665 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24666 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46667 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35668 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33669 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46670}
671
[email protected]e3daf3c2011-10-05 21:17:08672bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
673 const GURL& current_url,
674 const GURL& new_url) {
675 if (current_url.is_empty()) {
676 // Always choose a new process when navigating to extension URLs. The
677 // process grouping logic will combine all of a given extension's pages
678 // into the same process.
679 if (new_url.SchemeIs(chrome::kExtensionScheme))
680 return true;
681
682 return false;
683 }
684
685 // Also, we must switch if one is an extension and the other is not the exact
686 // same extension.
687 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
688 new_url.SchemeIs(chrome::kExtensionScheme)) {
689 if (current_url.GetOrigin() != new_url.GetOrigin())
690 return true;
691 }
692
693 return false;
694}
695
[email protected]763ec4ca2011-04-29 15:48:12696std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
697 const std::string& alias_name) {
698 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
699}
700
[email protected]b80f68432011-05-02 17:22:30701void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
702 CommandLine* command_line, int child_process_id) {
703#if defined(USE_LINUX_BREAKPAD)
704 if (IsCrashReporterEnabled()) {
705 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
706 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
707 }
708#elif defined(OS_MACOSX)
709 if (IsCrashReporterEnabled()) {
710 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
711 child_process_logging::GetClientId());
712 }
713#endif // OS_MACOSX
714
[email protected]f1933792011-06-14 00:49:34715 if (logging::DialogsAreSuppressed())
716 command_line->AppendSwitch(switches::kNoErrorDialogs);
717
[email protected]b80f68432011-05-02 17:22:30718 std::string process_type =
719 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17720 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52721 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30722 FilePath user_data_dir =
723 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
724 if (!user_data_dir.empty())
725 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
726#if defined(OS_CHROMEOS)
727 const std::string& login_profile =
728 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
729 if (!login_profile.empty())
730 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
731#endif
732
[email protected]f3b1a082011-11-18 00:34:30733 content::RenderProcessHost* process =
734 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37735 if (process) {
736 Profile* profile = Profile::FromBrowserContext(
737 process->GetBrowserContext());
738 extensions::ProcessMap* process_map =
739 profile->GetExtensionService()->process_map();
740 if (process_map && process_map->Contains(process->GetID()))
741 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30742
[email protected]a8d851f82011-12-21 00:32:37743 PrefService* prefs = profile->GetPrefs();
744 // Currently this pref is only registered if applied via a policy.
745 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
746 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
747 // Turn this policy into a command line switch.
748 command_line->AppendSwitch(switches::kDisable3DAPIs);
749 }
[email protected]718eab62011-10-05 21:16:52750
[email protected]a8d851f82011-12-21 00:32:37751 // Disable client-side phishing detection in the renderer if it is
752 // disabled in the Profile preferences or the browser process.
753 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
754 !g_browser_process->safe_browsing_detection_service()) {
755 command_line->AppendSwitch(
756 switches::kDisableClientSidePhishingDetection);
757 }
[email protected]8c40da62011-07-13 22:58:46758 }
[email protected]47c7ec82012-01-18 03:29:21759 {
760 PrefService* local_state = g_browser_process->local_state();
761 if (local_state &&
762 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
763 command_line->AppendSwitch(switches::kRendererPrintPreview);
764 }
765 }
[email protected]4287a3d2011-06-13 23:56:51766
[email protected]47c7ec82012-01-18 03:29:21767 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51768 static const char* const kSwitchNames[] = {
769 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48770 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51771 switches::kAllowScriptingGallery,
772 switches::kAppsCheckoutURL,
773 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31774 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51775 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50776 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51777 switches::kDumpHistogramsOnExit,
[email protected]b7e44ff2012-02-16 03:37:34778 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21779 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13780 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51781 switches::kEnableCrxlessWebApps,
782 switches::kEnableExperimentalExtensionApis,
783 switches::kEnableInBrowserThumbnailing,
784 switches::kEnableIPCFuzzing,
785 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:48786 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53787 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51788 switches::kEnableWatchdog,
789 switches::kExperimentalSpellcheckerFeatures,
790 switches::kMemoryProfiling,
791 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04792 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51793 switches::kPpapiFlashArgs,
794 switches::kPpapiFlashInProcess,
795 switches::kPpapiFlashPath,
796 switches::kPpapiFlashVersion,
797 switches::kProfilingAtStart,
798 switches::kProfilingFile,
799 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51800 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38801 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51802 };
803
804 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
805 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17806 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38807 static const char* const kSwitchNames[] = {
808 switches::kEnableExperimentalExtensionApis,
[email protected]ee14cad2012-03-29 01:59:37809 switches::kEnablePlatformApps,
[email protected]a446534d2012-02-09 00:07:38810 switches::kWhitelistedExtensionID,
811 };
812
813 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
814 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51815 } else if (process_type == switches::kPluginProcess) {
816 static const char* const kSwitchNames[] = {
817 #if defined(OS_CHROMEOS)
818 switches::kLoginProfile,
819 #endif
820 switches::kMemoryProfiling,
821 switches::kSilentDumpOnDCHECK,
822 switches::kUserDataDir,
823 };
824
825 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
826 arraysize(kSwitchNames));
827 } else if (process_type == switches::kZygoteProcess) {
828 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51829 switches::kUserDataDir, // Make logs go to the right file.
830 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50831 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13832 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51833 switches::kPpapiFlashInProcess,
834 switches::kPpapiFlashPath,
835 switches::kPpapiFlashVersion,
836 };
837
838 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
839 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11840 } else if (process_type == switches::kGpuProcess) {
841 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
842 // because GPU is expected to be unreliable.
843 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
844 !command_line->HasSwitch(switches::kDisableBreakpad))
845 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30846 }
[email protected]6f08af82011-09-15 01:19:03847
848 // The command line switch kEnableBenchmarking needs to be specified along
849 // with the kEnableStatsTable switch to ensure that the stats table global
850 // is initialized correctly.
851 if (command_line->HasSwitch(switches::kEnableBenchmarking))
852 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30853}
854
855std::string ChromeContentBrowserClient::GetApplicationLocale() {
856 return g_browser_process->GetApplicationLocale();
857}
858
[email protected]597a867b2011-11-18 18:31:20859std::string ChromeContentBrowserClient::GetAcceptLangs(
860 content::BrowserContext* context) {
861 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37862 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08863}
864
[email protected]ac55e292011-06-24 05:16:08865SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22866 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08867 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
868}
869
[email protected]a2176792011-05-08 19:30:49870bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09871 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19872 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20873 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32874 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20875 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05876 return io_data->GetCookieSettings()->
877 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49878}
879
[email protected]ed24fad2011-05-10 22:44:01880bool ChromeContentBrowserClient::AllowGetCookie(
881 const GURL& url,
882 const GURL& first_party,
883 const net::CookieList& cookie_list,
[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 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20888 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05889 bool allow = io_data->GetCookieSettings()->
890 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01891
[email protected]8093a542011-05-13 07:29:32892 BrowserThread::PostTask(
893 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03894 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43895 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01896 return allow;
897}
898
899bool ChromeContentBrowserClient::AllowSetCookie(
900 const GURL& url,
901 const GURL& first_party,
902 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20903 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01904 int render_process_id,
905 int render_view_id,
906 net::CookieOptions* options) {
907 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20908 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05909 CookieSettings* cookie_settings = io_data->GetCookieSettings();
910 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
911
912 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09913 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01914
[email protected]8093a542011-05-13 07:29:32915 BrowserThread::PostTask(
916 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03917 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43918 render_view_id, url, first_party, cookie_line, *options,
919 !allow));
[email protected]ed24fad2011-05-10 22:44:01920 return allow;
921}
922
[email protected]d5a19162011-06-30 18:51:54923bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20924 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54925 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20926 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26927
[email protected]f24bd172012-03-31 01:54:59928 return !io_data->clear_local_state_on_exit()->GetValue();
[email protected]d5a19162011-06-30 18:51:54929}
930
[email protected]5c5a88e2011-11-12 00:45:35931bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35932 const GURL& url,
933 const string16& name,
934 const string16& display_name,
935 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20936 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48937 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20939 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35940 CookieSettings* cookie_settings = io_data->GetCookieSettings();
941 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
942
[email protected]62151052012-02-01 18:40:48943 // Record access to database for potential display in UI.
944 std::vector<std::pair<int, int> >::const_iterator i;
945 for (i = render_views.begin(); i != render_views.end(); ++i) {
946 BrowserThread::PostTask(
947 BrowserThread::UI, FROM_HERE,
948 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
949 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35950 }
951
952 return allow;
953}
954
955bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35956 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20957 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48958 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35959 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20960 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35961 CookieSettings* cookie_settings = io_data->GetCookieSettings();
962 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
963
[email protected]62151052012-02-01 18:40:48964 // Record access to file system for potential display in UI.
965 std::vector<std::pair<int, int> >::const_iterator i;
966 for (i = render_views.begin(); i != render_views.end(); ++i) {
967 BrowserThread::PostTask(
968 BrowserThread::UI, FROM_HERE,
969 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
970 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35971 }
972
973 return allow;
974}
975
[email protected]7c5ff9a2012-03-02 07:42:49976bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
977 const GURL& url,
978 const string16& name,
979 content::ResourceContext* context,
980 const std::vector<std::pair<int, int> >& render_views) {
981 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
982 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
983 CookieSettings* cookie_settings = io_data->GetCookieSettings();
984 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
985
986 // Record access to IndexedDB for potential display in UI.
987 std::vector<std::pair<int, int> >::const_iterator i;
988 for (i = render_views.begin(); i != render_views.end(); ++i) {
989 BrowserThread::PostTask(
990 BrowserThread::UI, FROM_HERE,
991 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
992 i->first, i->second, url, name, !allow));
993 }
994
995 return allow;
996}
997
[email protected]6133f922011-07-01 21:34:34998net::URLRequestContext*
999ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:201000 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:341001 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1002 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:201003 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:341004 return io_data->extensions_request_context();
1005 }
1006
1007 return NULL;
1008}
1009
[email protected]317f96c92011-05-31 06:53:411010QuotaPermissionContext*
1011ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1012 return new ChromeQuotaPermissionContext();
1013}
1014
[email protected]a0ce3282011-08-19 20:49:521015void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421016 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421017}
1018
[email protected]a0ce3282011-08-19 20:49:521019void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521020 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521021}
1022
[email protected]848dd042011-06-04 18:24:031023void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171024 int render_process_id,
1025 int render_view_id,
1026 int cert_error,
1027 const net::SSLInfo& ssl_info,
1028 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031029 bool overridable,
[email protected]4cf611e32012-02-13 16:06:171030 const base::Callback<void(bool)>& callback,
1031 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411032 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131033 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171034 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411035 if (!tab) {
1036 NOTREACHED();
1037 return;
1038 }
1039 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501040 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301041 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091042 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411043 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171044 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411045 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171046 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411047 return;
1048 }
1049 }
1050
1051 // Otherwise, display an SSL blocking page.
[email protected]4cf611e32012-02-13 16:06:171052 new SSLBlockingPage(
1053 tab, cert_error, ssl_info, request_url, overridable, callback);
[email protected]848dd042011-06-04 18:24:031054}
1055
[email protected]c99c442e2011-08-24 11:37:301056void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451057 int render_process_id,
1058 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401059 const net::HttpNetworkSession* network_session,
1060 net::SSLCertRequestInfo* cert_request_info,
1061 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131062 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451063 render_process_id, render_view_id);
1064 if (!tab) {
1065 NOTREACHED();
1066 return;
1067 }
1068
[email protected]6786bf402011-12-03 15:19:451069 GURL requesting_url("https://" + cert_request_info->host_and_port);
1070 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1071 << cert_request_info->host_and_port;
1072
[email protected]627e0512011-12-21 22:55:301073 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451074 scoped_ptr<Value> filter(
1075 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1076 requesting_url,
1077 requesting_url,
1078 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1079 std::string(), NULL));
1080
1081 if (filter.get()) {
1082 // Try to automatically select a client certificate.
1083 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1084 DictionaryValue* filter_dict =
1085 static_cast<DictionaryValue*>(filter.get());
1086
1087 const std::vector<scoped_refptr<net::X509Certificate> >&
1088 all_client_certs = cert_request_info->client_certs;
1089 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1090 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1091 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401092 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451093 return;
1094 }
1095 }
1096 } else {
1097 NOTREACHED();
1098 }
1099 }
1100
[email protected]8ec26472011-06-06 16:52:451101 TabContentsWrapper* wrapper =
1102 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451103 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131104 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451105 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141106 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401107 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451108 return;
1109 }
[email protected]7a593db2012-02-13 21:19:401110 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1111 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451112}
1113
1114void ChromeContentBrowserClient::AddNewCertificate(
1115 net::URLRequest* request,
1116 net::X509Certificate* cert,
1117 int render_process_id,
1118 int render_view_id) {
1119 // The handler will run the UI and delete itself when it's finished.
1120 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1121}
1122
[email protected]a93670ab2012-02-24 03:46:391123void ChromeContentBrowserClient::RequestMediaAccessPermission(
1124 const content::MediaStreamRequest* request,
1125 const content::MediaResponseCallback& callback) {
1126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1127
[email protected]117b6b42012-02-29 09:11:081128 WebContents* contents = tab_util::GetWebContentsByID(
1129 request->render_process_id, request->render_view_id);
1130 if (!contents) {
1131 // Abort, if the tab was closed after the request was made but before we
1132 // got to this point.
1133 callback.Run(content::MediaStreamDevices());
1134 return;
1135 }
1136
1137 TabContentsWrapper* tab =
1138 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1139 DCHECK(tab);
1140
1141 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1142 InfoBarDelegate* old_infobar = NULL;
1143 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1144 old_infobar =
1145 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfobarDelegate();
1146 }
1147
[email protected]3bc518b2012-03-09 03:01:501148#if defined(TOOLKIT_VIEWS) || defined(OS_LINUX)
[email protected]117b6b42012-02-29 09:11:081149 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1150 request,
1151 callback);
1152 if (old_infobar)
1153 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1154 else
1155 infobar_helper->AddInfoBar(infobar);
[email protected]3bc518b2012-03-09 03:01:501156#elif defined(OS_MACOSX)
1157 // TODO(macourteau): UI is not implemented yet for OS X. Fallback to
[email protected]117b6b42012-02-29 09:11:081158 // the default behaviour and allow access to the first device of each
1159 // requested type.
1160 content::MediaStreamDevices devices;
[email protected]a93670ab2012-02-24 03:46:391161 for (content::MediaStreamDeviceMap::const_iterator it =
1162 request->devices.begin(); it != request->devices.end(); ++it) {
[email protected]6c6415a2012-03-01 17:17:281163 if (!it->second.empty())
1164 devices.push_back(*it->second.begin());
[email protected]a93670ab2012-02-24 03:46:391165 }
1166
[email protected]a93670ab2012-02-24 03:46:391167 callback.Run(devices);
[email protected]3bc518b2012-03-09 03:01:501168#endif // TOOLKIT_VIEWS || OS_LINUX
[email protected]a93670ab2012-02-24 03:46:391169}
1170
[email protected]dc73a7b2012-03-25 15:27:181171content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1172 return MediaInternals::GetInstance();
1173}
1174
[email protected]941623e2011-06-07 23:06:041175void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1176 const GURL& source_origin,
1177 int callback_context,
1178 int render_process_id,
1179 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111180#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041181 RenderViewHost* rvh = RenderViewHost::FromID(
1182 render_process_id, render_view_id);
1183 if (!rvh) {
1184 NOTREACHED();
1185 return;
1186 }
1187
[email protected]9f76c1e2012-03-05 15:15:581188 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301189 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041190 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371191 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041192 service->RequestPermission(
1193 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131194 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111195#else
1196 NOTIMPLEMENTED();
1197#endif
[email protected]941623e2011-06-07 23:06:041198}
1199
1200WebKit::WebNotificationPresenter::Permission
1201 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021202 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201203 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021204 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111205#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201207 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021208 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1209 source_origin, render_process_id,
1210 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041211 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041212
1213 // Fall back to the regular notification preferences, which works on an
1214 // origin basis.
1215 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371216 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041217 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111218#else
1219 return WebKit::WebNotificationPresenter::PermissionAllowed;
1220#endif
[email protected]941623e2011-06-07 23:06:041221}
1222
1223void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171224 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041225 int render_process_id,
1226 int render_view_id,
1227 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111228#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041229 RenderViewHost* rvh = RenderViewHost::FromID(
1230 render_process_id, render_view_id);
1231 if (!rvh) {
1232 NOTREACHED();
1233 return;
1234 }
1235
[email protected]9f76c1e2012-03-05 15:15:581236 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301237 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041238 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371239 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041240 service->ShowDesktopNotification(
1241 params, render_process_id, render_view_id,
1242 worker ? DesktopNotificationService::WorkerNotification :
1243 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111244#else
1245 NOTIMPLEMENTED();
1246#endif
[email protected]941623e2011-06-07 23:06:041247}
1248
1249void ChromeContentBrowserClient::CancelDesktopNotification(
1250 int render_process_id,
1251 int render_view_id,
1252 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111253#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041254 RenderViewHost* rvh = RenderViewHost::FromID(
1255 render_process_id, render_view_id);
1256 if (!rvh) {
1257 NOTREACHED();
1258 return;
1259 }
1260
[email protected]9f76c1e2012-03-05 15:15:581261 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301262 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041263 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371264 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041265 service->CancelDesktopNotification(
1266 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111267#else
1268 NOTIMPLEMENTED();
1269#endif
[email protected]941623e2011-06-07 23:06:041270}
1271
[email protected]9f3fba52011-06-08 20:37:191272bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351273 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021274 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191275 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201276 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011277 int render_process_id,
1278 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011280
1281 *no_javascript_access = false;
1282
[email protected]9f3fba52011-06-08 20:37:191283 // If the opener is trying to create a background window but doesn't have
1284 // the appropriate permission, fail the attempt.
1285 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201286 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531287 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1288
[email protected]03b6d552012-03-29 04:03:011289 if (!map->SecurityOriginHasAPIPermission(
1290 source_origin,
1291 render_process_id,
1292 ExtensionAPIPermission::kBackground)) {
1293 return false;
1294 }
1295
[email protected]7b54ca02012-03-02 18:06:531296 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1297 // return a recently installed Extension even if this CanCreateWindow call
1298 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011299 // because the permission check above would have caused an early return
1300 // already. We must use the full URL to find hosted apps, though, and not
1301 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531302 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351303 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531304 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011305 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191306 }
1307 return true;
1308}
1309
1310std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201311 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1313 // Check if it's an extension-created worker, in which case we want to use
1314 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201315 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191316 const Extension* extension =
1317 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1318 return extension ? extension->name() : std::string();
1319}
1320
[email protected]99907362012-01-11 05:41:401321void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1322 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171323}
1324
[email protected]c52b2892012-03-07 11:01:021325content::SpeechRecognitionManagerDelegate*
1326 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321327#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021328 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321329#else
1330 return NULL;
1331#endif
[email protected]66cfec62012-02-24 17:57:511332}
1333
[email protected]3cb054e62011-06-13 05:21:171334ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1335 return g_browser_process->clipboard();
1336}
1337
[email protected]ae6e9912011-07-27 01:18:281338net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1339 return g_browser_process->net_log();
1340}
1341
[email protected]32538d92011-08-25 00:09:231342AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1343 return new ChromeAccessTokenStore();
1344}
1345
[email protected]dbae6b02011-06-29 23:51:411346bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1347 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1348 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1349}
1350
[email protected]64d69de42012-02-06 00:19:541351void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321352 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061353 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581354 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061355 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061356
[email protected]64d69de42012-02-06 00:19:541357 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061358 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541359 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061360 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541361 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061362 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541363 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061364 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541365 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061366 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541367 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061368 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1369
1370 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541371 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061372 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541373 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061374 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541375 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061376 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541377 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061378 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541379 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061380 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541381 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061382
[email protected]64d69de42012-02-06 00:19:541383 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061384 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541385 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061386 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541387 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061388 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541389 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061390 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1391
[email protected]64d69de42012-02-06 00:19:541392 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061393
[email protected]64d69de42012-02-06 00:19:541394 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061395 prefs->GetBoolean(
1396 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541397 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061398 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541399 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061400 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1401 const DictionaryValue* inspector_settings =
1402 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1403 if (inspector_settings) {
1404 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1405 iter != inspector_settings->end_keys(); ++iter) {
1406 std::string value;
1407 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541408 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061409 std::make_pair(*iter, value));
1410 }
1411 }
[email protected]64d69de42012-02-06 00:19:541412 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061413
[email protected]64d69de42012-02-06 00:19:541414 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1415 web_prefs->javascript_enabled = false;
1416 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1417 web_prefs->web_security_enabled = false;
1418 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1419 web_prefs->plugins_enabled = false;
1420 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1421 web_prefs->java_enabled = false;
1422 web_prefs->loads_images_automatically =
1423 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061424
[email protected]64d69de42012-02-06 00:19:541425 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1426 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061427
[email protected]64d69de42012-02-06 00:19:541428 web_prefs->memory_info_enabled =
1429 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1430 web_prefs->allow_displaying_insecure_content =
1431 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1432 web_prefs->allow_running_insecure_content =
1433 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081434 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061435
[email protected]64d69de42012-02-06 00:19:541436 // The user stylesheet watcher may not exist in a testing profile.
1437 if (profile->GetUserStyleSheetWatcher()) {
1438 web_prefs->user_style_sheet_enabled = true;
1439 web_prefs->user_style_sheet_location =
1440 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1441 } else {
1442 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061443 }
1444
[email protected]b7e44ff2012-02-16 03:37:341445 web_prefs->asynchronous_spell_checking_enabled =
1446 CommandLine::ForCurrentProcess()->
1447 HasSwitch(switches::kEnableAsynchronousSpellChecking);
1448 web_prefs->unified_textchecker_enabled =
1449 web_prefs->asynchronous_spell_checking_enabled ||
1450 CommandLine::ForCurrentProcess()->
1451 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571452
[email protected]64d69de42012-02-06 00:19:541453 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061454 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541455 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061456 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541457 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061458 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1459
1460 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541461 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061462 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541463 web_prefs->default_encoding);
1464 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061465 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541466 web_prefs->default_encoding =
1467 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061468 }
[email protected]64d69de42012-02-06 00:19:541469 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061470
1471 ExtensionService* service = profile->GetExtensionService();
1472 if (service) {
1473 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581474 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061475 extension_webkit_preferences::SetPreferences(
[email protected]9f76c1e2012-03-05 15:15:581476 extension, rvh->GetDelegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061477 }
1478
[email protected]9f76c1e2012-03-05 15:15:581479 if (rvh->GetDelegate()->GetRenderViewType() ==
1480 chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541481 web_prefs->allow_scripts_to_close_windows = true;
[email protected]9f76c1e2012-03-05 15:15:581482 } else if (rvh->GetDelegate()->GetRenderViewType() ==
[email protected]f3986f82012-01-03 20:00:061483 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1484 // Disable all kinds of acceleration for background pages.
1485 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541486 web_prefs->force_compositing_mode = false;
1487 web_prefs->accelerated_compositing_enabled = false;
1488 web_prefs->accelerated_2d_canvas_enabled = false;
1489 web_prefs->accelerated_video_enabled = false;
1490 web_prefs->accelerated_painting_enabled = false;
1491 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061492 }
[email protected]2e21fe292012-03-02 22:52:321493
1494#if defined(FILE_MANAGER_EXTENSION)
1495 // Override the default of suppressing HW compositing for WebUI pages for the
1496 // file manager, which is implemented using WebUI but wants HW acceleration
1497 // for video decode & render.
1498 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1499 web_prefs->accelerated_compositing_enabled = true;
1500 web_prefs->accelerated_2d_canvas_enabled = true;
1501 }
1502#endif
[email protected]181a95ee2011-07-12 19:26:361503}
1504
1505void ChromeContentBrowserClient::UpdateInspectorSetting(
1506 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061507 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581508 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061509 DictionaryPrefUpdate update(
1510 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1511 prefs::kWebKitInspectorSettings);
1512 DictionaryValue* inspector_settings = update.Get();
1513 inspector_settings->SetWithoutPathExpansion(key,
1514 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361515}
1516
1517void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061518 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581519 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061520 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1521 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361522}
1523
[email protected]b8148ac2011-07-13 22:03:251524void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1525 BrowserURLHandler* handler) {
1526 // Add the default URL handlers.
1527 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1528 BrowserURLHandler::null_handler());
1529 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1530 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1531
[email protected]b3adbd02011-11-30 22:23:271532 // about: handler. Must come before chrome: handler, since it will
1533 // rewrite about: urls to chrome: URLs and then expect chrome: to
1534 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251535 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1536 BrowserURLHandler::null_handler());
1537 // chrome: & friends.
1538 handler->AddHandlerPair(&HandleWebUI,
1539 BrowserURLHandler::null_handler());
1540}
1541
1542void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371543 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581544 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251545 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1546 BrowsingDataRemover::EVERYTHING,
1547 base::Time());
1548 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1549 // BrowsingDataRemover takes care of deleting itself when done.
1550}
1551
1552void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371553 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581554 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251555 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1556 BrowsingDataRemover::EVERYTHING,
1557 base::Time());
[email protected]dceaa912011-09-06 17:17:231558 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251559 remover->Remove(remove_mask);
1560 // BrowsingDataRemover takes care of deleting itself when done.
1561}
1562
[email protected]e1d16eb92011-08-18 23:19:321563FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1564 return download_util::GetDefaultDownloadDirectory();
1565}
1566
[email protected]c9b6eb62011-10-18 20:49:391567std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1568 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1569}
1570
[email protected]a658d452012-03-02 12:45:291571bool ChromeContentBrowserClient::AllowSocketAPI(
1572 content::BrowserContext* browser_context, const GURL& url) {
1573 if (!url.is_valid())
1574 return false;
1575
1576 std::string host = url.host();
1577 if (allowed_socket_origins_.count(host))
1578 return true;
1579
[email protected]f237c0f2012-03-10 07:49:101580 // Need to check this now and not on construction because otherwise it won't
1581 // work with browser_tests.
1582 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1583 std::string allowed_list =
1584 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
1585 if (!allowed_list.empty()) {
1586 StringTokenizer t(allowed_list, ",");
1587 while (t.GetNext()) {
1588 if (t.token() == host)
1589 return true;
1590 }
1591 }
1592
[email protected]a658d452012-03-02 12:45:291593 Profile* profile = Profile::FromBrowserContext(browser_context);
1594 if (!profile || !profile->GetExtensionService())
1595 return false;
1596
1597 const Extension* extension = profile->GetExtensionService()->extensions()->
1598 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1599 if (!extension)
1600 return false;
1601
1602 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1603 return true;
1604
1605 return false;
[email protected]e461da2f2012-02-16 19:06:401606}
1607
[email protected]e60c0232011-11-11 19:56:351608#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301609int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521610 const CommandLine& command_line) {
[email protected]6e677a342012-02-11 01:21:141611#if defined(OS_ANDROID)
1612 // TODO(carlosvaldivia): Upstream breakpad code for Android and remove this
1613 // fork. http://crbug.com/113560
1614 NOTIMPLEMENTED();
1615#else
[email protected]718eab62011-10-05 21:16:521616 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071617 ExtensionCrashHandlerHostLinux* crash_handler =
1618 ExtensionCrashHandlerHostLinux::GetInstance();
1619 return crash_handler->GetDeathSignalSocket();
1620 }
1621
[email protected]718eab62011-10-05 21:16:521622 std::string process_type =
1623 command_line.GetSwitchValueASCII(switches::kProcessType);
1624
1625 if (process_type == switches::kRendererProcess)
1626 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1627
[email protected]b80f68432011-05-02 17:22:301628 if (process_type == switches::kPluginProcess)
1629 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1630
1631 if (process_type == switches::kPpapiPluginProcess)
1632 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1633
1634 if (process_type == switches::kGpuProcess)
1635 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
[email protected]6e677a342012-02-11 01:21:141636#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:301637
1638 return -1;
1639}
[email protected]e60c0232011-11-11 19:56:351640#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301641
[email protected]4a65826d2011-08-25 16:04:011642#if defined(OS_WIN)
1643const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1644 return chrome::kBrowserResourcesDll;
1645}
1646#endif
1647
[email protected]37a72af2011-06-13 05:42:011648#if defined(USE_NSS)
1649crypto::CryptoModuleBlockingPasswordDelegate*
1650 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1651 const GURL& url) {
1652 return browser::NewCryptoModuleBlockingDialogDelegate(
1653 browser::kCryptoModulePasswordKeygen, url.host());
1654}
1655#endif
1656
[email protected]d977f9c2011-03-14 16:10:261657} // namespace chrome