blob: 901f43e49c192e7bf5d5af4169a48c3476efcfbd [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]f364d1392011-04-08 21:03:1031#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]9c1662b2012-03-06 15:44:3332#include "chrome/browser/extensions/extension_process_manager.h"
[email protected]d977f9c2011-03-14 16:10:2633#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2534#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0635#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]32538d92011-08-25 00:09:2336#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1237#include "chrome/browser/google/google_util.h"
[email protected]117b6b42012-02-29 09:11:0838#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]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]c52b2892012-03-07 11:01:0256#include "chrome/browser/speech/chrome_speech_recognition_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]b48c9182011-10-26 18:03:3076#include "content/public/browser/browser_main_parts.h"
[email protected]b9535422012-02-09 01:47:5977#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3078#include "content/public/browser/render_process_host.h"
[email protected]9c1662b2012-03-06 15:44:3379#include "content/public/browser/render_view_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
[email protected]9f76c1e2012-03-05 15:15:58366 SiteInstance* site_instance = render_view_host->GetSiteInstance();
[email protected]67372ecf2011-09-10 01:30:46367 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]d977f9c2011-03-14 16:10:26373}
374
[email protected]f3b1a082011-11-18 00:34:30375void ChromeContentBrowserClient::RenderProcessHostCreated(
376 content::RenderProcessHost* host) {
377 int id = host->GetID();
378 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
379 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02380 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30381 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
[email protected]058e5732012-03-01 22:48:03382#if !defined(OS_ANDROID)
[email protected]f3b1a082011-11-18 00:34:30383 host->GetChannel()->AddFilter(new PrintingMessageFilter());
[email protected]058e5732012-03-01 22:48:03384#endif
[email protected]f3b1a082011-11-18 00:34:30385 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02386 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30387 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56388#if defined(OS_MACOSX)
389 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
390#endif
[email protected]f3b1a082011-11-18 00:34:30391 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03392 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38393
[email protected]2ccf45c2011-08-19 23:35:50394 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
395 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07396
397 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56398
399 RendererContentSettingRules rules;
400 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
401 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14402}
403
[email protected]863f70a2012-01-27 02:05:50404content::WebUIControllerFactory*
405 ChromeContentBrowserClient::GetWebUIControllerFactory() {
406 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56407}
408
[email protected]3d7474ff2011-07-27 17:47:37409GURL ChromeContentBrowserClient::GetEffectiveURL(
410 content::BrowserContext* browser_context, const GURL& url) {
411 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08412 // Get the effective URL for the given actual URL. If the URL is part of an
413 // installed app, the effective URL is an extension URL with the ID of that
414 // extension as the host. This has the effect of grouping apps together in
415 // a common SiteInstance.
416 if (!profile || !profile->GetExtensionService())
417 return url;
418
[email protected]615d88f2011-12-13 01:47:44419 const Extension* extension = profile->GetExtensionService()->extensions()->
420 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08421 if (!extension)
422 return url;
423
[email protected]15877ca2011-11-18 22:40:52424 // Bookmark apps do not use the hosted app process model, and should be
425 // treated as normal URLs.
426 if (extension->from_bookmark())
427 return url;
428
[email protected]36fb2c7c2011-04-04 15:49:08429 // If the URL is part of an extension's web extent, convert it to an
430 // extension URL.
431 return extension->GetResourceURL(url.path());
432}
433
[email protected]056ad2a2011-07-12 02:13:55434bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37435 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55436 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52437 // Because we expect to use the effective URL, URLs for hosted apps (apart
438 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55439 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
440 return false;
441
[email protected]3d7474ff2011-07-27 17:47:37442 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55443 if (!profile || !profile->GetExtensionService())
444 return false;
445
[email protected]615d88f2011-12-13 01:47:44446 const Extension* extension = profile->GetExtensionService()->extensions()->
447 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55448 if (!extension)
449 return false;
450
451 // If the URL is part of a hosted app that does not have the background
[email protected]7b54ca02012-03-02 18:06:53452 // permission, or that does not allow JavaScript access to the background
453 // page, we want to give each instance its own process to improve
[email protected]056ad2a2011-07-12 02:13:55454 // responsiveness.
[email protected]7b54ca02012-03-02 18:06:53455 if (extension->GetType() == Extension::TYPE_HOSTED_APP) {
456 if (!extension->HasAPIPermission(ExtensionAPIPermission::kBackground) ||
457 !extension->allow_background_js_access()) {
458 return false;
459 }
460 }
[email protected]056ad2a2011-07-12 02:13:55461
[email protected]7b54ca02012-03-02 18:06:53462 // Hosted apps that have script access to their background page must use
463 // process per site, since all instances can make synchronous calls to the
464 // background window. Other extensions should use process per site as well.
[email protected]056ad2a2011-07-12 02:13:55465 return true;
466}
467
[email protected]46fb9442011-12-09 17:57:47468bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
469 return ProfileIOData::IsHandledURL(url);
470}
471
[email protected]2a5221b2011-09-27 23:07:31472bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30473 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31474 const GURL& site_url) {
475 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30476 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42477 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46478 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31479
[email protected]ffa97602011-11-17 17:55:52480 // Don't allow the Task Manager to share a process with anything else.
481 // Otherwise it can affect the renderers it is observing.
482 // Note: we could create another RenderProcessHostPrivilege bucket for
483 // this to allow multiple chrome://tasks instances to share, but that's
484 // a very unlikely case without serious consequences.
485 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
486 return false;
487
[email protected]8d3132f62011-10-12 07:13:42488 // These may be NULL during tests. In that case, just assume any site can
489 // share any host.
[email protected]6f371442011-11-09 06:45:46490 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31491 return true;
492
[email protected]a8c269a2011-10-25 20:17:22493 // Experimental:
494 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
495 // to share a renderer process. (We could allow pages from the same site or
496 // extensions of the same type to share, if we knew what the given process
497 // was dedicated to. Allowing no sharing is simpler for now.) This may
498 // cause resource exhaustion issues if too many sites are open at once.
499 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
500 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
501 return false;
502
[email protected]eec0b33c2011-12-05 22:09:45503 // An isolated app is only allowed to share with the exact same app in order
504 // to provide complete renderer process isolation. This also works around
505 // issue http://crbug.com/85588, where different isolated apps in the same
506 // process would end up using the first app's storage contexts.
507 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42508 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45509 if (privilege_required == PRIV_ISOLATED)
510 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
511
512 // Otherwise, just make sure the process privilege matches the privilege
513 // required by the site.
514 return GetProcessPrivilege(process_host, process_map, service) ==
515 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31516}
517
[email protected]76411f412012-02-22 18:56:06518// This function is trying to limit the amount of processes used by extensions
519// with background pages. It uses a globally set percentage of processes to
520// run such extensions and if the limit is exceeded, it returns true, to
521// indicate to the content module to group extensions together.
522bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost(
523 content::BrowserContext* browser_context, const GURL& url) {
524 // It has to be a valid URL for us to check for an extension.
525 if (!url.is_valid())
526 return false;
527
528 Profile* profile = Profile::FromBrowserContext(browser_context);
529 ExtensionService* service = profile->GetExtensionService();
530 if (!service)
531 return false;
532
533 // We have to have a valid extension with background page to proceed.
534 const Extension* extension =
535 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(url));
536 if (!extension)
537 return false;
538 if (!extension->has_background_page())
539 return false;
540
541 std::set<int> process_ids;
542 size_t max_process_count =
543 content::RenderProcessHost::GetMaxRendererProcessCount();
544
545 // Go through all profiles to ensure we have total count of extension
546 // processes containing background pages, otherwise one profile can
547 // starve the other.
548 std::vector<Profile*> profiles = g_browser_process->profile_manager()->
549 GetLoadedProfiles();
550 for (size_t i = 0; i < profiles.size(); ++i) {
551 ExtensionProcessManager* epm = profiles[i]->GetExtensionProcessManager();
552 for (ExtensionProcessManager::const_iterator iter = epm->begin();
553 iter != epm->end();
554 ++iter) {
555 ExtensionHost* host = *iter;
556 if (host->extension()->has_background_page()) {
557 process_ids.insert(host->render_process_host()->GetID());
558 }
559 }
560 }
561
562 if (process_ids.size() >
563 (max_process_count * chrome::kMaxShareOfExtensionProcesses)) {
564 return true;
565 }
566
567 return false;
568}
569
[email protected]6f371442011-11-09 06:45:46570void ChromeContentBrowserClient::SiteInstanceGotProcess(
571 SiteInstance* site_instance) {
572 CHECK(site_instance->HasProcess());
573
574 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02575 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46576 ExtensionService* service = profile->GetExtensionService();
577 if (!service)
578 return;
579
580 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44581 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33582 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46583 if (!extension)
584 return;
585
[email protected]6bc04fd82011-12-04 02:29:35586 service->process_map()->Insert(extension->id(),
587 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33588 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46589 BrowserThread::PostTask(
590 BrowserThread::IO, FROM_HERE,
591 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
[email protected]9cf1c2d42012-03-03 06:42:27592 profile->GetExtensionInfoMap(),
[email protected]6f371442011-11-09 06:45:46593 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35594 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33595 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46596}
597
598void ChromeContentBrowserClient::SiteInstanceDeleting(
599 SiteInstance* site_instance) {
600 if (!site_instance->HasProcess())
601 return;
602
603 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02604 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46605 ExtensionService* service = profile->GetExtensionService();
606 if (!service)
607 return;
608
609 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44610 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33611 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46612 if (!extension)
613 return;
614
[email protected]6bc04fd82011-12-04 02:29:35615 service->process_map()->Remove(extension->id(),
616 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33617 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46618 BrowserThread::PostTask(
619 BrowserThread::IO, FROM_HERE,
620 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
[email protected]9cf1c2d42012-03-03 06:42:27621 profile->GetExtensionInfoMap(),
[email protected]6f371442011-11-09 06:45:46622 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35623 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33624 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46625}
626
[email protected]e3daf3c2011-10-05 21:17:08627bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
628 const GURL& current_url,
629 const GURL& new_url) {
630 if (current_url.is_empty()) {
631 // Always choose a new process when navigating to extension URLs. The
632 // process grouping logic will combine all of a given extension's pages
633 // into the same process.
634 if (new_url.SchemeIs(chrome::kExtensionScheme))
635 return true;
636
637 return false;
638 }
639
640 // Also, we must switch if one is an extension and the other is not the exact
641 // same extension.
642 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
643 new_url.SchemeIs(chrome::kExtensionScheme)) {
644 if (current_url.GetOrigin() != new_url.GetOrigin())
645 return true;
646 }
647
648 return false;
649}
650
[email protected]763ec4ca2011-04-29 15:48:12651std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
652 const std::string& alias_name) {
653 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
654}
655
[email protected]b80f68432011-05-02 17:22:30656void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
657 CommandLine* command_line, int child_process_id) {
658#if defined(USE_LINUX_BREAKPAD)
659 if (IsCrashReporterEnabled()) {
660 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
661 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
662 }
663#elif defined(OS_MACOSX)
664 if (IsCrashReporterEnabled()) {
665 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
666 child_process_logging::GetClientId());
667 }
668#endif // OS_MACOSX
669
[email protected]f1933792011-06-14 00:49:34670 if (logging::DialogsAreSuppressed())
671 command_line->AppendSwitch(switches::kNoErrorDialogs);
672
[email protected]b80f68432011-05-02 17:22:30673 std::string process_type =
674 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17675 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52676 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30677 FilePath user_data_dir =
678 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
679 if (!user_data_dir.empty())
680 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
681#if defined(OS_CHROMEOS)
682 const std::string& login_profile =
683 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
684 if (!login_profile.empty())
685 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
686#endif
687
[email protected]f3b1a082011-11-18 00:34:30688 content::RenderProcessHost* process =
689 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37690 if (process) {
691 Profile* profile = Profile::FromBrowserContext(
692 process->GetBrowserContext());
693 extensions::ProcessMap* process_map =
694 profile->GetExtensionService()->process_map();
695 if (process_map && process_map->Contains(process->GetID()))
696 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30697
[email protected]a8d851f82011-12-21 00:32:37698 PrefService* prefs = profile->GetPrefs();
699 // Currently this pref is only registered if applied via a policy.
700 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
701 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
702 // Turn this policy into a command line switch.
703 command_line->AppendSwitch(switches::kDisable3DAPIs);
704 }
[email protected]718eab62011-10-05 21:16:52705
[email protected]a8d851f82011-12-21 00:32:37706 // Disable client-side phishing detection in the renderer if it is
707 // disabled in the Profile preferences or the browser process.
708 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
709 !g_browser_process->safe_browsing_detection_service()) {
710 command_line->AppendSwitch(
711 switches::kDisableClientSidePhishingDetection);
712 }
[email protected]8c40da62011-07-13 22:58:46713 }
[email protected]47c7ec82012-01-18 03:29:21714 {
715 PrefService* local_state = g_browser_process->local_state();
716 if (local_state &&
717 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
718 command_line->AppendSwitch(switches::kRendererPrintPreview);
719 }
720 }
[email protected]4287a3d2011-06-13 23:56:51721
[email protected]47c7ec82012-01-18 03:29:21722 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51723 static const char* const kSwitchNames[] = {
724 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48725 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51726 switches::kAllowScriptingGallery,
727 switches::kAppsCheckoutURL,
728 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31729 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51730 switches::kDebugPrint,
[email protected]382fb0d2012-02-25 00:19:50731 switches::kDisableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51732 switches::kDumpHistogramsOnExit,
[email protected]b7e44ff2012-02-16 03:37:34733 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21734 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13735 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51736 switches::kEnableCrxlessWebApps,
737 switches::kEnableExperimentalExtensionApis,
738 switches::kEnableInBrowserThumbnailing,
739 switches::kEnableIPCFuzzing,
740 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:48741 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53742 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51743 switches::kEnableWatchdog,
744 switches::kExperimentalSpellcheckerFeatures,
745 switches::kMemoryProfiling,
746 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04747 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51748 switches::kPpapiFlashArgs,
749 switches::kPpapiFlashInProcess,
750 switches::kPpapiFlashPath,
751 switches::kPpapiFlashVersion,
752 switches::kProfilingAtStart,
753 switches::kProfilingFile,
754 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51755 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38756 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51757 };
758
759 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
760 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17761 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38762 static const char* const kSwitchNames[] = {
763 switches::kEnableExperimentalExtensionApis,
764 switches::kWhitelistedExtensionID,
765 };
766
767 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
768 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51769 } else if (process_type == switches::kPluginProcess) {
770 static const char* const kSwitchNames[] = {
771 #if defined(OS_CHROMEOS)
772 switches::kLoginProfile,
773 #endif
774 switches::kMemoryProfiling,
775 switches::kSilentDumpOnDCHECK,
776 switches::kUserDataDir,
777 };
778
779 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
780 arraysize(kSwitchNames));
781 } else if (process_type == switches::kZygoteProcess) {
782 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51783 switches::kUserDataDir, // Make logs go to the right file.
784 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]382fb0d2012-02-25 00:19:50785 switches::kDisableBundledPpapiFlash,
[email protected]b50368b2012-02-18 00:02:13786 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51787 switches::kPpapiFlashInProcess,
788 switches::kPpapiFlashPath,
789 switches::kPpapiFlashVersion,
790 };
791
792 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
793 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11794 } else if (process_type == switches::kGpuProcess) {
795 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
796 // because GPU is expected to be unreliable.
797 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
798 !command_line->HasSwitch(switches::kDisableBreakpad))
799 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30800 }
[email protected]6f08af82011-09-15 01:19:03801
802 // The command line switch kEnableBenchmarking needs to be specified along
803 // with the kEnableStatsTable switch to ensure that the stats table global
804 // is initialized correctly.
805 if (command_line->HasSwitch(switches::kEnableBenchmarking))
806 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30807}
808
809std::string ChromeContentBrowserClient::GetApplicationLocale() {
810 return g_browser_process->GetApplicationLocale();
811}
812
[email protected]597a867b2011-11-18 18:31:20813std::string ChromeContentBrowserClient::GetAcceptLangs(
814 content::BrowserContext* context) {
815 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37816 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08817}
818
[email protected]ac55e292011-06-24 05:16:08819SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22820 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08821 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
822}
823
[email protected]a2176792011-05-08 19:30:49824bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09825 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19826 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20827 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32828 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20829 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05830 return io_data->GetCookieSettings()->
831 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49832}
833
[email protected]ed24fad2011-05-10 22:44:01834bool ChromeContentBrowserClient::AllowGetCookie(
835 const GURL& url,
836 const GURL& first_party,
837 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20838 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01839 int render_process_id,
840 int render_view_id) {
841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20842 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05843 bool allow = io_data->GetCookieSettings()->
844 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01845
[email protected]8093a542011-05-13 07:29:32846 BrowserThread::PostTask(
847 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03848 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
849 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01850 return allow;
851}
852
853bool ChromeContentBrowserClient::AllowSetCookie(
854 const GURL& url,
855 const GURL& first_party,
856 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20857 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01858 int render_process_id,
859 int render_view_id,
860 net::CookieOptions* options) {
861 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20862 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05863 CookieSettings* cookie_settings = io_data->GetCookieSettings();
864 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
865
866 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09867 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01868
[email protected]8093a542011-05-13 07:29:32869 BrowserThread::PostTask(
870 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03871 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
872 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01873 return allow;
874}
875
[email protected]d5a19162011-06-30 18:51:54876bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20877 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54878 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20879 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26880
881 if (!io_data->clear_local_state_on_exit()->GetValue())
882 return true;
883
[email protected]068b7b52012-02-27 12:41:44884 // Disable clearing the local state on exit if the browsing session is going
[email protected]1848cdc2012-02-17 10:48:26885 // to be restored on the next startup.
886 SessionStartupPref::Type startup_pref =
887 SessionStartupPref::PrefValueToType(
888 io_data->session_startup_pref()->GetValue());
889 return (startup_pref == SessionStartupPref::LAST &&
[email protected]068b7b52012-02-27 12:41:44890 !CommandLine::ForCurrentProcess()->HasSwitch(
891 switches::kDisableRestoreSessionState));
[email protected]d5a19162011-06-30 18:51:54892}
893
[email protected]5c5a88e2011-11-12 00:45:35894bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35895 const GURL& url,
896 const string16& name,
897 const string16& display_name,
898 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20899 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48900 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35901 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20902 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35903 CookieSettings* cookie_settings = io_data->GetCookieSettings();
904 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
905
[email protected]62151052012-02-01 18:40:48906 // Record access to database for potential display in UI.
907 std::vector<std::pair<int, int> >::const_iterator i;
908 for (i = render_views.begin(); i != render_views.end(); ++i) {
909 BrowserThread::PostTask(
910 BrowserThread::UI, FROM_HERE,
911 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
912 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35913 }
914
915 return allow;
916}
917
918bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35919 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20920 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48921 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35922 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20923 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35924 CookieSettings* cookie_settings = io_data->GetCookieSettings();
925 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
926
[email protected]62151052012-02-01 18:40:48927 // Record access to file system for potential display in UI.
928 std::vector<std::pair<int, int> >::const_iterator i;
929 for (i = render_views.begin(); i != render_views.end(); ++i) {
930 BrowserThread::PostTask(
931 BrowserThread::UI, FROM_HERE,
932 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
933 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35934 }
935
936 return allow;
937}
938
[email protected]7c5ff9a2012-03-02 07:42:49939bool ChromeContentBrowserClient::AllowWorkerIndexedDB(
940 const GURL& url,
941 const string16& name,
942 content::ResourceContext* context,
943 const std::vector<std::pair<int, int> >& render_views) {
944 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
945 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
946 CookieSettings* cookie_settings = io_data->GetCookieSettings();
947 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
948
949 // Record access to IndexedDB for potential display in UI.
950 std::vector<std::pair<int, int> >::const_iterator i;
951 for (i = render_views.begin(); i != render_views.end(); ++i) {
952 BrowserThread::PostTask(
953 BrowserThread::UI, FROM_HERE,
954 base::Bind(&TabSpecificContentSettings::IndexedDBAccessed,
955 i->first, i->second, url, name, !allow));
956 }
957
958 return allow;
959}
960
[email protected]6133f922011-07-01 21:34:34961net::URLRequestContext*
962ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20963 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34964 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
965 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20966 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34967 return io_data->extensions_request_context();
968 }
969
970 return NULL;
971}
972
[email protected]317f96c92011-05-31 06:53:41973QuotaPermissionContext*
974ChromeContentBrowserClient::CreateQuotaPermissionContext() {
975 return new ChromeQuotaPermissionContext();
976}
977
[email protected]a0ce3282011-08-19 20:49:52978void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42979 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42980}
981
[email protected]a0ce3282011-08-19 20:49:52982void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52983 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52984}
985
[email protected]848dd042011-06-04 18:24:03986void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:17987 int render_process_id,
988 int render_view_id,
989 int cert_error,
990 const net::SSLInfo& ssl_info,
991 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:03992 bool overridable,
[email protected]4cf611e32012-02-13 16:06:17993 const base::Callback<void(bool)>& callback,
994 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:41995 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:13996 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:17997 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:41998 if (!tab) {
999 NOTREACHED();
1000 return;
1001 }
1002 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:501003 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:301004 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:091005 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:411006 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:171007 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:411008 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:171009 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:411010 return;
1011 }
1012 }
1013
1014 // Otherwise, display an SSL blocking page.
[email protected]4cf611e32012-02-13 16:06:171015 new SSLBlockingPage(
1016 tab, cert_error, ssl_info, request_url, overridable, callback);
[email protected]848dd042011-06-04 18:24:031017}
1018
[email protected]c99c442e2011-08-24 11:37:301019void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:451020 int render_process_id,
1021 int render_view_id,
[email protected]7a593db2012-02-13 21:19:401022 const net::HttpNetworkSession* network_session,
1023 net::SSLCertRequestInfo* cert_request_info,
1024 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:131025 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:451026 render_process_id, render_view_id);
1027 if (!tab) {
1028 NOTREACHED();
1029 return;
1030 }
1031
[email protected]6786bf402011-12-03 15:19:451032 GURL requesting_url("https://" + cert_request_info->host_and_port);
1033 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
1034 << cert_request_info->host_and_port;
1035
[email protected]627e0512011-12-21 22:55:301036 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:451037 scoped_ptr<Value> filter(
1038 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
1039 requesting_url,
1040 requesting_url,
1041 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
1042 std::string(), NULL));
1043
1044 if (filter.get()) {
1045 // Try to automatically select a client certificate.
1046 if (filter->IsType(Value::TYPE_DICTIONARY)) {
1047 DictionaryValue* filter_dict =
1048 static_cast<DictionaryValue*>(filter.get());
1049
1050 const std::vector<scoped_refptr<net::X509Certificate> >&
1051 all_client_certs = cert_request_info->client_certs;
1052 for (size_t i = 0; i < all_client_certs.size(); ++i) {
1053 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
1054 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:401055 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:451056 return;
1057 }
1058 }
1059 } else {
1060 NOTREACHED();
1061 }
1062 }
1063
[email protected]8ec26472011-06-06 16:52:451064 TabContentsWrapper* wrapper =
1065 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:451066 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:131067 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:451068 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:141069 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:401070 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:451071 return;
1072 }
[email protected]7a593db2012-02-13 21:19:401073 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
1074 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:451075}
1076
1077void ChromeContentBrowserClient::AddNewCertificate(
1078 net::URLRequest* request,
1079 net::X509Certificate* cert,
1080 int render_process_id,
1081 int render_view_id) {
1082 // The handler will run the UI and delete itself when it's finished.
1083 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1084}
1085
[email protected]a93670ab2012-02-24 03:46:391086void ChromeContentBrowserClient::RequestMediaAccessPermission(
1087 const content::MediaStreamRequest* request,
1088 const content::MediaResponseCallback& callback) {
1089 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1090
[email protected]117b6b42012-02-29 09:11:081091 WebContents* contents = tab_util::GetWebContentsByID(
1092 request->render_process_id, request->render_view_id);
1093 if (!contents) {
1094 // Abort, if the tab was closed after the request was made but before we
1095 // got to this point.
1096 callback.Run(content::MediaStreamDevices());
1097 return;
1098 }
1099
1100 TabContentsWrapper* tab =
1101 TabContentsWrapper::GetCurrentWrapperForContents(contents);
1102 DCHECK(tab);
1103
1104 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
1105 InfoBarDelegate* old_infobar = NULL;
1106 for (size_t i = 0; i < infobar_helper->infobar_count() && !old_infobar; ++i) {
1107 old_infobar =
1108 infobar_helper->GetInfoBarDelegateAt(i)->AsMediaStreamInfobarDelegate();
1109 }
1110
1111#if defined(TOOLKIT_VIEWS)
1112 InfoBarDelegate* infobar = new MediaStreamInfoBarDelegate(infobar_helper,
1113 request,
1114 callback);
1115 if (old_infobar)
1116 infobar_helper->ReplaceInfoBar(old_infobar, infobar);
1117 else
1118 infobar_helper->AddInfoBar(infobar);
1119#elif defined(OS_LINUX) || defined(OS_MACOSX)
1120 // TODO(macourteau): UI is not implemented yet for Linux and OS X. Fallback to
1121 // the default behaviour and allow access to the first device of each
1122 // requested type.
1123 content::MediaStreamDevices devices;
[email protected]a93670ab2012-02-24 03:46:391124 for (content::MediaStreamDeviceMap::const_iterator it =
1125 request->devices.begin(); it != request->devices.end(); ++it) {
[email protected]6c6415a2012-03-01 17:17:281126 if (!it->second.empty())
1127 devices.push_back(*it->second.begin());
[email protected]a93670ab2012-02-24 03:46:391128 }
1129
[email protected]a93670ab2012-02-24 03:46:391130 callback.Run(devices);
[email protected]117b6b42012-02-29 09:11:081131#endif // TOOLKIT_VIEWS
[email protected]a93670ab2012-02-24 03:46:391132}
1133
[email protected]941623e2011-06-07 23:06:041134void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1135 const GURL& source_origin,
1136 int callback_context,
1137 int render_process_id,
1138 int render_view_id) {
[email protected]5fd2e842012-03-01 00:29:111139#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041140 RenderViewHost* rvh = RenderViewHost::FromID(
1141 render_process_id, render_view_id);
1142 if (!rvh) {
1143 NOTREACHED();
1144 return;
1145 }
1146
[email protected]9f76c1e2012-03-05 15:15:581147 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301148 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041149 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371150 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041151 service->RequestPermission(
1152 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131153 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]5fd2e842012-03-01 00:29:111154#else
1155 NOTIMPLEMENTED();
1156#endif
[email protected]941623e2011-06-07 23:06:041157}
1158
1159WebKit::WebNotificationPresenter::Permission
1160 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021161 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201162 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021163 int render_process_id) {
[email protected]5fd2e842012-03-01 00:29:111164#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201166 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021167 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1168 source_origin, render_process_id,
1169 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041170 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041171
1172 // Fall back to the regular notification preferences, which works on an
1173 // origin basis.
1174 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371175 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041176 WebKit::WebNotificationPresenter::PermissionNotAllowed;
[email protected]5fd2e842012-03-01 00:29:111177#else
1178 return WebKit::WebNotificationPresenter::PermissionAllowed;
1179#endif
[email protected]941623e2011-06-07 23:06:041180}
1181
1182void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171183 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041184 int render_process_id,
1185 int render_view_id,
1186 bool worker) {
[email protected]5fd2e842012-03-01 00:29:111187#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041188 RenderViewHost* rvh = RenderViewHost::FromID(
1189 render_process_id, render_view_id);
1190 if (!rvh) {
1191 NOTREACHED();
1192 return;
1193 }
1194
[email protected]9f76c1e2012-03-05 15:15:581195 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301196 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041197 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371198 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041199 service->ShowDesktopNotification(
1200 params, render_process_id, render_view_id,
1201 worker ? DesktopNotificationService::WorkerNotification :
1202 DesktopNotificationService::PageNotification);
[email protected]5fd2e842012-03-01 00:29:111203#else
1204 NOTIMPLEMENTED();
1205#endif
[email protected]941623e2011-06-07 23:06:041206}
1207
1208void ChromeContentBrowserClient::CancelDesktopNotification(
1209 int render_process_id,
1210 int render_view_id,
1211 int notification_id) {
[email protected]5fd2e842012-03-01 00:29:111212#if defined(ENABLE_NOTIFICATIONS)
[email protected]941623e2011-06-07 23:06:041213 RenderViewHost* rvh = RenderViewHost::FromID(
1214 render_process_id, render_view_id);
1215 if (!rvh) {
1216 NOTREACHED();
1217 return;
1218 }
1219
[email protected]9f76c1e2012-03-05 15:15:581220 content::RenderProcessHost* process = rvh->GetProcess();
[email protected]f3b1a082011-11-18 00:34:301221 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041222 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371223 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041224 service->CancelDesktopNotification(
1225 render_process_id, render_view_id, notification_id);
[email protected]5fd2e842012-03-01 00:29:111226#else
1227 NOTIMPLEMENTED();
1228#endif
[email protected]941623e2011-06-07 23:06:041229}
1230
[email protected]9f3fba52011-06-08 20:37:191231bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]2b751a12012-03-06 03:00:351232 const GURL& opener_url,
[email protected]34eec7ffe32011-11-02 23:49:021233 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191234 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201235 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021236 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1238 // If the opener is trying to create a background window but doesn't have
1239 // the appropriate permission, fail the attempt.
1240 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201241 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]7b54ca02012-03-02 18:06:531242 ExtensionInfoMap* map = io_data->GetExtensionInfoMap();
1243
1244 // If the opener is not allowed to script its background window, then return
1245 // false so that the window.open call returns null. In this case, only
1246 // the manifest is permitted to create a background window.
1247 // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may
1248 // return a recently installed Extension even if this CanCreateWindow call
1249 // was made by an old copy of the page in a normal web process. That's ok,
[email protected]2b751a12012-03-06 03:00:351250 // because the permission check below will still fail. We must use the
1251 // full URL to find hosted apps, though, and not just the origin.
[email protected]7b54ca02012-03-02 18:06:531252 const Extension* extension = map->extensions().GetExtensionOrAppByURL(
[email protected]2b751a12012-03-06 03:00:351253 ExtensionURLInfo(opener_url));
[email protected]7b54ca02012-03-02 18:06:531254 if (extension && !extension->allow_background_js_access())
1255 return false;
1256
1257 return map->SecurityOriginHasAPIPermission(
[email protected]34eec7ffe32011-11-02 23:49:021258 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191259 }
1260 return true;
1261}
1262
1263std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201264 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1266 // Check if it's an extension-created worker, in which case we want to use
1267 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201268 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191269 const Extension* extension =
1270 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1271 return extension ? extension->name() : std::string();
1272}
1273
[email protected]99907362012-01-11 05:41:401274void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1275 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171276}
1277
[email protected]c52b2892012-03-07 11:01:021278content::SpeechRecognitionManagerDelegate*
1279 ChromeContentBrowserClient::GetSpeechRecognitionManagerDelegate() {
1280 return new speech::ChromeSpeechRecognitionManagerDelegate();
[email protected]66cfec62012-02-24 17:57:511281}
1282
[email protected]3cb054e62011-06-13 05:21:171283ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1284 return g_browser_process->clipboard();
1285}
1286
[email protected]ae6e9912011-07-27 01:18:281287net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1288 return g_browser_process->net_log();
1289}
1290
[email protected]32538d92011-08-25 00:09:231291AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1292 return new ChromeAccessTokenStore();
1293}
1294
[email protected]dbae6b02011-06-29 23:51:411295bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1296 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1297 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1298}
1299
[email protected]64d69de42012-02-06 00:19:541300void ChromeContentBrowserClient::OverrideWebkitPrefs(
[email protected]2e21fe292012-03-02 22:52:321301 RenderViewHost* rvh, const GURL& url, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061302 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581303 rvh->GetProcess()->GetBrowserContext());
[email protected]f3986f82012-01-03 20:00:061304 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061305
[email protected]64d69de42012-02-06 00:19:541306 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061307 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541308 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061309 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541310 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061311 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541312 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061313 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541314 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061315 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541316 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061317 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1318
1319 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541320 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061321 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541322 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061323 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541324 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061325 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541326 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061327 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541328 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061329 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541330 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061331
[email protected]64d69de42012-02-06 00:19:541332 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061333 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541334 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061335 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541336 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061337 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541338 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061339 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1340
[email protected]64d69de42012-02-06 00:19:541341 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061342
[email protected]64d69de42012-02-06 00:19:541343 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061344 prefs->GetBoolean(
1345 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541346 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061347 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541348 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061349 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1350 const DictionaryValue* inspector_settings =
1351 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1352 if (inspector_settings) {
1353 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1354 iter != inspector_settings->end_keys(); ++iter) {
1355 std::string value;
1356 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541357 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061358 std::make_pair(*iter, value));
1359 }
1360 }
[email protected]64d69de42012-02-06 00:19:541361 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061362
[email protected]64d69de42012-02-06 00:19:541363 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1364 web_prefs->javascript_enabled = false;
1365 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1366 web_prefs->web_security_enabled = false;
1367 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1368 web_prefs->plugins_enabled = false;
1369 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1370 web_prefs->java_enabled = false;
1371 web_prefs->loads_images_automatically =
1372 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061373
[email protected]64d69de42012-02-06 00:19:541374 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1375 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061376
[email protected]64d69de42012-02-06 00:19:541377 web_prefs->memory_info_enabled =
1378 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1379 web_prefs->allow_displaying_insecure_content =
1380 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1381 web_prefs->allow_running_insecure_content =
1382 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]9d06d88d2012-02-23 22:37:081383 web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled;
[email protected]f3986f82012-01-03 20:00:061384
[email protected]64d69de42012-02-06 00:19:541385 // The user stylesheet watcher may not exist in a testing profile.
1386 if (profile->GetUserStyleSheetWatcher()) {
1387 web_prefs->user_style_sheet_enabled = true;
1388 web_prefs->user_style_sheet_location =
1389 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1390 } else {
1391 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061392 }
1393
[email protected]b7e44ff2012-02-16 03:37:341394 web_prefs->asynchronous_spell_checking_enabled =
1395 CommandLine::ForCurrentProcess()->
1396 HasSwitch(switches::kEnableAsynchronousSpellChecking);
1397 web_prefs->unified_textchecker_enabled =
1398 web_prefs->asynchronous_spell_checking_enabled ||
1399 CommandLine::ForCurrentProcess()->
1400 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571401
[email protected]64d69de42012-02-06 00:19:541402 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061403 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541404 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061405 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541406 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061407 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1408
1409 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541410 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061411 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541412 web_prefs->default_encoding);
1413 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061414 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541415 web_prefs->default_encoding =
1416 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061417 }
[email protected]64d69de42012-02-06 00:19:541418 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061419
1420 ExtensionService* service = profile->GetExtensionService();
1421 if (service) {
1422 const Extension* extension = service->extensions()->GetByID(
[email protected]9f76c1e2012-03-05 15:15:581423 rvh->GetSiteInstance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061424 extension_webkit_preferences::SetPreferences(
[email protected]9f76c1e2012-03-05 15:15:581425 extension, rvh->GetDelegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061426 }
1427
[email protected]9f76c1e2012-03-05 15:15:581428 if (rvh->GetDelegate()->GetRenderViewType() ==
1429 chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541430 web_prefs->allow_scripts_to_close_windows = true;
[email protected]9f76c1e2012-03-05 15:15:581431 } else if (rvh->GetDelegate()->GetRenderViewType() ==
[email protected]f3986f82012-01-03 20:00:061432 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1433 // Disable all kinds of acceleration for background pages.
1434 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541435 web_prefs->force_compositing_mode = false;
1436 web_prefs->accelerated_compositing_enabled = false;
1437 web_prefs->accelerated_2d_canvas_enabled = false;
1438 web_prefs->accelerated_video_enabled = false;
1439 web_prefs->accelerated_painting_enabled = false;
1440 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061441 }
[email protected]2e21fe292012-03-02 22:52:321442
1443#if defined(FILE_MANAGER_EXTENSION)
1444 // Override the default of suppressing HW compositing for WebUI pages for the
1445 // file manager, which is implemented using WebUI but wants HW acceleration
1446 // for video decode & render.
1447 if (url.spec() == chrome::kChromeUIFileManagerURL) {
1448 web_prefs->accelerated_compositing_enabled = true;
1449 web_prefs->accelerated_2d_canvas_enabled = true;
1450 }
1451#endif
[email protected]181a95ee2011-07-12 19:26:361452}
1453
1454void ChromeContentBrowserClient::UpdateInspectorSetting(
1455 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061456 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581457 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061458 DictionaryPrefUpdate update(
1459 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1460 prefs::kWebKitInspectorSettings);
1461 DictionaryValue* inspector_settings = update.Get();
1462 inspector_settings->SetWithoutPathExpansion(key,
1463 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361464}
1465
1466void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061467 content::BrowserContext* browser_context =
[email protected]9f76c1e2012-03-05 15:15:581468 rvh->GetProcess()->GetBrowserContext();
[email protected]f3986f82012-01-03 20:00:061469 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1470 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361471}
1472
[email protected]b8148ac2011-07-13 22:03:251473void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1474 BrowserURLHandler* handler) {
1475 // Add the default URL handlers.
1476 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1477 BrowserURLHandler::null_handler());
1478 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1479 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1480
[email protected]b3adbd02011-11-30 22:23:271481 // about: handler. Must come before chrome: handler, since it will
1482 // rewrite about: urls to chrome: URLs and then expect chrome: to
1483 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251484 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1485 BrowserURLHandler::null_handler());
1486 // chrome: & friends.
1487 handler->AddHandlerPair(&HandleWebUI,
1488 BrowserURLHandler::null_handler());
1489}
1490
1491void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371492 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581493 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251494 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1495 BrowsingDataRemover::EVERYTHING,
1496 base::Time());
1497 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1498 // BrowsingDataRemover takes care of deleting itself when done.
1499}
1500
1501void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371502 Profile* profile = Profile::FromBrowserContext(
[email protected]9f76c1e2012-03-05 15:15:581503 rvh->GetSiteInstance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251504 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1505 BrowsingDataRemover::EVERYTHING,
1506 base::Time());
[email protected]dceaa912011-09-06 17:17:231507 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251508 remover->Remove(remove_mask);
1509 // BrowsingDataRemover takes care of deleting itself when done.
1510}
1511
[email protected]e1d16eb92011-08-18 23:19:321512FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1513 return download_util::GetDefaultDownloadDirectory();
1514}
1515
[email protected]c9b6eb62011-10-18 20:49:391516std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1517 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1518}
1519
[email protected]a658d452012-03-02 12:45:291520bool ChromeContentBrowserClient::AllowSocketAPI(
1521 content::BrowserContext* browser_context, const GURL& url) {
1522 if (!url.is_valid())
1523 return false;
1524
1525 std::string host = url.host();
1526 if (allowed_socket_origins_.count(host))
1527 return true;
1528
1529 Profile* profile = Profile::FromBrowserContext(browser_context);
1530 if (!profile || !profile->GetExtensionService())
1531 return false;
1532
1533 const Extension* extension = profile->GetExtensionService()->extensions()->
1534 GetExtensionOrAppByURL(ExtensionURLInfo(url));
1535 if (!extension)
1536 return false;
1537
1538 if (extension->HasAPIPermission(ExtensionAPIPermission::kSocket))
1539 return true;
1540
1541 return false;
[email protected]e461da2f2012-02-16 19:06:401542}
1543
[email protected]e60c0232011-11-11 19:56:351544#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301545int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521546 const CommandLine& command_line) {
[email protected]6e677a342012-02-11 01:21:141547#if defined(OS_ANDROID)
1548 // TODO(carlosvaldivia): Upstream breakpad code for Android and remove this
1549 // fork. http://crbug.com/113560
1550 NOTIMPLEMENTED();
1551#else
[email protected]718eab62011-10-05 21:16:521552 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071553 ExtensionCrashHandlerHostLinux* crash_handler =
1554 ExtensionCrashHandlerHostLinux::GetInstance();
1555 return crash_handler->GetDeathSignalSocket();
1556 }
1557
[email protected]718eab62011-10-05 21:16:521558 std::string process_type =
1559 command_line.GetSwitchValueASCII(switches::kProcessType);
1560
1561 if (process_type == switches::kRendererProcess)
1562 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1563
[email protected]b80f68432011-05-02 17:22:301564 if (process_type == switches::kPluginProcess)
1565 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1566
1567 if (process_type == switches::kPpapiPluginProcess)
1568 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1569
1570 if (process_type == switches::kGpuProcess)
1571 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
[email protected]6e677a342012-02-11 01:21:141572#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:301573
1574 return -1;
1575}
[email protected]e60c0232011-11-11 19:56:351576#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301577
[email protected]4a65826d2011-08-25 16:04:011578#if defined(OS_WIN)
1579const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1580 return chrome::kBrowserResourcesDll;
1581}
1582#endif
1583
[email protected]37a72af2011-06-13 05:42:011584#if defined(USE_NSS)
1585crypto::CryptoModuleBlockingPasswordDelegate*
1586 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1587 const GURL& url) {
1588 return browser::NewCryptoModuleBlockingDialogDelegate(
1589 browser::kCryptoModulePasswordKeygen, url.host());
1590}
1591#endif
1592
[email protected]d977f9c2011-03-14 16:10:261593} // namespace chrome