blob: 7ee35b9e0fb80140d296f3eef63884f24703ec3d [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]e461da2f2012-02-16 19:06:4013#include "base/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0614#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3015#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2516#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3017#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2318#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1219#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0320#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4121#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5622#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0523#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4524#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3225#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0826#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3227#include "chrome/browser/download/download_util.h"
[email protected]2b33dcd02012-03-18 01:34:1628#include "chrome/browser/extensions/api/web_request/web_request_api.h"
[email protected]76411f412012-02-22 18:56:0629#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0430#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1031#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]9c1662b2012-03-06 15:44:3332#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2633#include "chrome/browser/extensions/extension_service.h"
[email protected]31d8f5f22012-04-02 15:22:0834#include "chrome/browser/extensions/extension_system.h"
[email protected]b8148ac2011-07-13 22:03:2535#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0636#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]32538d92011-08-25 00:09:2337#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1238#include "chrome/browser/google/google_util.h"
[email protected]117b6b42012-02-29 09:11:0839#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]dc73a7b2012-03-25 15:27:1840#include "chrome/browser/media/media_internals.h"
[email protected]ae6e9912011-07-27 01:18:2841#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0442#include "chrome/browser/notifications/desktop_notification_service.h"
43#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]e0ada9c2012-03-20 03:54:4344#include "chrome/browser/pepper_gtalk_message_filter.h"
[email protected]0609b17f2011-05-31 20:13:4245#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1246#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0647#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4148#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5049#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4150#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1451#include "chrome/browser/printing/printing_message_filter.h"
52#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3253#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0654#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1455#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3356#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4257#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1458#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]c52b2892012-03-07 11:01:0259#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4660#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4561#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0362#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4563#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
64#include "chrome/browser/tab_contents/tab_util.h"
[email protected]117b6b42012-02-29 09:11:0865#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]8ec26472011-06-06 16:52:4566#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]863f70a2012-01-27 02:05:5067#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0668#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]13169ab2012-04-06 07:48:1569#include "chrome/browser/user_style_sheet_watcher_factory.h"
[email protected]b80f68432011-05-02 17:22:3070#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0171#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3072#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0473#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4474#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3475#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1276#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3877#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0978#include "chrome/common/url_constants.h"
[email protected]e0ada9c2012-03-20 03:54:4379#include "content/public/browser/browser_child_process_host.h"
[email protected]b48c9182011-10-26 18:03:3080#include "content/public/browser/browser_main_parts.h"
[email protected]825b1662012-03-12 19:07:3181#include "content/public/browser/browser_url_handler.h"
[email protected]b9535422012-02-09 01:47:5982#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3083#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3384#include "content/public/browser/render_view_host.h"
[email protected]ce967862012-02-09 22:47:0585#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3386#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1987#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1088#include "content/public/browser/web_contents_view.h"
[email protected]e0ada9c2012-03-20 03:54:4389#include "content/public/common/child_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3990#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3491#include "grit/ui_resources.h"
[email protected]7a593db2012-02-13 21:19:4092#include "net/base/ssl_cert_request_info.h"
[email protected]aa84a7e2012-03-15 21:29:0693#include "net/cookies/cookie_monster.h"
94#include "net/cookies/cookie_options.h"
[email protected]c9b6eb62011-10-18 20:49:3995#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0896#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3697#include "webkit/glue/webpreferences.h"
[email protected]a085aed72012-04-24 05:32:0498#include "webkit/plugins/plugin_switches.h"
[email protected]d977f9c2011-03-14 16:10:2699
[email protected]b48c9182011-10-26 18:03:30100#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:38101#include "chrome/browser/chrome_browser_main_win.h"
102#elif defined(OS_MACOSX)
103#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:56104#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]38b098f2012-03-14 21:11:57105#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h"
[email protected]b48c9182011-10-26 18:03:30106#elif defined(OS_CHROMEOS)
107#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]fe69558d2012-03-12 11:34:49108#include "chrome/browser/chromeos/login/user_manager.h"
[email protected]81ce2c42012-03-24 01:43:26109#elif defined(OS_LINUX)
[email protected]b48c9182011-10-26 18:03:30110#include "chrome/browser/chrome_browser_main_linux.h"
111#elif defined(OS_POSIX)
112#include "chrome/browser/chrome_browser_main_posix.h"
113#endif
114
[email protected]c0d7f792012-04-18 19:16:00115#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13116#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_views.h"
[email protected]61e69822012-03-14 22:08:57117#endif
118
[email protected]a13283cc2012-04-05 00:21:22119#if defined(TOOLKIT_GTK)
[email protected]50462bf02011-11-21 19:13:31120#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38121#endif
122
[email protected]c7480942011-11-08 19:18:27123#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31124#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27125#endif
126
127#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31128#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
129#endif
130
[email protected]dc04be7c2012-03-15 23:57:49131#if defined(USE_ASH)
132#include "chrome/browser/chrome_browser_main_extra_parts_ash.h"
133#endif
134
[email protected]6653c192012-04-10 22:52:44135#if defined(OS_LINUX) || defined(OS_OPENBSD) || defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:30136#include "base/linux_util.h"
[email protected]6653c192012-04-10 22:52:44137#include "chrome/browser/crash_handler_host_linuxish.h"
[email protected]1fd5302c2011-05-28 04:06:43138#endif
[email protected]b80f68432011-05-02 17:22:30139
[email protected]38b098f2012-03-14 21:11:57140#if defined(TOOLKIT_GTK)
141#include "chrome/browser/tab_contents/chrome_web_contents_view_delegate_gtk.h"
[email protected]74313b42011-08-24 16:51:32142#endif
[email protected]37a72af2011-06-13 05:42:01143#if defined(USE_NSS)
144#include "chrome/browser/ui/crypto_module_password_dialog.h"
145#endif
146
[email protected]c8c77182011-12-21 15:04:47147using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39148using content::BrowserThread;
[email protected]825b1662012-03-12 19:07:31149using content::BrowserURLHandler;
[email protected]b9535422012-02-09 01:47:59150using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00151using content::QuotaPermissionContext;
[email protected]eaabba22012-03-07 15:02:11152using content::RenderViewHost;
[email protected]b6583592012-01-25 19:52:33153using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13154using content::WebContents;
[email protected]631bb742011-11-02 11:29:39155
[email protected]c5dbef02011-05-13 05:06:09156namespace {
157
[email protected]e461da2f2012-02-16 19:06:40158const char* kPredefinedAllowedSocketOrigins[] = {
159 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
[email protected]b95bf502012-04-06 07:41:18160 "pnhechapfaindjhompbnflcldabbghjo", // HTerm App (SSH Client)
[email protected]99132682012-04-24 19:00:45161 "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126
162 "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop
163 "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop
164 "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop
165 "ojoimpklfciegopdfgeenehpalipignm" // Chromoting canary
[email protected]e461da2f2012-02-16 19:06:40166};
167
[email protected]b8148ac2011-07-13 22:03:25168// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42169bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50170 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
171 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25172 return false;
173
[email protected]fe69558d2012-03-12 11:34:49174#if defined(OS_CHROMEOS)
175 // Special case : in ChromeOS in Guest mode bookmarks and history are
176 // disabled for security reasons. New tab page explains the reasons, so
177 // we redirect user to new tab page.
178 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) {
179 if (url->SchemeIs(chrome::kChromeUIScheme) &&
180 (url->DomainIs(chrome::kChromeUIBookmarksHost) ||
181 url->DomainIs(chrome::kChromeUIHistoryHost))) {
182 // Rewrite with new tab URL
183 *url = GURL(chrome::kChromeUINewTabURL);
184 }
185 }
186#endif
187
[email protected]b8148ac2011-07-13 22:03:25188 // Special case the new tab page. In older versions of Chrome, the new tab
189 // page was hosted at chrome-internal:<blah>. This might be in people's saved
190 // sessions or bookmarks, so we say any URL with that scheme triggers the new
191 // tab page.
192 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
193 // Rewrite it with the proper new tab URL.
194 *url = GURL(chrome::kChromeUINewTabURL);
195 }
196
197 return true;
198}
199
[email protected]8d3132f62011-10-12 07:13:42200// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
201// below. Extension, and isolated apps require different privileges to be
202// granted to their RenderProcessHosts. This classification allows us to make
203// sure URLs are served by hosts with the right set of privileges.
204enum RenderProcessHostPrivilege {
205 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45206 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42207 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45208 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42209};
210
211RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
212 const GURL& url,
213 ExtensionService* service) {
214 // Default to a normal renderer cause it is lower privileged. This should only
215 // occur if the URL on a site instance is either malformed, or uninitialized.
216 // If it is malformed, then there is no need for better privileges anyways.
217 // If it is uninitialized, but eventually settles on being an a scheme other
218 // than normal webrenderer, the navigation logic will correct us out of band
219 // anyways.
220 if (!url.is_valid())
221 return PRIV_NORMAL;
222
223 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44224 const Extension* extension =
225 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45226 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42227 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45228 if (extension && extension->is_hosted_app())
229 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42230
231 return PRIV_EXTENSION;
232 }
233
234 return PRIV_NORMAL;
235}
236
237RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30238 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46239 extensions::ProcessMap* process_map,
240 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46241 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30242 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46243 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21244 return PRIV_NORMAL;
245
[email protected]6f371442011-11-09 06:45:46246 for (std::set<std::string>::iterator iter = extension_ids.begin();
247 iter != extension_ids.end(); ++iter) {
248 const Extension* extension = service->GetExtensionById(*iter, false);
249 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42250 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45251 if (extension && extension->is_hosted_app())
252 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42253 }
254
[email protected]676f6ab2011-10-19 20:23:21255 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42256}
257
[email protected]eec0b33c2011-12-05 22:09:45258bool IsIsolatedAppInProcess(const GURL& site_url,
259 content::RenderProcessHost* process_host,
260 extensions::ProcessMap* process_map,
261 ExtensionService* service) {
262 std::set<std::string> extension_ids =
263 process_map->GetExtensionsInProcess(process_host->GetID());
264 if (extension_ids.empty())
265 return false;
266
267 for (std::set<std::string>::iterator iter = extension_ids.begin();
268 iter != extension_ids.end(); ++iter) {
269 const Extension* extension = service->GetExtensionById(*iter, false);
270 if (extension &&
271 extension->is_storage_isolated() &&
272 extension->url() == site_url)
273 return true;
274 }
275
276 return false;
277}
278
[email protected]6786bf402011-12-03 15:19:45279bool CertMatchesFilter(const net::X509Certificate& cert,
280 const base::DictionaryValue& filter) {
281 // TODO(markusheintz): This is the minimal required filter implementation.
282 // Implement a better matcher.
283
284 // An empty filter matches any client certificate since no requirements are
285 // specified at all.
286 if (filter.empty())
287 return true;
288
289 std::string common_name;
290 if (filter.GetString("ISSUER.CN", &common_name) &&
291 (cert.issuer().common_name == common_name)) {
292 return true;
293 }
294 return false;
295}
296
[email protected]f3986f82012-01-03 20:00:06297// Fills |map| with the per-script font prefs under path |map_name|.
298void FillFontFamilyMap(const PrefService* prefs,
299 const char* map_name,
300 WebPreferences::ScriptFontFamilyMap* map) {
301 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
302 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
303 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
304 std::string font_family = prefs->GetString(pref_name.c_str());
305 if (!font_family.empty())
306 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
307 }
308}
309
[email protected]9dbfff12011-07-01 19:37:07310} // namespace
[email protected]c5dbef02011-05-13 05:06:09311
[email protected]d977f9c2011-03-14 16:10:26312namespace chrome {
313
[email protected]e461da2f2012-02-16 19:06:40314ChromeContentBrowserClient::ChromeContentBrowserClient() {
315 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
316 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
[email protected]e461da2f2012-02-16 19:06:40317}
318
319ChromeContentBrowserClient::~ChromeContentBrowserClient() {
320}
321
[email protected]50462bf02011-11-21 19:13:31322content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
323 const content::MainFunctionParams& parameters) {
324 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30325 // Construct the Main browser parts based on the OS type.
326#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31327 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04328#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31329 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30330#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31331 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]81ce2c42012-03-24 01:43:26332#elif defined(OS_LINUX)
[email protected]50462bf02011-11-21 19:13:31333 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14334#elif defined(OS_ANDROID)
335 // Do nothing for Android.
336 // TODO(klobag): Android initialization should use the
337 // *BrowserMainParts class-hierarchy for setting up custom initialization.
338 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30339#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31340 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04341#else
[email protected]b48c9182011-10-26 18:03:30342 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31343 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30344#endif
345
[email protected]c7480942011-11-08 19:18:27346 // Construct additional browser parts. Stages are called in the order in
347 // which they are added.
[email protected]a13283cc2012-04-05 00:21:22348#if defined(TOOLKIT_GTK)
[email protected]50462bf02011-11-21 19:13:31349 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04350#endif
[email protected]c7480942011-11-08 19:18:27351
352#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31353 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27354#endif
355
[email protected]dc04be7c2012-03-15 23:57:49356#if defined(USE_ASH)
357 main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh());
358#endif
359
[email protected]e050ef142012-03-21 01:04:24360#if defined(USE_AURA)
361 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
362#endif
363
[email protected]50462bf02011-11-21 19:13:31364 return main_parts;
[email protected]f967b722011-09-07 00:58:04365}
366
[email protected]38b098f2012-03-14 21:11:57367content::WebContentsView*
368 ChromeContentBrowserClient::OverrideCreateWebContentsView(
369 WebContents* web_contents) {
[email protected]38b098f2012-03-14 21:11:57370 return NULL;
371}
372
373content::WebContentsViewDelegate*
374 ChromeContentBrowserClient::GetWebContentsViewDelegate(
375 content::WebContents* web_contents) {
[email protected]c0d7f792012-04-18 19:16:00376#if defined(USE_AURA) || defined(OS_WIN)
[email protected]68b52252012-04-04 19:26:13377 return new ChromeWebContentsViewDelegateViews(web_contents);
[email protected]38b098f2012-03-14 21:11:57378#elif defined(TOOLKIT_GTK)
379 return new ChromeWebContentsViewDelegateGtk(web_contents);
[email protected]74313b42011-08-24 16:51:32380#elif defined(OS_MACOSX)
[email protected]38b098f2012-03-14 21:11:57381 return
382 chrome_web_contents_view_delegate_mac::CreateWebContentsViewDelegateMac(
383 web_contents);
[email protected]74313b42011-08-24 16:51:32384#else
[email protected]38b098f2012-03-14 21:11:57385 return NULL;
[email protected]74313b42011-08-24 16:51:32386#endif
387}
388
[email protected]f364d1392011-04-08 21:03:10389void ChromeContentBrowserClient::RenderViewHostCreated(
390 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46391
[email protected]9f76c1e2012-03-05 15:15:58392 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46393 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02394 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46395
396 new ChromeRenderViewHostObserver(render_view_host,
397 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10398 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26399}
400
[email protected]f3b1a082011-11-18 00:34:30401void ChromeContentBrowserClient::RenderProcessHostCreated(
402 content::RenderProcessHost* host) {
403 int id = host->GetID();
404 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
405 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02406 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30407 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03408#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30409 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03410#endif
[email protected]f3b1a082011-11-18 00:34:30411 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02412 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30413 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56414#if defined(OS_MACOSX)
415 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
416#endif
[email protected]f3b1a082011-11-18 00:34:30417 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03418 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38419
[email protected]2ccf45c2011-08-19 23:35:50420 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
421 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07422
423 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56424
425 RendererContentSettingRules rules;
426 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
427 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14428}
429
[email protected]e0ada9c2012-03-20 03:54:43430void ChromeContentBrowserClient::BrowserChildProcessHostCreated(
431 content::BrowserChildProcessHost* host) {
432 host->GetHost()->AddFilter(new PepperGtalkMessageFilter());
433}
434
[email protected]863f70a2012-01-27 02:05:50435content::WebUIControllerFactory*
436 ChromeContentBrowserClient::GetWebUIControllerFactory() {
437 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56438}
439
[email protected]3d7474ff2011-07-27 17:47:37440GURL ChromeContentBrowserClient::GetEffectiveURL(
441 content::BrowserContext* browser_context, const GURL& url) {
442 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08443 // Get the effective URL for the given actual URL. If the URL is part of an
444 // installed app, the effective URL is an extension URL with the ID of that
445 // extension as the host. This has the effect of grouping apps together in
446 // a common SiteInstance.
447 if (!profile || !profile->GetExtensionService())
448 return url;
449
[email protected]615d88f2011-12-13 01:47:44450 const Extension* extension = profile->GetExtensionService()->extensions()->
451 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08452 if (!extension)
453 return url;
454
[email protected]15877ca2011-11-18 22:40:52455 // Bookmark apps do not use the hosted app process model, and should be
456 // treated as normal URLs.
457 if (extension->from_bookmark())
458 return url;
459
[email protected]36fb2c7c2011-04-04 15:49:08460 // If the URL is part of an extension's web extent, convert it to an
461 // extension URL.
462 return extension->GetResourceURL(url.path());
463}
464
[email protected]056ad2a2011-07-12 02:13:55465bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37466 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55467 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52468 // Because we expect to use the effective URL, URLs for hosted apps (apart
469 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55470 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
471 return false;
472
[email protected]3d7474ff2011-07-27 17:47:37473 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55474 if (!profile || !profile->GetExtensionService())
475 return false;
476
[email protected]615d88f2011-12-13 01:47:44477 const Extension* extension = profile->GetExtensionService()->extensions()->
478 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55479 if (!extension)
480 return false;
481
482 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53483 // permission, or that does not allow JavaScript access to the background
484 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55485 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53486 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
487 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
488 !extension->allow_background_js_access()) {
489 return false;
490 }
491 }
[email protected]056ad2a2011-07-12 02:13:55492
[email protected]7b54ca02012-03-02 18:06:53493 // Hosted apps that have script access to their background page must use
494 // process per site, since all instances can make synchronous calls to the
495 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55496 return true;
497}
498
[email protected]46fb9442011-12-09 17:57:47499bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
500 return ProfileIOData::IsHandledURL(url);
501}
502
[email protected]2a5221b2011-09-27 23:07:31503bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30504 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31505 const GURL& site_url) {
506 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30507 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42508 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46509 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31510
[email protected]ffa97602011-11-17 17:55:52511 // Don't allow the Task Manager to share a process with anything else.
512 // Otherwise it can affect the renderers it is observing.
513 // Note: we could create another RenderProcessHostPrivilege bucket for
514 // this to allow multiple chrome://tasks instances to share, but that's
515 // a very unlikely case without serious consequences.
516 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
517 return false;
518
[email protected]8d3132f62011-10-12 07:13:42519 // These may be NULL during tests. In that case, just assume any site can
520 // share any host.
[email protected]6f371442011-11-09 06:45:46521 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31522 return true;
523
[email protected]a8c269a2011-10-25 20:17:22524 // Experimental:
525 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
526 // to share a renderer process. (We could allow pages from the same site or
527 // extensions of the same type to share, if we knew what the given process
528 // was dedicated to. Allowing no sharing is simpler for now.) This may
529 // cause resource exhaustion issues if too many sites are open at once.
530 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
531 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
532 return false;
533
[email protected]eec0b33c2011-12-05 22:09:45534 // An isolated app is only allowed to share with the exact same app in order
535 // to provide complete renderer process isolation. This also works around
536 // issue http://crbug.com/85588, where different isolated apps in the same
537 // process would end up using the first app's storage contexts.
538 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42539 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45540 if (privilege_required == PRIV_ISOLATED)
541 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
542
543 // Otherwise, just make sure the process privilege matches the privilege
544 // required by the site.
545 return GetProcessPrivilege(process_host, process_map, service) ==
546 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31547}
548
[email protected]76411f412012-02-22 18:56:06549// This function is trying to limit the amount of processes used by extensions
550// with background pages. It uses a globally set percentage of processes to
551// run such extensions and if the limit is exceeded, it returns true, to
552// indicate to the content module to group extensions together.
553bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
554 content::BrowserContext* browser_context, const GURL& url) {
555 // It has to be a valid URL for us to check for an extension.
556 if (!url.is_valid())
557 return false;
558
559 Profile* profile = Profile::FromBrowserContext(browser_context);
560 ExtensionService* service = profile->GetExtensionService();
561 if (!service)
562 return false;
563
564 // We have to have a valid extension with background page to proceed.
565 const Extension* extension =
566 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
567 if (!extension)
568 return false;
569 if (!extension->has_background_page())
570 return false;
571
572 std::set<int> process_ids;
573 size_t max_process_count =
574 content::RenderProcessHost::GetMaxRendererProcessCount();
575
576 // Go through all profiles to ensure we have total count of extension
577 // processes containing background pages, otherwise one profile can
578 // starve the other.
579 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
580 GetLoadedProfiles();
581 for (size_t i = 0; i < profiles.size(); ++i) {
582 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
583 for (ExtensionProcessManager::const_iterator iter = epm->begin();
584 iter != epm->end();
585 ++iter) {
586 ExtensionHost* host = *iter;
587 if (host->extension()->has_background_page()) {
588 process_ids.insert(host->render_process_host()->GetID());
589 }
590 }
591 }
592
593 if (process_ids.size() >
594 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
595 return true;
596 }
597
598 return false;
599}
600
[email protected]6f371442011-11-09 06:45:46601void ChromeContentBrowserClient::SiteInstanceGotProcess(
602 SiteInstance* site_instance) {
603 CHECK(site_instance->HasProcess());
604
605 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02606 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46607 ExtensionService* service = profile->GetExtensionService();
608 if (!service)
609 return;
610
611 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44612 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33613 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46614 if (!extension)
615 return;
616
[email protected]6bc04fd82011-12-04 02:29:35617 service->process_map()->Insert(extension->id(),
618 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33619 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46620 BrowserThread::PostTask(
621 BrowserThread::IO, FROM_HERE,
622 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24623 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46624 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35625 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33626 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46627}
628
629void ChromeContentBrowserClient::SiteInstanceDeleting(
630 SiteInstance* site_instance) {
631 if (!site_instance->HasProcess())
632 return;
633
634 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02635 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46636 ExtensionService* service = profile->GetExtensionService();
637 if (!service)
638 return;
639
640 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44641 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33642 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46643 if (!extension)
644 return;
645
[email protected]6bc04fd82011-12-04 02:29:35646 service->process_map()->Remove(extension->id(),
647 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33648 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46649 BrowserThread::PostTask(
650 BrowserThread::IO, FROM_HERE,
651 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]749d59a2012-04-05 00:23:24652 ExtensionSystem::Get(profile)->info_map(),
[email protected]6f371442011-11-09 06:45:46653 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35654 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33655 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46656}
657
[email protected]e3daf3c2011-10-05 21:17:08658bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
659 const GURL& current_url,
660 const GURL& new_url) {
661 if (current_url.is_empty()) {
662 // Always choose a new process when navigating to extension URLs. The
663 // process grouping logic will combine all of a given extension's pages
664 // into the same process.
665 if (new_url.SchemeIs(chrome::kExtensionScheme))
666 return true;
667
668 return false;
669 }
670
671 // Also, we must switch if one is an extension and the other is not the exact
672 // same extension.
673 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
674 new_url.SchemeIs(chrome::kExtensionScheme)) {
675 if (current_url.GetOrigin() != new_url.GetOrigin())
676 return true;
677 }
678
679 return false;
680}
681
[email protected]763ec4ca2011-04-29 15:48:12682std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
683 const std::string& alias_name) {
684 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
685}
686
[email protected]b80f68432011-05-02 17:22:30687void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
688 CommandLine* command_line, int child_process_id) {
689#if defined(USE_LINUX_BREAKPAD)
690 if (IsCrashReporterEnabled()) {
691 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
692 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
693 }
694#elif defined(OS_MACOSX)
695 if (IsCrashReporterEnabled()) {
696 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
697 child_process_logging::GetClientId());
698 }
699#endif // OS_MACOSX
700
[email protected]f1933792011-06-14 00:49:34701 if (logging::DialogsAreSuppressed())
702 command_line->AppendSwitch(switches::kNoErrorDialogs);
703
[email protected]b80f68432011-05-02 17:22:30704 std::string process_type =
705 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17706 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52707 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30708 FilePath user_data_dir =
709 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
710 if (!user_data_dir.empty())
711 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
712#if defined(OS_CHROMEOS)
713 const std::string& login_profile =
714 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
715 if (!login_profile.empty())
716 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
717#endif
718
[email protected]f3b1a082011-11-18 00:34:30719 content::RenderProcessHost* process =
720 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37721 if (process) {
722 Profile* profile = Profile::FromBrowserContext(
723 process->GetBrowserContext());
724 extensions::ProcessMap* process_map =
725 profile->GetExtensionService()->process_map();
726 if (process_map && process_map->Contains(process->GetID()))
727 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30728
[email protected]a8d851f82011-12-21 00:32:37729 PrefService* prefs = profile->GetPrefs();
730 // Currently this pref is only registered if applied via a policy.
731 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
732 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
733 // Turn this policy into a command line switch.
734 command_line->AppendSwitch(switches::kDisable3DAPIs);
735 }
[email protected]718eab62011-10-05 21:16:52736
[email protected]a8d851f82011-12-21 00:32:37737 // Disable client-side phishing detection in the renderer if it is
738 // disabled in the Profile preferences or the browser process.
739 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
740 !g_browser_process->safe_browsing_detection_service()) {
741 command_line->AppendSwitch(
742 switches::kDisableClientSidePhishingDetection);
743 }
[email protected]8c40da62011-07-13 22:58:46744 }
[email protected]47c7ec82012-01-18 03:29:21745 {
746 PrefService* local_state = g_browser_process->local_state();
747 if (local_state &&
748 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
749 command_line->AppendSwitch(switches::kRendererPrintPreview);
750 }
751 }
[email protected]4287a3d2011-06-13 23:56:51752
[email protected]47c7ec82012-01-18 03:29:21753 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51754 static const char* const kSwitchNames[] = {
755 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48756 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51757 switches::kAllowScriptingGallery,
758 switches::kAppsCheckoutURL,
759 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31760 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51761 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50762 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51763 switches::kDumpHistogramsOnExit,
[email protected]b7e44ff2012-02-16 03:37:34764 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21765 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13766 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51767 switches::kEnableCrxlessWebApps,
768 switches::kEnableExperimentalExtensionApis,
769 switches::kEnableInBrowserThumbnailing,
770 switches::kEnableIPCFuzzing,
771 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:48772 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53773 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51774 switches::kEnableWatchdog,
775 switches::kExperimentalSpellcheckerFeatures,
776 switches::kMemoryProfiling,
777 switches::kMessageLoopHistogrammer,
[email protected]f45c5f32012-04-18 19:26:37778 switches::kNoJsRandomness,
[email protected]2a6bb0b12011-10-05 19:18:04779 switches::kNoRunningInsecureContent,
[email protected]f45c5f32012-04-18 19:26:37780 switches::kPlaybackMode,
[email protected]4287a3d2011-06-13 23:56:51781 switches::kPpapiFlashArgs,
782 switches::kPpapiFlashInProcess,
783 switches::kPpapiFlashPath,
784 switches::kPpapiFlashVersion,
785 switches::kProfilingAtStart,
786 switches::kProfilingFile,
787 switches::kProfilingFlush,
[email protected]f45c5f32012-04-18 19:26:37788 switches::kRecordMode,
[email protected]4287a3d2011-06-13 23:56:51789 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38790 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51791 };
792
793 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
794 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17795 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38796 static const char* const kSwitchNames[] = {
797 switches::kEnableExperimentalExtensionApis,
[email protected]ee14cad2012-03-29 01:59:37798 switches::kEnablePlatformApps,
[email protected]a446534d2012-02-09 00:07:38799 switches::kWhitelistedExtensionID,
800 };
801
802 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
803 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51804 } else if (process_type == switches::kPluginProcess) {
805 static const char* const kSwitchNames[] = {
806 #if defined(OS_CHROMEOS)
807 switches::kLoginProfile,
808 #endif
809 switches::kMemoryProfiling,
810 switches::kSilentDumpOnDCHECK,
811 switches::kUserDataDir,
812 };
813
814 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
815 arraysize(kSwitchNames));
816 } else if (process_type == switches::kZygoteProcess) {
817 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51818 switches::kUserDataDir, // Make logs go to the right file.
819 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50820 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13821 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51822 switches::kPpapiFlashInProcess,
823 switches::kPpapiFlashPath,
824 switches::kPpapiFlashVersion,
825 };
826
827 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
828 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11829 } else if (process_type == switches::kGpuProcess) {
830 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
831 // because GPU is expected to be unreliable.
832 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
833 !command_line->HasSwitch(switches::kDisableBreakpad))
834 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30835 }
[email protected]6f08af82011-09-15 01:19:03836
837 // The command line switch kEnableBenchmarking needs to be specified along
838 // with the kEnableStatsTable switch to ensure that the stats table global
839 // is initialized correctly.
840 if (command_line->HasSwitch(switches::kEnableBenchmarking))
841 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30842}
843
844std::string ChromeContentBrowserClient::GetApplicationLocale() {
845 return g_browser_process->GetApplicationLocale();
846}
847
[email protected]597a867b2011-11-18 18:31:20848std::string ChromeContentBrowserClient::GetAcceptLangs(
849 content::BrowserContext* context) {
850 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37851 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08852}
853
[email protected]ac55e292011-06-24 05:16:08854SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22855 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08856 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
857}
858
[email protected]a2176792011-05-08 19:30:49859bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09860 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19861 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20862 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32863 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20864 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05865 return io_data->GetCookieSettings()->
866 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49867}
868
[email protected]ed24fad2011-05-10 22:44:01869bool ChromeContentBrowserClient::AllowGetCookie(
870 const GURL& url,
871 const GURL& first_party,
872 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20873 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01874 int render_process_id,
875 int render_view_id) {
876 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20877 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05878 bool allow = io_data->GetCookieSettings()->
879 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01880
[email protected]8093a542011-05-13 07:29:32881 BrowserThread::PostTask(
882 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03883 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
[email protected]fd473d12012-04-05 11:38:43884 render_view_id, url, first_party, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01885 return allow;
886}
887
888bool ChromeContentBrowserClient::AllowSetCookie(
889 const GURL& url,
890 const GURL& first_party,
891 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20892 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01893 int render_process_id,
894 int render_view_id,
895 net::CookieOptions* options) {
896 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20897 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05898 CookieSettings* cookie_settings = io_data->GetCookieSettings();
899 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
900
901 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09902 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01903
[email protected]8093a542011-05-13 07:29:32904 BrowserThread::PostTask(
905 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03906 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
[email protected]fd473d12012-04-05 11:38:43907 render_view_id, url, first_party, cookie_line, *options,
908 !allow));
[email protected]ed24fad2011-05-10 22:44:01909 return allow;
910}
911
[email protected]d5a19162011-06-30 18:51:54912bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20913 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54914 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20915 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26916
[email protected]f24bd172012-03-31 01:54:59917 return !io_data->clear_local_state_on_exit()->GetValue();
[email protected]d5a19162011-06-30 18:51:54918}
919
[email protected]5c5a88e2011-11-12 00:45:35920bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35921 const GURL& url,
922 const string16& name,
923 const string16& display_name,
924 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20925 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48926 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35927 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20928 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35929 CookieSettings* cookie_settings = io_data->GetCookieSettings();
930 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
931
[email protected]62151052012-02-01 18:40:48932 // Record access to database for potential display in UI.
933 std::vector<std::pair<int, int> >::const_iterator i;
934 for (i = render_views.begin(); i != render_views.end(); ++i) {
935 BrowserThread::PostTask(
936 BrowserThread::UI, FROM_HERE,
937 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
938 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35939 }
940
941 return allow;
942}
943
944bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35945 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20946 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48947 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20949 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35950 CookieSettings* cookie_settings = io_data->GetCookieSettings();
951 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
952
[email protected]62151052012-02-01 18:40:48953 // Record access to file system for potential display in UI.
954 std::vector<std::pair<int, int> >::const_iterator i;
955 for (i = render_views.begin(); i != render_views.end(); ++i) {
956 BrowserThread::PostTask(
957 BrowserThread::UI, FROM_HERE,
958 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
959 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35960 }
961
962 return allow;
963}
964
[email protected]7c5ff9a2012-03-02 07:42:49965bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
966 const GURL& url,
967 const string16& name,
968 content::ResourceContext* context,
969 const std::vector<std::pair<int, int> >& render_views) {
970 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
971 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
972 CookieSettings* cookie_settings = io_data->GetCookieSettings();
973 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
974
975 // Record access to IndexedDB for potential display in UI.
976 std::vector<std::pair<int, int> >::const_iterator i;
977 for (i = render_views.begin(); i != render_views.end(); ++i) {
978 BrowserThread::PostTask(
979 BrowserThread::UI, FROM_HERE,
980 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
981 i->first, i->second, url, name, !allow));
982 }
983
984 return allow;
985}
986
[email protected]6133f922011-07-01 21:34:34987net::URLRequestContext*
988ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20989 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34990 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
991 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20992 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34993 return io_data->extensions_request_context();
994 }
995
996 return NULL;
997}
998
[email protected]317f96c92011-05-31 06:53:41999QuotaPermissionContext*
1000ChromeContentBrowserClient::CreateQuotaPermissionContext() {
1001 return new ChromeQuotaPermissionContext();
1002}
1003
[email protected]a0ce3282011-08-19 20:49:521004void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:421005 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:421006}
1007
[email protected]a0ce3282011-08-19 20:49:521008void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:521009 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:521010}
1011
[email protected]848dd042011-06-04 18:24:031012void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:171013 int render_process_id,
1014 int render_view_id,
1015 int cert_error,
1016 const net::SSLInfo& ssl_info,
1017 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:031018 bool overridable,
[email protected]4cf611e32012-02-13 16:06:171019 const base::Callback<void(bool)>& callback,
1020 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411021 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131022 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171023 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411024 if (!tab) {
1025 NOTREACHED();
1026 return;
1027 }
1028 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501029 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301030 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091031 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411032 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171033 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411034 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171035 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411036 return;
1037 }
1038 }
1039
1040 // Otherwise, display an SSL blocking page.
[email protected]4cf611e32012-02-13 16:06:171041 new SSLBlockingPage(
1042 tab, cert_error, ssl_info, request_url, overridable, callback);
[email protected]848dd042011-06-04 18:24:031043}
1044
[email protected]c99c442e2011-08-24 11:37:301045void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451046 int render_process_id,
1047 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401048 const net::HttpNetworkSession* network_session,
1049 net::SSLCertRequestInfo* cert_request_info,
1050 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131051 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451052 render_process_id, render_view_id);
1053 if (!tab) {
1054 NOTREACHED();
1055 return;
1056 }
1057
[email protected]6786bf402011-12-03 15:19:451058 GURL requesting_url("https://" + cert_request_info->host_and_port);
1059 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1060 << cert_request_info->host_and_port;
1061
[email protected]627e0512011-12-21 22:55:301062 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451063 scoped_ptr<Value> filter(
1064 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1065 requesting_url,
1066 requesting_url,
1067 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1068 std::string(), NULL));
1069
1070 if (filter.get()) {
1071 // Try to automatically select a client certificate.
1072 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1073 DictionaryValue* filter_dict =
1074 static_cast<DictionaryValue*>(filter.get());
1075
1076 const std::vector<scoped_refptr<net::X509Certificate> >&
1077 all_client_certs = cert_request_info->client_certs;
1078 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1079 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1080 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401081 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451082 return;
1083 }
1084 }
1085 } else {
1086 NOTREACHED();
1087 }
1088 }
1089
[email protected]8ec26472011-06-06 16:52:451090 TabContentsWrapper* wrapper =
1091 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451092 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131093 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451094 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141095 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401096 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451097 return;
1098 }
[email protected]7a593db2012-02-13 21:19:401099 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1100 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451101}
1102
1103void ChromeContentBrowserClient::AddNewCertificate(
1104 net::URLRequest* request,
1105 net::X509Certificate* cert,
1106 int render_process_id,
1107 int render_view_id) {
1108 // The handler will run the UI and delete itself when it's finished.
1109 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1110}
1111
[email protected]a93670ab2012-02-24 03:46:391112void ChromeContentBrowserClient::RequestMediaAccessPermission(
1113 const content::MediaStreamRequest* request,
1114 const content::MediaResponseCallback& callback) {
1115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1116
[email protected]117b6b42012-02-29 09:11:081117 WebContents* contents = tab_util::GetWebContentsByID(
1118 request->render_process_id, request->render_view_id);
1119 if (!contents) {
1120 // Abort, if the tab was closed after the request was made but before we
1121 // got to this point.
1122 callback.Run(content::MediaStreamDevices());
1123 return;
1124 }
1125
1126 TabContentsWrapper* tab =
1127 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1128 DCHECK(tab);
1129
1130 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1131 InfoBarDelegate* old_infobar = NULL;
1132 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1133 old_infobar =
1134 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfobarDelegate();
1135 }
1136
[email protected]3bc518b2012-03-09 03:01:501137#if defined(TOOLKIT_VIEWS) || defined(OS_LINUX)
[email protected]117b6b42012-02-29 09:11:081138 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1139 request,
1140 callback);
1141 if (old_infobar)
1142 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1143 else
1144 infobar_helper->AddInfoBar(infobar);
[email protected]3bc518b2012-03-09 03:01:501145#elif defined(OS_MACOSX)
1146 // TODO(macourteau): UI is not implemented yet for OS X. Fallback to
[email protected]117b6b42012-02-29 09:11:081147 // the default behaviour and allow access to the first device of each
1148 // requested type.
1149 content::MediaStreamDevices devices;
[email protected]a93670ab2012-02-24 03:46:391150 for (content::MediaStreamDeviceMap::const_iterator it =
1151 request->devices.begin(); it != request->devices.end(); ++it) {
[email protected]6c6415a2012-03-01 17:17:281152 if (!it->second.empty())
1153 devices.push_back(*it->second.begin());
[email protected]a93670ab2012-02-24 03:46:391154 }
1155
[email protected]a93670ab2012-02-24 03:46:391156 callback.Run(devices);
[email protected]3bc518b2012-03-09 03:01:501157#endif // TOOLKIT_VIEWS || OS_LINUX
[email protected]a93670ab2012-02-24 03:46:391158}
1159
[email protected]dc73a7b2012-03-25 15:27:181160content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() {
1161 return MediaInternals::GetInstance();
1162}
1163
[email protected]941623e2011-06-07 23:06:041164void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1165 const GURL& source_origin,
1166 int callback_context,
1167 int render_process_id,
1168 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111169#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041170 RenderViewHost* rvh = RenderViewHost::FromID(
1171 render_process_id, render_view_id);
1172 if (!rvh) {
1173 NOTREACHED();
1174 return;
1175 }
1176
[email protected]9f76c1e2012-03-05 15:15:581177 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301178 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041179 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371180 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041181 service->RequestPermission(
1182 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131183 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111184#else
1185 NOTIMPLEMENTED();
1186#endif
[email protected]941623e2011-06-07 23:06:041187}
1188
1189WebKit::WebNotificationPresenter::Permission
1190 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021191 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201192 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021193 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111194#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201196 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021197 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1198 source_origin, render_process_id,
1199 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041200 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041201
1202 // Fall back to the regular notification preferences, which works on an
1203 // origin basis.
1204 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371205 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041206 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111207#else
1208 return WebKit::WebNotificationPresenter::PermissionAllowed;
1209#endif
[email protected]941623e2011-06-07 23:06:041210}
1211
1212void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171213 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041214 int render_process_id,
1215 int render_view_id,
1216 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111217#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041218 RenderViewHost* rvh = RenderViewHost::FromID(
1219 render_process_id, render_view_id);
1220 if (!rvh) {
1221 NOTREACHED();
1222 return;
1223 }
1224
[email protected]9f76c1e2012-03-05 15:15:581225 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301226 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041227 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371228 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041229 service->ShowDesktopNotification(
1230 params, render_process_id, render_view_id,
1231 worker ? DesktopNotificationService::WorkerNotification :
1232 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111233#else
1234 NOTIMPLEMENTED();
1235#endif
[email protected]941623e2011-06-07 23:06:041236}
1237
1238void ChromeContentBrowserClient::CancelDesktopNotification(
1239 int render_process_id,
1240 int render_view_id,
1241 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111242#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041243 RenderViewHost* rvh = RenderViewHost::FromID(
1244 render_process_id, render_view_id);
1245 if (!rvh) {
1246 NOTREACHED();
1247 return;
1248 }
1249
[email protected]9f76c1e2012-03-05 15:15:581250 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301251 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041252 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371253 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041254 service->CancelDesktopNotification(
1255 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111256#else
1257 NOTIMPLEMENTED();
1258#endif
[email protected]941623e2011-06-07 23:06:041259}
1260
[email protected]9f3fba52011-06-08 20:37:191261bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351262 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021263 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191264 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201265 content::ResourceContext* context,
[email protected]03b6d552012-03-29 04:03:011266 int render_process_id,
1267 bool* no_javascript_access) {
[email protected]9f3fba52011-06-08 20:37:191268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]03b6d552012-03-29 04:03:011269
1270 *no_javascript_access = false;
1271
[email protected]9f3fba52011-06-08 20:37:191272 // If the opener is trying to create a background window but doesn't have
1273 // the appropriate permission, fail the attempt.
1274 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201275 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531276 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1277
[email protected]03b6d552012-03-29 04:03:011278 if (!map->SecurityOriginHasAPIPermission(
1279 source_origin,
1280 render_process_id,
1281 ExtensionAPIPermission::kBackground)) {
1282 return false;
1283 }
1284
[email protected]7b54ca02012-03-02 18:06:531285 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1286 // return a recently installed Extension even if this CanCreateWindow call
1287 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]03b6d552012-03-29 04:03:011288 // because the permission check above would have caused an early return
1289 // already. We must use the full URL to find hosted apps, though, and not
1290 // just the origin.
[email protected]7b54ca02012-03-02 18:06:531291 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351292 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531293 if (extension && !extension->allow_background_js_access())
[email protected]03b6d552012-03-29 04:03:011294 *no_javascript_access = true;
[email protected]9f3fba52011-06-08 20:37:191295 }
1296 return true;
1297}
1298
1299std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201300 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1302 // Check if it's an extension-created worker, in which case we want to use
1303 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201304 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191305 const Extension* extension =
1306 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1307 return extension ? extension->name() : std::string();
1308}
1309
[email protected]99907362012-01-11 05:41:401310void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1311 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171312}
1313
[email protected]c52b2892012-03-07 11:01:021314content::SpeechRecognitionManagerDelegate*
1315 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
[email protected]a03f2d32012-03-14 00:26:321316#if defined(ENABLE_INPUT_SPEECH)
[email protected]c52b2892012-03-07 11:01:021317 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]a03f2d32012-03-14 00:26:321318#else
1319 return NULL;
1320#endif
[email protected]66cfec62012-02-24 17:57:511321}
1322
[email protected]3cb054e62011-06-13 05:21:171323ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1324 return g_browser_process->clipboard();
1325}
1326
[email protected]ae6e9912011-07-27 01:18:281327net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1328 return g_browser_process->net_log();
1329}
1330
[email protected]32538d92011-08-25 00:09:231331AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1332 return new ChromeAccessTokenStore();
1333}
1334
[email protected]dbae6b02011-06-29 23:51:411335bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1336 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1337 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1338}
1339
[email protected]64d69de42012-02-06 00:19:541340void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321341 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061342 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581343 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061344 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061345
[email protected]64d69de42012-02-06 00:19:541346 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061347 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541348 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061349 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541350 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061351 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541352 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061353 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541354 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061355 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541356 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061357 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1358
1359 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541360 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061361 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541362 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061363 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541364 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061365 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541366 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061367 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541368 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061369 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541370 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061371
[email protected]64d69de42012-02-06 00:19:541372 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061373 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541374 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061375 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541376 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061377 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541378 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061379 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1380
[email protected]64d69de42012-02-06 00:19:541381 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061382
[email protected]64d69de42012-02-06 00:19:541383 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061384 prefs->GetBoolean(
1385 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541386 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061387 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541388 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061389 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1390 const DictionaryValue* inspector_settings =
1391 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1392 if (inspector_settings) {
1393 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1394 iter != inspector_settings->end_keys(); ++iter) {
1395 std::string value;
1396 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541397 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061398 std::make_pair(*iter, value));
1399 }
1400 }
[email protected]64d69de42012-02-06 00:19:541401 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061402
[email protected]64d69de42012-02-06 00:19:541403 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1404 web_prefs->javascript_enabled = false;
1405 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1406 web_prefs->web_security_enabled = false;
1407 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1408 web_prefs->plugins_enabled = false;
1409 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1410 web_prefs->java_enabled = false;
1411 web_prefs->loads_images_automatically =
1412 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061413
[email protected]64d69de42012-02-06 00:19:541414 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1415 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061416
[email protected]64d69de42012-02-06 00:19:541417 web_prefs->memory_info_enabled =
1418 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1419 web_prefs->allow_displaying_insecure_content =
1420 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1421 web_prefs->allow_running_insecure_content =
1422 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081423 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061424
[email protected]64d69de42012-02-06 00:19:541425 // The user stylesheet watcher may not exist in a testing profile.
[email protected]13169ab2012-04-06 07:48:151426 UserStyleSheetWatcher* user_style_sheet_watcher =
1427 UserStyleSheetWatcherFactory::GetForProfile(profile);
1428 if (user_style_sheet_watcher) {
[email protected]64d69de42012-02-06 00:19:541429 web_prefs->user_style_sheet_enabled = true;
1430 web_prefs->user_style_sheet_location =
[email protected]13169ab2012-04-06 07:48:151431 user_style_sheet_watcher->user_style_sheet();
[email protected]64d69de42012-02-06 00:19:541432 } else {
1433 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061434 }
1435
[email protected]b7e44ff2012-02-16 03:37:341436 web_prefs->asynchronous_spell_checking_enabled =
1437 CommandLine::ForCurrentProcess()->
1438 HasSwitch(switches::kEnableAsynchronousSpellChecking);
1439 web_prefs->unified_textchecker_enabled =
1440 web_prefs->asynchronous_spell_checking_enabled ||
1441 CommandLine::ForCurrentProcess()->
1442 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571443
[email protected]64d69de42012-02-06 00:19:541444 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061445 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541446 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061447 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541448 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061449 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1450
1451 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541452 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061453 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541454 web_prefs->default_encoding);
1455 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061456 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541457 web_prefs->default_encoding =
1458 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061459 }
[email protected]64d69de42012-02-06 00:19:541460 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061461
1462 ExtensionService* service = profile->GetExtensionService();
1463 if (service) {
1464 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581465 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061466 extension_webkit_preferences::SetPreferences(
[email protected]9f76c1e2012-03-05 15:15:581467 extension, rvh->GetDelegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061468 }
1469
[email protected]9f76c1e2012-03-05 15:15:581470 if (rvh->GetDelegate()->GetRenderViewType() ==
1471 chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541472 web_prefs->allow_scripts_to_close_windows = true;
[email protected]9f76c1e2012-03-05 15:15:581473 } else if (rvh->GetDelegate()->GetRenderViewType() ==
[email protected]f3986f82012-01-03 20:00:061474 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1475 // Disable all kinds of acceleration for background pages.
1476 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541477 web_prefs->force_compositing_mode = false;
1478 web_prefs->accelerated_compositing_enabled = false;
1479 web_prefs->accelerated_2d_canvas_enabled = false;
1480 web_prefs->accelerated_video_enabled = false;
1481 web_prefs->accelerated_painting_enabled = false;
1482 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061483 }
[email protected]2e21fe292012-03-02 22:52:321484
1485#if defined(FILE_MANAGER_EXTENSION)
1486 // Override the default of suppressing HW compositing for WebUI pages for the
1487 // file manager, which is implemented using WebUI but wants HW acceleration
1488 // for video decode & render.
1489 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1490 web_prefs->accelerated_compositing_enabled = true;
1491 web_prefs->accelerated_2d_canvas_enabled = true;
1492 }
1493#endif
[email protected]181a95ee2011-07-12 19:26:361494}
1495
1496void ChromeContentBrowserClient::UpdateInspectorSetting(
1497 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061498 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581499 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061500 DictionaryPrefUpdate update(
1501 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1502 prefs::kWebKitInspectorSettings);
1503 DictionaryValue* inspector_settings = update.Get();
1504 inspector_settings->SetWithoutPathExpansion(key,
1505 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361506}
1507
1508void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061509 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581510 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061511 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1512 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361513}
1514
[email protected]b8148ac2011-07-13 22:03:251515void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1516 BrowserURLHandler* handler) {
1517 // Add the default URL handlers.
1518 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1519 BrowserURLHandler::null_handler());
1520 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1521 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1522
[email protected]b3adbd02011-11-30 22:23:271523 // about: handler. Must come before chrome: handler, since it will
1524 // rewrite about: urls to chrome: URLs and then expect chrome: to
1525 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251526 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1527 BrowserURLHandler::null_handler());
1528 // chrome: & friends.
1529 handler->AddHandlerPair(&HandleWebUI,
1530 BrowserURLHandler::null_handler());
1531}
1532
1533void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371534 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581535 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251536 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1537 BrowsingDataRemover::EVERYTHING,
1538 base::Time());
1539 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1540 // BrowsingDataRemover takes care of deleting itself when done.
1541}
1542
1543void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371544 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581545 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251546 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1547 BrowsingDataRemover::EVERYTHING,
1548 base::Time());
[email protected]dceaa912011-09-06 17:17:231549 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251550 remover->Remove(remove_mask);
1551 // BrowsingDataRemover takes care of deleting itself when done.
1552}
1553
[email protected]e1d16eb92011-08-18 23:19:321554FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1555 return download_util::GetDefaultDownloadDirectory();
1556}
1557
[email protected]c9b6eb62011-10-18 20:49:391558std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1559 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1560}
1561
[email protected]a658d452012-03-02 12:45:291562bool ChromeContentBrowserClient::AllowSocketAPI(
1563 content::BrowserContext* browser_context, const GURL& url) {
1564 if (!url.is_valid())
1565 return false;
1566
1567 std::string host = url.host();
1568 if (allowed_socket_origins_.count(host))
1569 return true;
1570
[email protected]f237c0f2012-03-10 07:49:101571 // Need to check this now and not on construction because otherwise it won't
1572 // work with browser_tests.
1573 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1574 std::string allowed_list =
1575 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
1576 if (!allowed_list.empty()) {
1577 StringTokenizer t(allowed_list, ",");
1578 while (t.GetNext()) {
1579 if (t.token() == host)
1580 return true;
1581 }
1582 }
1583
[email protected]a658d452012-03-02 12:45:291584 Profile* profile = Profile::FromBrowserContext(browser_context);
1585 if (!profile || !profile->GetExtensionService())
1586 return false;
1587
1588 const Extension* extension = profile->GetExtensionService()->extensions()->
1589 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1590 if (!extension)
1591 return false;
1592
1593 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1594 return true;
1595
1596 return false;
[email protected]e461da2f2012-02-16 19:06:401597}
1598
[email protected]e60c0232011-11-11 19:56:351599#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301600int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521601 const CommandLine& command_line) {
1602 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071603 ExtensionCrashHandlerHostLinux* crash_handler =
1604 ExtensionCrashHandlerHostLinux::GetInstance();
1605 return crash_handler->GetDeathSignalSocket();
1606 }
1607
[email protected]718eab62011-10-05 21:16:521608 std::string process_type =
1609 command_line.GetSwitchValueASCII(switches::kProcessType);
1610
1611 if (process_type == switches::kRendererProcess)
1612 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1613
[email protected]b80f68432011-05-02 17:22:301614 if (process_type == switches::kPluginProcess)
1615 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1616
1617 if (process_type == switches::kPpapiPluginProcess)
1618 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1619
1620 if (process_type == switches::kGpuProcess)
1621 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1622
1623 return -1;
1624}
[email protected]e60c0232011-11-11 19:56:351625#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301626
[email protected]4a65826d2011-08-25 16:04:011627#if defined(OS_WIN)
1628const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1629 return chrome::kBrowserResourcesDll;
1630}
1631#endif
1632
[email protected]37a72af2011-06-13 05:42:011633#if defined(USE_NSS)
1634crypto::CryptoModuleBlockingPasswordDelegate*
1635 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1636 const GURL& url) {
1637 return browser::NewCryptoModuleBlockingDialogDelegate(
1638 browser::kCryptoModulePasswordKeygen, url.host());
1639}
1640#endif
1641
[email protected]d977f9c2011-03-14 16:10:261642} // namespace chrome