blob: ed827c59df6ef2ece96a46d8538bd75216313286 [file] [log] [blame]
[email protected]f3986f82012-01-03 20:00:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d977f9c2011-03-14 16:10:262// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]7c3228a2011-11-11 21:35:227#include <set>
[email protected]1033acd2012-02-08 08:46:278#include <utility>
[email protected]7c3228a2011-11-11 21:35:229#include <vector>
10
[email protected]317c58f02011-11-09 02:15:0311#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3012#include "base/command_line.h"
[email protected]e461da2f2012-02-16 19:06:4013#include "base/string_tokenizer.h"
[email protected]f3986f82012-01-03 20:00:0614#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3015#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2516#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3017#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2318#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1219#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0320#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4121#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5622#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0523#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4524#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3225#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]9d06d88d2012-02-23 22:37:0826#include "chrome/browser/defaults.h"
[email protected]e1d16eb92011-08-18 23:19:3227#include "chrome/browser/download/download_util.h"
[email protected]6e672df2012-01-25 10:39:4728#include "chrome/browser/extensions/api/webrequest/webrequest_api.h"
[email protected]76411f412012-02-22 18:56:0629#include "chrome/browser/extensions/extension_host.h"
[email protected]941623e2011-06-07 23:06:0430#include "chrome/browser/extensions/extension_info_map.h"
[email protected]76411f412012-02-22 18:56:0631#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]f364d1392011-04-08 21:03:1032#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2633#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2534#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0635#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]32538d92011-08-25 00:09:2336#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1237#include "chrome/browser/google/google_util.h"
[email protected]117b6b42012-02-29 09:11:0838#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]ae6e9912011-07-27 01:18:2839#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0440#include "chrome/browser/notifications/desktop_notification_service.h"
41#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4242#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1243#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0644#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4145#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5046#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4147#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1448#include "chrome/browser/printing/printing_message_filter.h"
49#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3250#include "chrome/browser/profiles/profile_io_data.h"
[email protected]76411f412012-02-22 18:56:0651#include "chrome/browser/profiles/profile_manager.h"
[email protected]05fcf982011-04-19 00:44:1452#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3353#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4254#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1455#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]66cfec62012-02-24 17:57:5156#include "chrome/browser/speech/chrome_speech_input_manager_delegate.h"
[email protected]8ec71262011-07-28 08:12:4657#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4558#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0359#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4560#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
61#include "chrome/browser/tab_contents/tab_util.h"
[email protected]117b6b42012-02-29 09:11:0862#include "chrome/browser/ui/media_stream_infobar_delegate.h"
[email protected]8ec26472011-06-06 16:52:4563#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]863f70a2012-01-27 02:05:5064#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
[email protected]f3986f82012-01-03 20:00:0665#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]b80f68432011-05-02 17:22:3066#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0167#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3068#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0469#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4470#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3471#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1272#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3873#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0974#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2575#include "content/browser/browser_url_handler.h"
[email protected]d977f9c2011-03-14 16:10:2676#include "content/browser/renderer_host/render_view_host.h"
[email protected]b48c9182011-10-26 18:03:3077#include "content/public/browser/browser_main_parts.h"
[email protected]b9535422012-02-09 01:47:5978#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3079#include "content/public/browser/render_process_host.h"
[email protected]ce967862012-02-09 22:47:0580#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3381#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1982#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1083#include "content/public/browser/web_contents_view.h"
[email protected]c9b6eb62011-10-18 20:49:3984#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3485#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0186#include "net/base/cookie_monster.h"
87#include "net/base/cookie_options.h"
[email protected]7a593db2012-02-13 21:19:4088#include "net/base/ssl_cert_request_info.h"
[email protected]c9b6eb62011-10-18 20:49:3989#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0890#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3691#include "webkit/glue/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:2692
[email protected]b48c9182011-10-26 18:03:3093#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3894#include "chrome/browser/chrome_browser_main_win.h"
95#elif defined(OS_MACOSX)
96#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:5697#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:3098#elif defined(OS_CHROMEOS)
99#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]e60c0232011-11-11 19:56:35100#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:30101#include "chrome/browser/chrome_browser_main_linux.h"
102#elif defined(OS_POSIX)
103#include "chrome/browser/chrome_browser_main_posix.h"
104#endif
105
[email protected]b48c9182011-10-26 18:03:30106#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31107#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38108#endif
109
[email protected]c7480942011-11-08 19:18:27110#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31111#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27112#endif
113
114#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31115#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
116#endif
117
[email protected]e60c0232011-11-11 19:56:35118#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30119#include "base/linux_util.h"
120#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43121#endif
[email protected]b80f68432011-05-02 17:22:30122
[email protected]080f34f2011-09-20 05:39:26123#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32124#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21125#elif defined(TOOLKIT_USES_GTK)
[email protected]1c05b7c2012-03-02 18:53:43126#include "chrome/browser/tab_contents/chrome_web_contents_view_gtk_delegate.h"
[email protected]90580422012-01-12 00:26:22127#include "content/browser/tab_contents/tab_contents_view_gtk.h"
[email protected]74313b42011-08-24 16:51:32128#elif defined(OS_MACOSX)
[email protected]cce3ab72012-02-04 18:05:16129#include "chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.h"
[email protected]eb668c92012-02-06 15:35:29130#include "content/browser/tab_contents/web_contents_view_mac.h"
[email protected]6e677a342012-02-11 01:21:14131#elif defined(OS_ANDROID)
[email protected]82c9f44b2012-02-14 21:02:52132#include "content/browser/tab_contents/web_contents_view_android.h"
[email protected]74313b42011-08-24 16:51:32133#endif
134
[email protected]37a72af2011-06-13 05:42:01135#if defined(USE_NSS)
136#include "chrome/browser/ui/crypto_module_password_dialog.h"
137#endif
138
[email protected]c8c77182011-12-21 15:04:47139using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39140using content::BrowserThread;
[email protected]b9535422012-02-09 01:47:59141using content::ChildProcessSecurityPolicy;
[email protected]9f9749a2012-03-02 19:37:00142using content::QuotaPermissionContext;
[email protected]b6583592012-01-25 19:52:33143using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13144using content::WebContents;
[email protected]631bb742011-11-02 11:29:39145
[email protected]c5dbef02011-05-13 05:06:09146namespace {
147
[email protected]e461da2f2012-02-16 19:06:40148const char* kPredefinedAllowedSocketOrigins[] = {
149 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
150 "pnhechapfaindjhompbnflcldabbghjo" // HTerm App (SSH Client)
151};
152
[email protected]b8148ac2011-07-13 22:03:25153// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42154bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50155 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
156 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25157 return false;
158
159 // Special case the new tab page. In older versions of Chrome, the new tab
160 // page was hosted at chrome-internal:<blah>. This might be in people's saved
161 // sessions or bookmarks, so we say any URL with that scheme triggers the new
162 // tab page.
163 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
164 // Rewrite it with the proper new tab URL.
165 *url = GURL(chrome::kChromeUINewTabURL);
166 }
167
168 return true;
169}
170
[email protected]8d3132f62011-10-12 07:13:42171// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
172// below. Extension, and isolated apps require different privileges to be
173// granted to their RenderProcessHosts. This classification allows us to make
174// sure URLs are served by hosts with the right set of privileges.
175enum RenderProcessHostPrivilege {
176 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45177 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42178 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45179 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42180};
181
182RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
183 const GURL& url,
184 ExtensionService* service) {
185 // Default to a normal renderer cause it is lower privileged. This should only
186 // occur if the URL on a site instance is either malformed, or uninitialized.
187 // If it is malformed, then there is no need for better privileges anyways.
188 // If it is uninitialized, but eventually settles on being an a scheme other
189 // than normal webrenderer, the navigation logic will correct us out of band
190 // anyways.
191 if (!url.is_valid())
192 return PRIV_NORMAL;
193
194 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44195 const Extension* extension =
196 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45197 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42198 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45199 if (extension && extension->is_hosted_app())
200 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42201
202 return PRIV_EXTENSION;
203 }
204
205 return PRIV_NORMAL;
206}
207
208RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30209 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46210 extensions::ProcessMap* process_map,
211 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46212 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30213 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46214 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21215 return PRIV_NORMAL;
216
[email protected]6f371442011-11-09 06:45:46217 for (std::set<std::string>::iterator iter = extension_ids.begin();
218 iter != extension_ids.end(); ++iter) {
219 const Extension* extension = service->GetExtensionById(*iter, false);
220 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42221 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45222 if (extension && extension->is_hosted_app())
223 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42224 }
225
[email protected]676f6ab2011-10-19 20:23:21226 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42227}
228
[email protected]eec0b33c2011-12-05 22:09:45229bool IsIsolatedAppInProcess(const GURL& site_url,
230 content::RenderProcessHost* process_host,
231 extensions::ProcessMap* process_map,
232 ExtensionService* service) {
233 std::set<std::string> extension_ids =
234 process_map->GetExtensionsInProcess(process_host->GetID());
235 if (extension_ids.empty())
236 return false;
237
238 for (std::set<std::string>::iterator iter = extension_ids.begin();
239 iter != extension_ids.end(); ++iter) {
240 const Extension* extension = service->GetExtensionById(*iter, false);
241 if (extension &&
242 extension->is_storage_isolated() &&
243 extension->url() == site_url)
244 return true;
245 }
246
247 return false;
248}
249
[email protected]6786bf402011-12-03 15:19:45250bool CertMatchesFilter(const net::X509Certificate& cert,
251 const base::DictionaryValue& filter) {
252 // TODO(markusheintz): This is the minimal required filter implementation.
253 // Implement a better matcher.
254
255 // An empty filter matches any client certificate since no requirements are
256 // specified at all.
257 if (filter.empty())
258 return true;
259
260 std::string common_name;
261 if (filter.GetString("ISSUER.CN", &common_name) &&
262 (cert.issuer().common_name == common_name)) {
263 return true;
264 }
265 return false;
266}
267
[email protected]f3986f82012-01-03 20:00:06268// Fills |map| with the per-script font prefs under path |map_name|.
269void FillFontFamilyMap(const PrefService* prefs,
270 const char* map_name,
271 WebPreferences::ScriptFontFamilyMap* map) {
272 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
273 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
274 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
275 std::string font_family = prefs->GetString(pref_name.c_str());
276 if (!font_family.empty())
277 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
278 }
279}
280
[email protected]9dbfff12011-07-01 19:37:07281} // namespace
[email protected]c5dbef02011-05-13 05:06:09282
[email protected]d977f9c2011-03-14 16:10:26283namespace chrome {
284
[email protected]e461da2f2012-02-16 19:06:40285ChromeContentBrowserClient::ChromeContentBrowserClient() {
286 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
287 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
288
289 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
290 std::string allowed_list =
291 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
292 if (!allowed_list.empty()) {
293 StringTokenizer t(allowed_list, ",");
294 while (t.GetNext()) {
295 allowed_socket_origins_.insert(t.token());
296 }
297 }
298}
299
300ChromeContentBrowserClient::~ChromeContentBrowserClient() {
301}
302
[email protected]50462bf02011-11-21 19:13:31303content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
304 const content::MainFunctionParams& parameters) {
305 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30306 // Construct the Main browser parts based on the OS type.
307#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31308 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04309#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31310 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30311#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31312 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35313#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31314 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14315#elif defined(OS_ANDROID)
316 // Do nothing for Android.
317 // TODO(klobag): Android initialization should use the
318 // *BrowserMainParts class-hierarchy for setting up custom initialization.
319 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30320#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31321 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04322#else
[email protected]b48c9182011-10-26 18:03:30323 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31324 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30325#endif
326
[email protected]c7480942011-11-08 19:18:27327 // Construct additional browser parts. Stages are called in the order in
328 // which they are added.
[email protected]b48c9182011-10-26 18:03:30329#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31330 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04331#endif
[email protected]c7480942011-11-08 19:18:27332
333#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31334 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27335#endif
336
337#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31338 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27339#endif
340
[email protected]50462bf02011-11-21 19:13:31341 return main_parts;
[email protected]f967b722011-09-07 00:58:04342}
343
[email protected]8643e6d2012-01-18 20:26:10344content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView(
[email protected]8dad546b2012-01-17 21:47:35345 WebContents* web_contents) {
[email protected]080f34f2011-09-20 05:39:26346#if defined(TOOLKIT_VIEWS)
[email protected]8dad546b2012-01-17 21:47:35347 return new TabContentsViewViews(web_contents);
[email protected]c92f4ed2011-10-21 19:50:21348#elif defined(TOOLKIT_USES_GTK)
[email protected]8dad546b2012-01-17 21:47:35349 return new content::TabContentsViewGtk(web_contents,
[email protected]1c05b7c2012-03-02 18:53:43350 new ChromeWebContentsViewGtkDelegate);
[email protected]74313b42011-08-24 16:51:32351#elif defined(OS_MACOSX)
[email protected]eb668c92012-02-06 15:35:29352 return web_contents_view_mac::CreateWebContentsView(
[email protected]cce3ab72012-02-04 18:05:16353 web_contents,
354 chrome_web_contents_view_mac_delegate::CreateWebContentsViewMacDelegate(
355 web_contents));
[email protected]6e677a342012-02-11 01:21:14356#elif defined(OS_ANDROID)
[email protected]82c9f44b2012-02-14 21:02:52357 return new WebContentsViewAndroid(web_contents);
[email protected]74313b42011-08-24 16:51:32358#else
[email protected]8643e6d2012-01-18 20:26:10359#error Need to create your platform WebContentsView here.
[email protected]74313b42011-08-24 16:51:32360#endif
361}
362
[email protected]f364d1392011-04-08 21:03:10363void ChromeContentBrowserClient::RenderViewHostCreated(
364 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46365
366 SiteInstance* site_instance = render_view_host->site_instance();
367 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02368 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46369
370 new ChromeRenderViewHostObserver(render_view_host,
371 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10372 new ExtensionMessageHandler(render_view_host);
[email protected]85f0a572012-02-07 22:20:13373
374 if (render_view_host->delegate()->GetRenderViewType() ==
375 content::VIEW_TYPE_INTERSTITIAL_PAGE) {
376 render_view_host->Send(new ChromeViewMsg_SetAsInterstitial(
377 render_view_host->routing_id()));
378 }
[email protected]d977f9c2011-03-14 16:10:26379}
380
[email protected]f3b1a082011-11-18 00:34:30381void ChromeContentBrowserClient::RenderProcessHostCreated(
382 content::RenderProcessHost* host) {
383 int id = host->GetID();
384 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
385 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02386 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30387 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03388#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30389 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03390#endif
[email protected]f3b1a082011-11-18 00:34:30391 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02392 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30393 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56394#if defined(OS_MACOSX)
395 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
396#endif
[email protected]f3b1a082011-11-18 00:34:30397 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03398 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38399
[email protected]2ccf45c2011-08-19 23:35:50400 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
401 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07402
403 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56404
405 RendererContentSettingRules rules;
406 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
407 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14408}
409
[email protected]863f70a2012-01-27 02:05:50410content::WebUIControllerFactory*
411 ChromeContentBrowserClient::GetWebUIControllerFactory() {
412 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56413}
414
[email protected]3d7474ff2011-07-27 17:47:37415GURL ChromeContentBrowserClient::GetEffectiveURL(
416 content::BrowserContext* browser_context, const GURL& url) {
417 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08418 // Get the effective URL for the given actual URL. If the URL is part of an
419 // installed app, the effective URL is an extension URL with the ID of that
420 // extension as the host. This has the effect of grouping apps together in
421 // a common SiteInstance.
422 if (!profile || !profile->GetExtensionService())
423 return url;
424
[email protected]615d88f2011-12-13 01:47:44425 const Extension* extension = profile->GetExtensionService()->extensions()->
426 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08427 if (!extension)
428 return url;
429
[email protected]15877ca2011-11-18 22:40:52430 // Bookmark apps do not use the hosted app process model, and should be
431 // treated as normal URLs.
432 if (extension->from_bookmark())
433 return url;
434
[email protected]36fb2c7c2011-04-04 15:49:08435 // If the URL is part of an extension's web extent, convert it to an
436 // extension URL.
437 return extension->GetResourceURL(url.path());
438}
439
[email protected]056ad2a2011-07-12 02:13:55440bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37441 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55442 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52443 // Because we expect to use the effective URL, URLs for hosted apps (apart
444 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55445 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
446 return false;
447
[email protected]3d7474ff2011-07-27 17:47:37448 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55449 if (!profile || !profile->GetExtensionService())
450 return false;
451
[email protected]615d88f2011-12-13 01:47:44452 const Extension* extension = profile->GetExtensionService()->extensions()->
453 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55454 if (!extension)
455 return false;
456
457 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53458 // permission, or that does not allow JavaScript access to the background
459 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55460 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53461 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
462 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
463 !extension->allow_background_js_access()) {
464 return false;
465 }
466 }
[email protected]056ad2a2011-07-12 02:13:55467
[email protected]7b54ca02012-03-02 18:06:53468 // Hosted apps that have script access to their background page must use
469 // process per site, since all instances can make synchronous calls to the
470 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55471 return true;
472}
473
[email protected]46fb9442011-12-09 17:57:47474bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
475 return ProfileIOData::IsHandledURL(url);
476}
477
[email protected]2a5221b2011-09-27 23:07:31478bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30479 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31480 const GURL& site_url) {
481 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30482 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42483 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46484 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31485
[email protected]ffa97602011-11-17 17:55:52486 // Don't allow the Task Manager to share a process with anything else.
487 // Otherwise it can affect the renderers it is observing.
488 // Note: we could create another RenderProcessHostPrivilege bucket for
489 // this to allow multiple chrome://tasks instances to share, but that's
490 // a very unlikely case without serious consequences.
491 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
492 return false;
493
[email protected]8d3132f62011-10-12 07:13:42494 // These may be NULL during tests. In that case, just assume any site can
495 // share any host.
[email protected]6f371442011-11-09 06:45:46496 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31497 return true;
498
[email protected]a8c269a2011-10-25 20:17:22499 // Experimental:
500 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
501 // to share a renderer process. (We could allow pages from the same site or
502 // extensions of the same type to share, if we knew what the given process
503 // was dedicated to. Allowing no sharing is simpler for now.) This may
504 // cause resource exhaustion issues if too many sites are open at once.
505 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
506 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
507 return false;
508
[email protected]eec0b33c2011-12-05 22:09:45509 // An isolated app is only allowed to share with the exact same app in order
510 // to provide complete renderer process isolation. This also works around
511 // issue http://crbug.com/85588, where different isolated apps in the same
512 // process would end up using the first app's storage contexts.
513 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42514 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45515 if (privilege_required == PRIV_ISOLATED)
516 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
517
518 // Otherwise, just make sure the process privilege matches the privilege
519 // required by the site.
520 return GetProcessPrivilege(process_host, process_map, service) ==
521 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31522}
523
[email protected]76411f412012-02-22 18:56:06524// This function is trying to limit the amount of processes used by extensions
525// with background pages. It uses a globally set percentage of processes to
526// run such extensions and if the limit is exceeded, it returns true, to
527// indicate to the content module to group extensions together.
528bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
529 content::BrowserContext* browser_context, const GURL& url) {
530 // It has to be a valid URL for us to check for an extension.
531 if (!url.is_valid())
532 return false;
533
534 Profile* profile = Profile::FromBrowserContext(browser_context);
535 ExtensionService* service = profile->GetExtensionService();
536 if (!service)
537 return false;
538
539 // We have to have a valid extension with background page to proceed.
540 const Extension* extension =
541 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
542 if (!extension)
543 return false;
544 if (!extension->has_background_page())
545 return false;
546
547 std::set<int> process_ids;
548 size_t max_process_count =
549 content::RenderProcessHost::GetMaxRendererProcessCount();
550
551 // Go through all profiles to ensure we have total count of extension
552 // processes containing background pages, otherwise one profile can
553 // starve the other.
554 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
555 GetLoadedProfiles();
556 for (size_t i = 0; i < profiles.size(); ++i) {
557 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
558 for (ExtensionProcessManager::const_iterator iter = epm->begin();
559 iter != epm->end();
560 ++iter) {
561 ExtensionHost* host = *iter;
562 if (host->extension()->has_background_page()) {
563 process_ids.insert(host->render_process_host()->GetID());
564 }
565 }
566 }
567
568 if (process_ids.size() >
569 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
570 return true;
571 }
572
573 return false;
574}
575
[email protected]6f371442011-11-09 06:45:46576void ChromeContentBrowserClient::SiteInstanceGotProcess(
577 SiteInstance* site_instance) {
578 CHECK(site_instance->HasProcess());
579
580 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02581 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46582 ExtensionService* service = profile->GetExtensionService();
583 if (!service)
584 return;
585
586 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44587 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33588 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46589 if (!extension)
590 return;
591
[email protected]6bc04fd82011-12-04 02:29:35592 service->process_map()->Insert(extension->id(),
593 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33594 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46595 BrowserThread::PostTask(
596 BrowserThread::IO, FROM_HERE,
597 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
598 profile->GetExtensionInfoMap(),
599 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35600 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33601 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46602}
603
604void ChromeContentBrowserClient::SiteInstanceDeleting(
605 SiteInstance* site_instance) {
606 if (!site_instance->HasProcess())
607 return;
608
609 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02610 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46611 ExtensionService* service = profile->GetExtensionService();
612 if (!service)
613 return;
614
615 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44616 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33617 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46618 if (!extension)
619 return;
620
[email protected]6bc04fd82011-12-04 02:29:35621 service->process_map()->Remove(extension->id(),
622 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33623 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46624 BrowserThread::PostTask(
625 BrowserThread::IO, FROM_HERE,
626 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
627 profile->GetExtensionInfoMap(),
628 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35629 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33630 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46631}
632
[email protected]e3daf3c2011-10-05 21:17:08633bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
634 const GURL& current_url,
635 const GURL& new_url) {
636 if (current_url.is_empty()) {
637 // Always choose a new process when navigating to extension URLs. The
638 // process grouping logic will combine all of a given extension's pages
639 // into the same process.
640 if (new_url.SchemeIs(chrome::kExtensionScheme))
641 return true;
642
643 return false;
644 }
645
646 // Also, we must switch if one is an extension and the other is not the exact
647 // same extension.
648 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
649 new_url.SchemeIs(chrome::kExtensionScheme)) {
650 if (current_url.GetOrigin() != new_url.GetOrigin())
651 return true;
652 }
653
654 return false;
655}
656
[email protected]763ec4ca2011-04-29 15:48:12657std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
658 const std::string& alias_name) {
659 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
660}
661
[email protected]b80f68432011-05-02 17:22:30662void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
663 CommandLine* command_line, int child_process_id) {
664#if defined(USE_LINUX_BREAKPAD)
665 if (IsCrashReporterEnabled()) {
666 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
667 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
668 }
669#elif defined(OS_MACOSX)
670 if (IsCrashReporterEnabled()) {
671 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
672 child_process_logging::GetClientId());
673 }
674#endif // OS_MACOSX
675
[email protected]f1933792011-06-14 00:49:34676 if (logging::DialogsAreSuppressed())
677 command_line->AppendSwitch(switches::kNoErrorDialogs);
678
[email protected]b80f68432011-05-02 17:22:30679 std::string process_type =
680 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17681 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52682 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30683 FilePath user_data_dir =
684 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
685 if (!user_data_dir.empty())
686 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
687#if defined(OS_CHROMEOS)
688 const std::string& login_profile =
689 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
690 if (!login_profile.empty())
691 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
692#endif
693
[email protected]f3b1a082011-11-18 00:34:30694 content::RenderProcessHost* process =
695 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37696 if (process) {
697 Profile* profile = Profile::FromBrowserContext(
698 process->GetBrowserContext());
699 extensions::ProcessMap* process_map =
700 profile->GetExtensionService()->process_map();
701 if (process_map && process_map->Contains(process->GetID()))
702 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30703
[email protected]a8d851f82011-12-21 00:32:37704 PrefService* prefs = profile->GetPrefs();
705 // Currently this pref is only registered if applied via a policy.
706 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
707 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
708 // Turn this policy into a command line switch.
709 command_line->AppendSwitch(switches::kDisable3DAPIs);
710 }
[email protected]718eab62011-10-05 21:16:52711
[email protected]a8d851f82011-12-21 00:32:37712 // Disable client-side phishing detection in the renderer if it is
713 // disabled in the Profile preferences or the browser process.
714 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
715 !g_browser_process->safe_browsing_detection_service()) {
716 command_line->AppendSwitch(
717 switches::kDisableClientSidePhishingDetection);
718 }
[email protected]8c40da62011-07-13 22:58:46719 }
[email protected]47c7ec82012-01-18 03:29:21720 {
721 PrefService* local_state = g_browser_process->local_state();
722 if (local_state &&
723 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
724 command_line->AppendSwitch(switches::kRendererPrintPreview);
725 }
726 }
[email protected]4287a3d2011-06-13 23:56:51727
[email protected]47c7ec82012-01-18 03:29:21728 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51729 static const char* const kSwitchNames[] = {
730 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48731 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51732 switches::kAllowScriptingGallery,
733 switches::kAppsCheckoutURL,
734 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31735 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51736 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50737 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51738 switches::kDumpHistogramsOnExit,
[email protected]b7e44ff2012-02-16 03:37:34739 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21740 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13741 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51742 switches::kEnableCrxlessWebApps,
743 switches::kEnableExperimentalExtensionApis,
744 switches::kEnableInBrowserThumbnailing,
745 switches::kEnableIPCFuzzing,
746 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:48747 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53748 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51749 switches::kEnableWatchdog,
750 switches::kExperimentalSpellcheckerFeatures,
751 switches::kMemoryProfiling,
752 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04753 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51754 switches::kPpapiFlashArgs,
755 switches::kPpapiFlashInProcess,
756 switches::kPpapiFlashPath,
757 switches::kPpapiFlashVersion,
758 switches::kProfilingAtStart,
759 switches::kProfilingFile,
760 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51761 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38762 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51763 };
764
765 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
766 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17767 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38768 static const char* const kSwitchNames[] = {
769 switches::kEnableExperimentalExtensionApis,
770 switches::kWhitelistedExtensionID,
771 };
772
773 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
774 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51775 } else if (process_type == switches::kPluginProcess) {
776 static const char* const kSwitchNames[] = {
777 #if defined(OS_CHROMEOS)
778 switches::kLoginProfile,
779 #endif
780 switches::kMemoryProfiling,
781 switches::kSilentDumpOnDCHECK,
782 switches::kUserDataDir,
783 };
784
785 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
786 arraysize(kSwitchNames));
787 } else if (process_type == switches::kZygoteProcess) {
788 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51789 switches::kUserDataDir, // Make logs go to the right file.
790 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50791 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13792 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51793 switches::kPpapiFlashInProcess,
794 switches::kPpapiFlashPath,
795 switches::kPpapiFlashVersion,
796 };
797
798 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
799 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11800 } else if (process_type == switches::kGpuProcess) {
801 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
802 // because GPU is expected to be unreliable.
803 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
804 !command_line->HasSwitch(switches::kDisableBreakpad))
805 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30806 }
[email protected]6f08af82011-09-15 01:19:03807
808 // The command line switch kEnableBenchmarking needs to be specified along
809 // with the kEnableStatsTable switch to ensure that the stats table global
810 // is initialized correctly.
811 if (command_line->HasSwitch(switches::kEnableBenchmarking))
812 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30813}
814
815std::string ChromeContentBrowserClient::GetApplicationLocale() {
816 return g_browser_process->GetApplicationLocale();
817}
818
[email protected]597a867b2011-11-18 18:31:20819std::string ChromeContentBrowserClient::GetAcceptLangs(
820 content::BrowserContext* context) {
821 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37822 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08823}
824
[email protected]ac55e292011-06-24 05:16:08825SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22826 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08827 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
828}
829
[email protected]a2176792011-05-08 19:30:49830bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09831 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19832 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20833 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32834 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20835 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05836 return io_data->GetCookieSettings()->
837 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49838}
839
[email protected]ed24fad2011-05-10 22:44:01840bool ChromeContentBrowserClient::AllowGetCookie(
841 const GURL& url,
842 const GURL& first_party,
843 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20844 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01845 int render_process_id,
846 int render_view_id) {
847 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20848 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05849 bool allow = io_data->GetCookieSettings()->
850 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01851
[email protected]8093a542011-05-13 07:29:32852 BrowserThread::PostTask(
853 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03854 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
855 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01856 return allow;
857}
858
859bool ChromeContentBrowserClient::AllowSetCookie(
860 const GURL& url,
861 const GURL& first_party,
862 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20863 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01864 int render_process_id,
865 int render_view_id,
866 net::CookieOptions* options) {
867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20868 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05869 CookieSettings* cookie_settings = io_data->GetCookieSettings();
870 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
871
872 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09873 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01874
[email protected]8093a542011-05-13 07:29:32875 BrowserThread::PostTask(
876 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03877 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
878 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01879 return allow;
880}
881
[email protected]d5a19162011-06-30 18:51:54882bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20883 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54884 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20885 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26886
887 if (!io_data->clear_local_state_on_exit()->GetValue())
888 return true;
889
[email protected]068b7b52012-02-27 12:41:44890 // Disable clearing the local state on exit if the browsing session is going
[email protected]1848cdc2012-02-17 10:48:26891 // to be restored on the next startup.
892 SessionStartupPref::Type startup_pref =
893 SessionStartupPref::PrefValueToType(
894 io_data->session_startup_pref()->GetValue());
895 return (startup_pref == SessionStartupPref::LAST &&
[email protected]068b7b52012-02-27 12:41:44896 !CommandLine::ForCurrentProcess()->HasSwitch(
897 switches::kDisableRestoreSessionState));
[email protected]d5a19162011-06-30 18:51:54898}
899
[email protected]5c5a88e2011-11-12 00:45:35900bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35901 const GURL& url,
902 const string16& name,
903 const string16& display_name,
904 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20905 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48906 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35907 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20908 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35909 CookieSettings* cookie_settings = io_data->GetCookieSettings();
910 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
911
[email protected]62151052012-02-01 18:40:48912 // Record access to database for potential display in UI.
913 std::vector<std::pair<int, int> >::const_iterator i;
914 for (i = render_views.begin(); i != render_views.end(); ++i) {
915 BrowserThread::PostTask(
916 BrowserThread::UI, FROM_HERE,
917 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
918 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35919 }
920
921 return allow;
922}
923
924bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35925 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20926 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48927 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35928 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20929 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35930 CookieSettings* cookie_settings = io_data->GetCookieSettings();
931 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
932
[email protected]62151052012-02-01 18:40:48933 // Record access to file system for potential display in UI.
934 std::vector<std::pair<int, int> >::const_iterator i;
935 for (i = render_views.begin(); i != render_views.end(); ++i) {
936 BrowserThread::PostTask(
937 BrowserThread::UI, FROM_HERE,
938 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
939 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35940 }
941
942 return allow;
943}
944
[email protected]7c5ff9a2012-03-02 07:42:49945bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
946 const GURL& url,
947 const string16& name,
948 content::ResourceContext* context,
949 const std::vector<std::pair<int, int> >& render_views) {
950 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
951 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
952 CookieSettings* cookie_settings = io_data->GetCookieSettings();
953 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
954
955 // Record access to IndexedDB for potential display in UI.
956 std::vector<std::pair<int, int> >::const_iterator i;
957 for (i = render_views.begin(); i != render_views.end(); ++i) {
958 BrowserThread::PostTask(
959 BrowserThread::UI, FROM_HERE,
960 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
961 i->first, i->second, url, name, !allow));
962 }
963
964 return allow;
965}
966
[email protected]6133f922011-07-01 21:34:34967net::URLRequestContext*
968ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20969 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34970 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
971 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20972 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34973 return io_data->extensions_request_context();
974 }
975
976 return NULL;
977}
978
[email protected]317f96c92011-05-31 06:53:41979QuotaPermissionContext*
980ChromeContentBrowserClient::CreateQuotaPermissionContext() {
981 return new ChromeQuotaPermissionContext();
982}
983
[email protected]a0ce3282011-08-19 20:49:52984void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42985 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42986}
987
[email protected]a0ce3282011-08-19 20:49:52988void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52989 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52990}
991
[email protected]848dd042011-06-04 18:24:03992void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:17993 int render_process_id,
994 int render_view_id,
995 int cert_error,
996 const net::SSLInfo& ssl_info,
997 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:03998 bool overridable,
[email protected]4cf611e32012-02-13 16:06:17999 const base::Callback<void(bool)>& callback,
1000 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:411001 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:131002 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:171003 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:411004 if (!tab) {
1005 NOTREACHED();
1006 return;
1007 }
1008 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501009 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301010 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091011 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411012 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171013 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411014 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171015 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411016 return;
1017 }
1018 }
1019
1020 // Otherwise, display an SSL blocking page.
[email protected]4cf611e32012-02-13 16:06:171021 new SSLBlockingPage(
1022 tab, cert_error, ssl_info, request_url, overridable, callback);
[email protected]848dd042011-06-04 18:24:031023}
1024
[email protected]c99c442e2011-08-24 11:37:301025void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451026 int render_process_id,
1027 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401028 const net::HttpNetworkSession* network_session,
1029 net::SSLCertRequestInfo* cert_request_info,
1030 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131031 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451032 render_process_id, render_view_id);
1033 if (!tab) {
1034 NOTREACHED();
1035 return;
1036 }
1037
[email protected]6786bf402011-12-03 15:19:451038 GURL requesting_url("https://" + cert_request_info->host_and_port);
1039 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1040 << cert_request_info->host_and_port;
1041
[email protected]627e0512011-12-21 22:55:301042 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451043 scoped_ptr<Value> filter(
1044 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1045 requesting_url,
1046 requesting_url,
1047 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1048 std::string(), NULL));
1049
1050 if (filter.get()) {
1051 // Try to automatically select a client certificate.
1052 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1053 DictionaryValue* filter_dict =
1054 static_cast<DictionaryValue*>(filter.get());
1055
1056 const std::vector<scoped_refptr<net::X509Certificate> >&
1057 all_client_certs = cert_request_info->client_certs;
1058 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1059 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1060 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401061 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451062 return;
1063 }
1064 }
1065 } else {
1066 NOTREACHED();
1067 }
1068 }
1069
[email protected]8ec26472011-06-06 16:52:451070 TabContentsWrapper* wrapper =
1071 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451072 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131073 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451074 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141075 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401076 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451077 return;
1078 }
[email protected]7a593db2012-02-13 21:19:401079 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1080 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451081}
1082
1083void ChromeContentBrowserClient::AddNewCertificate(
1084 net::URLRequest* request,
1085 net::X509Certificate* cert,
1086 int render_process_id,
1087 int render_view_id) {
1088 // The handler will run the UI and delete itself when it's finished.
1089 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1090}
1091
[email protected]a93670ab2012-02-24 03:46:391092void ChromeContentBrowserClient::RequestMediaAccessPermission(
1093 const content::MediaStreamRequest* request,
1094 const content::MediaResponseCallback& callback) {
1095 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1096
[email protected]117b6b42012-02-29 09:11:081097 WebContents* contents = tab_util::GetWebContentsByID(
1098 request->render_process_id, request->render_view_id);
1099 if (!contents) {
1100 // Abort, if the tab was closed after the request was made but before we
1101 // got to this point.
1102 callback.Run(content::MediaStreamDevices());
1103 return;
1104 }
1105
1106 TabContentsWrapper* tab =
1107 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1108 DCHECK(tab);
1109
1110 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1111 InfoBarDelegate* old_infobar = NULL;
1112 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1113 old_infobar =
1114 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfobarDelegate();
1115 }
1116
1117#if defined(TOOLKIT_VIEWS)
1118 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1119 request,
1120 callback);
1121 if (old_infobar)
1122 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1123 else
1124 infobar_helper->AddInfoBar(infobar);
1125#elif defined(OS_LINUX) || defined(OS_MACOSX)
1126 // TODO(macourteau): UI is not implemented yet for Linux and OS X. Fallback to
1127 // the default behaviour and allow access to the first device of each
1128 // requested type.
1129 content::MediaStreamDevices devices;
[email protected]a93670ab2012-02-24 03:46:391130 for (content::MediaStreamDeviceMap::const_iterator it =
1131 request->devices.begin(); it != request->devices.end(); ++it) {
[email protected]6c6415a2012-03-01 17:17:281132 if (!it->second.empty())
1133 devices.push_back(*it->second.begin());
[email protected]a93670ab2012-02-24 03:46:391134 }
1135
[email protected]a93670ab2012-02-24 03:46:391136 callback.Run(devices);
[email protected]117b6b42012-02-29 09:11:081137#endif // TOOLKIT_VIEWS
[email protected]a93670ab2012-02-24 03:46:391138}
1139
[email protected]941623e2011-06-07 23:06:041140void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1141 const GURL& source_origin,
1142 int callback_context,
1143 int render_process_id,
1144 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111145#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041146 RenderViewHost* rvh = RenderViewHost::FromID(
1147 render_process_id, render_view_id);
1148 if (!rvh) {
1149 NOTREACHED();
1150 return;
1151 }
1152
[email protected]f3b1a082011-11-18 00:34:301153 content::RenderProcessHost* process = rvh->process();
1154 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041155 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371156 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041157 service->RequestPermission(
1158 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131159 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111160#else
1161 NOTIMPLEMENTED();
1162#endif
[email protected]941623e2011-06-07 23:06:041163}
1164
1165WebKit::WebNotificationPresenter::Permission
1166 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021167 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201168 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021169 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111170#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201172 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021173 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1174 source_origin, render_process_id,
1175 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041176 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041177
1178 // Fall back to the regular notification preferences, which works on an
1179 // origin basis.
1180 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371181 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041182 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111183#else
1184 return WebKit::WebNotificationPresenter::PermissionAllowed;
1185#endif
[email protected]941623e2011-06-07 23:06:041186}
1187
1188void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171189 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041190 int render_process_id,
1191 int render_view_id,
1192 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111193#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041194 RenderViewHost* rvh = RenderViewHost::FromID(
1195 render_process_id, render_view_id);
1196 if (!rvh) {
1197 NOTREACHED();
1198 return;
1199 }
1200
[email protected]f3b1a082011-11-18 00:34:301201 content::RenderProcessHost* process = rvh->process();
1202 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041203 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371204 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041205 service->ShowDesktopNotification(
1206 params, render_process_id, render_view_id,
1207 worker ? DesktopNotificationService::WorkerNotification :
1208 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111209#else
1210 NOTIMPLEMENTED();
1211#endif
[email protected]941623e2011-06-07 23:06:041212}
1213
1214void ChromeContentBrowserClient::CancelDesktopNotification(
1215 int render_process_id,
1216 int render_view_id,
1217 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111218#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041219 RenderViewHost* rvh = RenderViewHost::FromID(
1220 render_process_id, render_view_id);
1221 if (!rvh) {
1222 NOTREACHED();
1223 return;
1224 }
1225
[email protected]f3b1a082011-11-18 00:34:301226 content::RenderProcessHost* process = rvh->process();
1227 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041228 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371229 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041230 service->CancelDesktopNotification(
1231 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111232#else
1233 NOTIMPLEMENTED();
1234#endif
[email protected]941623e2011-06-07 23:06:041235}
1236
[email protected]9f3fba52011-06-08 20:37:191237bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:021238 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191239 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201240 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021241 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1243 // If the opener is trying to create a background window but doesn't have
1244 // the appropriate permission, fail the attempt.
1245 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201246 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531247 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1248
1249 // If the opener is not allowed to script its background window, then return
1250 // false so that the window.open call returns null. In this case, only
1251 // the manifest is permitted to create a background window.
1252 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1253 // return a recently installed Extension even if this CanCreateWindow call
1254 // was made by an old copy of the page in a normal web process. That's ok,
1255 // because the permission check below will still fail.
1256 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
1257 ExtensionURLInfo(source_origin));
1258 if (extension && !extension->allow_background_js_access())
1259 return false;
1260
1261 return map->SecurityOriginHasAPIPermission(
[email protected]34eec7ffe32011-11-02 23:49:021262 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191263 }
1264 return true;
1265}
1266
1267std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201268 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1270 // Check if it's an extension-created worker, in which case we want to use
1271 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201272 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191273 const Extension* extension =
1274 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1275 return extension ? extension->name() : std::string();
1276}
1277
[email protected]99907362012-01-11 05:41:401278void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1279 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171280}
1281
[email protected]66cfec62012-02-24 17:57:511282content::SpeechInputManagerDelegate*
1283 ChromeContentBrowserClient::GetSpeechInputManagerDelegate() {
1284 return new speech_input::ChromeSpeechInputManagerDelegate();
1285}
1286
[email protected]3cb054e62011-06-13 05:21:171287ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1288 return g_browser_process->clipboard();
1289}
1290
[email protected]ae6e9912011-07-27 01:18:281291net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1292 return g_browser_process->net_log();
1293}
1294
[email protected]32538d92011-08-25 00:09:231295AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1296 return new ChromeAccessTokenStore();
1297}
1298
[email protected]dbae6b02011-06-29 23:51:411299bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1300 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1301 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1302}
1303
[email protected]64d69de42012-02-06 00:19:541304void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321305 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061306 Profile* profile = Profile::FromBrowserContext(
1307 rvh->process()->GetBrowserContext());
1308 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061309
[email protected]64d69de42012-02-06 00:19:541310 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061311 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541312 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061313 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541314 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061315 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541316 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061317 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541318 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061319 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541320 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061321 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1322
1323 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541324 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061325 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541326 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061327 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541328 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061329 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541330 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061331 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541332 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061333 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541334 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061335
[email protected]64d69de42012-02-06 00:19:541336 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061337 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541338 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061339 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541340 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061341 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541342 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061343 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1344
[email protected]64d69de42012-02-06 00:19:541345 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061346
[email protected]64d69de42012-02-06 00:19:541347 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061348 prefs->GetBoolean(
1349 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541350 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061351 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541352 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061353 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1354 const DictionaryValue* inspector_settings =
1355 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1356 if (inspector_settings) {
1357 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1358 iter != inspector_settings->end_keys(); ++iter) {
1359 std::string value;
1360 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541361 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061362 std::make_pair(*iter, value));
1363 }
1364 }
[email protected]64d69de42012-02-06 00:19:541365 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061366
[email protected]64d69de42012-02-06 00:19:541367 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1368 web_prefs->javascript_enabled = false;
1369 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1370 web_prefs->web_security_enabled = false;
1371 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1372 web_prefs->plugins_enabled = false;
1373 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1374 web_prefs->java_enabled = false;
1375 web_prefs->loads_images_automatically =
1376 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061377
[email protected]64d69de42012-02-06 00:19:541378 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1379 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061380
[email protected]64d69de42012-02-06 00:19:541381 web_prefs->memory_info_enabled =
1382 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1383 web_prefs->allow_displaying_insecure_content =
1384 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1385 web_prefs->allow_running_insecure_content =
1386 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081387 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061388
[email protected]64d69de42012-02-06 00:19:541389 // The user stylesheet watcher may not exist in a testing profile.
1390 if (profile->GetUserStyleSheetWatcher()) {
1391 web_prefs->user_style_sheet_enabled = true;
1392 web_prefs->user_style_sheet_location =
1393 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1394 } else {
1395 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061396 }
1397
[email protected]b7e44ff2012-02-16 03:37:341398 web_prefs->asynchronous_spell_checking_enabled =
1399 CommandLine::ForCurrentProcess()->
1400 HasSwitch(switches::kEnableAsynchronousSpellChecking);
1401 web_prefs->unified_textchecker_enabled =
1402 web_prefs->asynchronous_spell_checking_enabled ||
1403 CommandLine::ForCurrentProcess()->
1404 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571405
[email protected]64d69de42012-02-06 00:19:541406 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061407 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541408 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061409 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541410 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061411 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1412
1413 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541414 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061415 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541416 web_prefs->default_encoding);
1417 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061418 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541419 web_prefs->default_encoding =
1420 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061421 }
[email protected]64d69de42012-02-06 00:19:541422 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061423
1424 ExtensionService* service = profile->GetExtensionService();
1425 if (service) {
1426 const Extension* extension = service->extensions()->GetByID(
[email protected]b6583592012-01-25 19:52:331427 rvh->site_instance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061428 extension_webkit_preferences::SetPreferences(
[email protected]64d69de42012-02-06 00:19:541429 extension, rvh->delegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061430 }
1431
1432 if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541433 web_prefs->allow_scripts_to_close_windows = true;
[email protected]f3986f82012-01-03 20:00:061434 } else if (rvh->delegate()->GetRenderViewType() ==
1435 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1436 // Disable all kinds of acceleration for background pages.
1437 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541438 web_prefs->force_compositing_mode = false;
1439 web_prefs->accelerated_compositing_enabled = false;
1440 web_prefs->accelerated_2d_canvas_enabled = false;
1441 web_prefs->accelerated_video_enabled = false;
1442 web_prefs->accelerated_painting_enabled = false;
1443 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061444 }
[email protected]2e21fe292012-03-02 22:52:321445
1446#if defined(FILE_MANAGER_EXTENSION)
1447 // Override the default of suppressing HW compositing for WebUI pages for the
1448 // file manager, which is implemented using WebUI but wants HW acceleration
1449 // for video decode & render.
1450 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1451 web_prefs->accelerated_compositing_enabled = true;
1452 web_prefs->accelerated_2d_canvas_enabled = true;
1453 }
1454#endif
[email protected]181a95ee2011-07-12 19:26:361455}
1456
1457void ChromeContentBrowserClient::UpdateInspectorSetting(
1458 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061459 content::BrowserContext* browser_context =
1460 rvh->process()->GetBrowserContext();
1461 DictionaryPrefUpdate update(
1462 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1463 prefs::kWebKitInspectorSettings);
1464 DictionaryValue* inspector_settings = update.Get();
1465 inspector_settings->SetWithoutPathExpansion(key,
1466 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361467}
1468
1469void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061470 content::BrowserContext* browser_context =
1471 rvh->process()->GetBrowserContext();
1472 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1473 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361474}
1475
[email protected]b8148ac2011-07-13 22:03:251476void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1477 BrowserURLHandler* handler) {
1478 // Add the default URL handlers.
1479 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1480 BrowserURLHandler::null_handler());
1481 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1482 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1483
[email protected]b3adbd02011-11-30 22:23:271484 // about: handler. Must come before chrome: handler, since it will
1485 // rewrite about: urls to chrome: URLs and then expect chrome: to
1486 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251487 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1488 BrowserURLHandler::null_handler());
1489 // chrome: & friends.
1490 handler->AddHandlerPair(&HandleWebUI,
1491 BrowserURLHandler::null_handler());
1492}
1493
1494void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371495 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301496 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251497 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1498 BrowsingDataRemover::EVERYTHING,
1499 base::Time());
1500 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1501 // BrowsingDataRemover takes care of deleting itself when done.
1502}
1503
1504void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371505 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301506 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251507 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1508 BrowsingDataRemover::EVERYTHING,
1509 base::Time());
[email protected]dceaa912011-09-06 17:17:231510 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251511 remover->Remove(remove_mask);
1512 // BrowsingDataRemover takes care of deleting itself when done.
1513}
1514
[email protected]e1d16eb92011-08-18 23:19:321515FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1516 return download_util::GetDefaultDownloadDirectory();
1517}
1518
[email protected]c9b6eb62011-10-18 20:49:391519std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1520 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1521}
1522
[email protected]a658d452012-03-02 12:45:291523bool ChromeContentBrowserClient::AllowSocketAPI(
1524 content::BrowserContext* browser_context, const GURL& url) {
1525 if (!url.is_valid())
1526 return false;
1527
1528 std::string host = url.host();
1529 if (allowed_socket_origins_.count(host))
1530 return true;
1531
1532 Profile* profile = Profile::FromBrowserContext(browser_context);
1533 if (!profile || !profile->GetExtensionService())
1534 return false;
1535
1536 const Extension* extension = profile->GetExtensionService()->extensions()->
1537 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1538 if (!extension)
1539 return false;
1540
1541 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1542 return true;
1543
1544 return false;
[email protected]e461da2f2012-02-16 19:06:401545}
1546
[email protected]e60c0232011-11-11 19:56:351547#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301548int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521549 const CommandLine& command_line) {
[email protected]6e677a342012-02-11 01:21:141550#if defined(OS_ANDROID)
1551 // TODO(carlosvaldivia): Upstream breakpad code for Android and remove this
1552 // fork. http://crbug.com/113560
1553 NOTIMPLEMENTED();
1554#else
[email protected]718eab62011-10-05 21:16:521555 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071556 ExtensionCrashHandlerHostLinux* crash_handler =
1557 ExtensionCrashHandlerHostLinux::GetInstance();
1558 return crash_handler->GetDeathSignalSocket();
1559 }
1560
[email protected]718eab62011-10-05 21:16:521561 std::string process_type =
1562 command_line.GetSwitchValueASCII(switches::kProcessType);
1563
1564 if (process_type == switches::kRendererProcess)
1565 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1566
[email protected]b80f68432011-05-02 17:22:301567 if (process_type == switches::kPluginProcess)
1568 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1569
1570 if (process_type == switches::kPpapiPluginProcess)
1571 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1572
1573 if (process_type == switches::kGpuProcess)
1574 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
[email protected]6e677a342012-02-11 01:21:141575#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:301576
1577 return -1;
1578}
[email protected]e60c0232011-11-11 19:56:351579#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301580
[email protected]4a65826d2011-08-25 16:04:011581#if defined(OS_WIN)
1582const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1583 return chrome::kBrowserResourcesDll;
1584}
1585#endif
1586
[email protected]37a72af2011-06-13 05:42:011587#if defined(USE_NSS)
1588crypto::CryptoModuleBlockingPasswordDelegate*
1589 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1590 const GURL& url) {
1591 return browser::NewCryptoModuleBlockingDialogDelegate(
1592 browser::kCryptoModulePasswordKeygen, url.host());
1593}
1594#endif
1595
[email protected]d977f9c2011-03-14 16:10:261596} // namespace chrome