blob: 301377cee18baf2de2740e26a823dff7351c7ddd [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>
8#include <vector>
9
[email protected]317c58f02011-11-09 02:15:0310#include "base/bind.h"
[email protected]b80f68432011-05-02 17:22:3011#include "base/command_line.h"
[email protected]f3986f82012-01-03 20:00:0612#include "base/utf_string_conversions.h"
[email protected]b80f68432011-05-02 17:22:3013#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:2514#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3015#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2316#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1217#include "chrome/browser/character_encoding.h"
[email protected]6f08af82011-09-15 01:19:0318#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]97e6c4c2011-05-18 16:08:5119#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4120#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]edece212011-11-16 11:56:5621#include "chrome/browser/content_settings/content_settings_utils.h"
[email protected]30fde822011-10-28 09:49:0522#include "chrome/browser/content_settings/cookie_settings.h"
[email protected]6786bf402011-12-03 15:19:4523#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3224#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]e1d16eb92011-08-18 23:19:3225#include "chrome/browser/download/download_util.h"
[email protected]941623e2011-06-07 23:06:0426#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1027#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2628#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2529#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0630#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]39a5b532011-10-22 01:47:0731#include "chrome/browser/extensions/extension_webrequest_api.h"
[email protected]32538d92011-08-25 00:09:2332#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1233#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2834#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0435#include "chrome/browser/notifications/desktop_notification_service.h"
36#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4237#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1238#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0639#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4140#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5041#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4142#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1443#include "chrome/browser/printing/printing_message_filter.h"
44#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3245#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1446#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3347#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4248#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1449#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0450#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4651#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4552#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0353#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3654#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4555#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
56#include "chrome/browser/tab_contents/tab_util.h"
57#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5658#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]f3986f82012-01-03 20:00:0659#include "chrome/browser/user_style_sheet_watcher.h"
[email protected]b80f68432011-05-02 17:22:3060#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0161#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3062#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0463#include "chrome/common/extensions/extension.h"
[email protected]615d88f2011-12-13 01:47:4464#include "chrome/common/extensions/extension_set.h"
[email protected]f1933792011-06-14 00:49:3465#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1266#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3867#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0968#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2569#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0970#include "content/browser/browsing_instance.h"
[email protected]f3986f82012-01-03 20:00:0671#include "content/browser/child_process_security_policy.h"
72#include "content/browser/gpu/gpu_data_manager.h"
73#include "content/browser/gpu/gpu_process_host.h"
[email protected]97e6c4c2011-05-18 16:08:5174#include "content/browser/plugin_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2675#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4976#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0977#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4178#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4579#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1280#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3281#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3682#include "content/browser/worker_host/worker_process_host.h"
[email protected]b48c9182011-10-26 18:03:3083#include "content/public/browser/browser_main_parts.h"
[email protected]f3b1a082011-11-18 00:34:3084#include "content/public/browser/render_process_host.h"
[email protected]c9b6eb62011-10-18 20:49:3985#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3486#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0187#include "net/base/cookie_monster.h"
88#include "net/base/cookie_options.h"
[email protected]f3986f82012-01-03 20:00:0689#include "net/base/network_change_notifier.h"
[email protected]c9b6eb62011-10-18 20:49:3990#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0891#include "ui/base/resource/resource_bundle.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]9bce7772011-11-16 01:24:45126#include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h"
[email protected]74313b42011-08-24 16:51:32127#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
128#elif defined(OS_MACOSX)
129#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:32130#endif
131
[email protected]37a72af2011-06-13 05:42:01132#if defined(USE_NSS)
133#include "chrome/browser/ui/crypto_module_password_dialog.h"
134#endif
135
[email protected]c8c77182011-12-21 15:04:47136using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39137using content::BrowserThread;
[email protected]83ff91c2012-01-05 20:54:13138using content::WebContents;
[email protected]631bb742011-11-02 11:29:39139
[email protected]c5dbef02011-05-13 05:06:09140namespace {
141
[email protected]b8148ac2011-07-13 22:03:25142// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42143bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]3d7474ff2011-07-27 17:47:37144 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25145 return false;
146
147 // Special case the new tab page. In older versions of Chrome, the new tab
148 // page was hosted at chrome-internal:<blah>. This might be in people's saved
149 // sessions or bookmarks, so we say any URL with that scheme triggers the new
150 // tab page.
151 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
152 // Rewrite it with the proper new tab URL.
153 *url = GURL(chrome::kChromeUINewTabURL);
154 }
155
156 return true;
157}
158
[email protected]8d3132f62011-10-12 07:13:42159// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
160// below. Extension, and isolated apps require different privileges to be
161// granted to their RenderProcessHosts. This classification allows us to make
162// sure URLs are served by hosts with the right set of privileges.
163enum RenderProcessHostPrivilege {
164 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45165 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42166 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45167 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42168};
169
170RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
171 const GURL& url,
172 ExtensionService* service) {
173 // Default to a normal renderer cause it is lower privileged. This should only
174 // occur if the URL on a site instance is either malformed, or uninitialized.
175 // If it is malformed, then there is no need for better privileges anyways.
176 // If it is uninitialized, but eventually settles on being an a scheme other
177 // than normal webrenderer, the navigation logic will correct us out of band
178 // anyways.
179 if (!url.is_valid())
180 return PRIV_NORMAL;
181
182 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44183 const Extension* extension =
184 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45185 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42186 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45187 if (extension && extension->is_hosted_app())
188 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42189
190 return PRIV_EXTENSION;
191 }
192
193 return PRIV_NORMAL;
194}
195
196RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30197 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46198 extensions::ProcessMap* process_map,
199 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46200 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30201 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46202 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21203 return PRIV_NORMAL;
204
[email protected]6f371442011-11-09 06:45:46205 for (std::set<std::string>::iterator iter = extension_ids.begin();
206 iter != extension_ids.end(); ++iter) {
207 const Extension* extension = service->GetExtensionById(*iter, false);
208 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42209 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45210 if (extension && extension->is_hosted_app())
211 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42212 }
213
[email protected]676f6ab2011-10-19 20:23:21214 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42215}
216
[email protected]eec0b33c2011-12-05 22:09:45217bool IsIsolatedAppInProcess(const GURL& site_url,
218 content::RenderProcessHost* process_host,
219 extensions::ProcessMap* process_map,
220 ExtensionService* service) {
221 std::set<std::string> extension_ids =
222 process_map->GetExtensionsInProcess(process_host->GetID());
223 if (extension_ids.empty())
224 return false;
225
226 for (std::set<std::string>::iterator iter = extension_ids.begin();
227 iter != extension_ids.end(); ++iter) {
228 const Extension* extension = service->GetExtensionById(*iter, false);
229 if (extension &&
230 extension->is_storage_isolated() &&
231 extension->url() == site_url)
232 return true;
233 }
234
235 return false;
236}
237
[email protected]6786bf402011-12-03 15:19:45238bool CertMatchesFilter(const net::X509Certificate& cert,
239 const base::DictionaryValue& filter) {
240 // TODO(markusheintz): This is the minimal required filter implementation.
241 // Implement a better matcher.
242
243 // An empty filter matches any client certificate since no requirements are
244 // specified at all.
245 if (filter.empty())
246 return true;
247
248 std::string common_name;
249 if (filter.GetString("ISSUER.CN", &common_name) &&
250 (cert.issuer().common_name == common_name)) {
251 return true;
252 }
253 return false;
254}
255
[email protected]f3986f82012-01-03 20:00:06256// Fills |map| with the per-script font prefs under path |map_name|.
257void FillFontFamilyMap(const PrefService* prefs,
258 const char* map_name,
259 WebPreferences::ScriptFontFamilyMap* map) {
260 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
261 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
262 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
263 std::string font_family = prefs->GetString(pref_name.c_str());
264 if (!font_family.empty())
265 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
266 }
267}
268
[email protected]9dbfff12011-07-01 19:37:07269} // namespace
[email protected]c5dbef02011-05-13 05:06:09270
[email protected]d977f9c2011-03-14 16:10:26271namespace chrome {
272
[email protected]50462bf02011-11-21 19:13:31273content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
274 const content::MainFunctionParams& parameters) {
275 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30276 // Construct the Main browser parts based on the OS type.
277#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31278 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04279#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31280 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30281#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31282 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35283#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31284 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]b48c9182011-10-26 18:03:30285#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31286 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04287#else
[email protected]b48c9182011-10-26 18:03:30288 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31289 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30290#endif
291
[email protected]c7480942011-11-08 19:18:27292 // Construct additional browser parts. Stages are called in the order in
293 // which they are added.
[email protected]b48c9182011-10-26 18:03:30294#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31295 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04296#endif
[email protected]c7480942011-11-08 19:18:27297
298#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31299 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27300#endif
301
302#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31303 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27304#endif
305
[email protected]50462bf02011-11-21 19:13:31306 return main_parts;
[email protected]f967b722011-09-07 00:58:04307}
308
[email protected]74313b42011-08-24 16:51:32309TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
310 TabContents* tab_contents) {
[email protected]080f34f2011-09-20 05:39:26311#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32312 return new TabContentsViewViews(tab_contents);
[email protected]c92f4ed2011-10-21 19:50:21313#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45314 return new TabContentsViewGtk(tab_contents,
315 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32316#elif defined(OS_MACOSX)
317 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32318#else
319#error Need to create your platform TabContentsView here.
320#endif
321}
322
[email protected]f364d1392011-04-08 21:03:10323void ChromeContentBrowserClient::RenderViewHostCreated(
324 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46325
326 SiteInstance* site_instance = render_view_host->site_instance();
327 Profile* profile = Profile::FromBrowserContext(
328 site_instance->browsing_instance()->browser_context());
329
330 new ChromeRenderViewHostObserver(render_view_host,
331 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10332 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26333}
334
[email protected]f3b1a082011-11-18 00:34:30335void ChromeContentBrowserClient::RenderProcessHostCreated(
336 content::RenderProcessHost* host) {
337 int id = host->GetID();
338 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
339 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02340 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30341 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
342 host->GetChannel()->AddFilter(new PrintingMessageFilter());
343 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02344 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30345 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56346#if defined(OS_MACOSX)
347 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
348#endif
[email protected]f3b1a082011-11-18 00:34:30349 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03350 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38351
[email protected]2ccf45c2011-08-19 23:35:50352 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
353 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07354
355 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56356
357 RendererContentSettingRules rules;
358 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
359 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14360}
361
[email protected]97e6c4c2011-05-18 16:08:51362void ChromeContentBrowserClient::PluginProcessHostCreated(
363 PluginProcessHost* host) {
[email protected]f6d2a3e2011-11-17 21:42:40364#if !defined(USE_AURA)
[email protected]97e6c4c2011-05-18 16:08:51365 host->AddFilter(new ChromePluginMessageFilter(host));
[email protected]f6d2a3e2011-11-17 21:42:40366#endif
[email protected]97e6c4c2011-05-18 16:08:51367}
368
[email protected]1fd1a502011-03-30 16:55:56369content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
370 return ChromeWebUIFactory::GetInstance();
371}
372
[email protected]3d7474ff2011-07-27 17:47:37373GURL ChromeContentBrowserClient::GetEffectiveURL(
374 content::BrowserContext* browser_context, const GURL& url) {
375 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08376 // Get the effective URL for the given actual URL. If the URL is part of an
377 // installed app, the effective URL is an extension URL with the ID of that
378 // extension as the host. This has the effect of grouping apps together in
379 // a common SiteInstance.
380 if (!profile || !profile->GetExtensionService())
381 return url;
382
[email protected]615d88f2011-12-13 01:47:44383 const Extension* extension = profile->GetExtensionService()->extensions()->
384 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08385 if (!extension)
386 return url;
387
[email protected]15877ca2011-11-18 22:40:52388 // Bookmark apps do not use the hosted app process model, and should be
389 // treated as normal URLs.
390 if (extension->from_bookmark())
391 return url;
392
[email protected]36fb2c7c2011-04-04 15:49:08393 // If the URL is part of an extension's web extent, convert it to an
394 // extension URL.
395 return extension->GetResourceURL(url.path());
396}
397
[email protected]056ad2a2011-07-12 02:13:55398bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37399 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55400 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52401 // Because we expect to use the effective URL, URLs for hosted apps (apart
402 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55403 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
404 return false;
405
[email protected]3d7474ff2011-07-27 17:47:37406 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55407 if (!profile || !profile->GetExtensionService())
408 return false;
409
[email protected]615d88f2011-12-13 01:47:44410 const Extension* extension = profile->GetExtensionService()->extensions()->
411 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55412 if (!extension)
413 return false;
414
415 // If the URL is part of a hosted app that does not have the background
416 // permission, we want to give each instance its own process to improve
417 // responsiveness.
418 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
419 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
420 return false;
421
422 // Hosted apps that have the background permission must use process per site,
423 // since all instances can make synchronous calls to the background window.
424 // Other extensions should use process per site as well.
425 return true;
426}
427
[email protected]0f012df82011-05-19 14:15:29428bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03429 return url == GURL(chrome::kChromeUICrashURL) ||
430 url == GURL(chrome::kChromeUIKillURL) ||
431 url == GURL(chrome::kChromeUIHangURL) ||
432 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29433}
434
[email protected]46fb9442011-12-09 17:57:47435bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
436 return ProfileIOData::IsHandledURL(url);
437}
438
[email protected]2a5221b2011-09-27 23:07:31439bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30440 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31441 const GURL& site_url) {
442 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30443 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42444 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46445 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31446
[email protected]ffa97602011-11-17 17:55:52447 // Don't allow the Task Manager to share a process with anything else.
448 // Otherwise it can affect the renderers it is observing.
449 // Note: we could create another RenderProcessHostPrivilege bucket for
450 // this to allow multiple chrome://tasks instances to share, but that's
451 // a very unlikely case without serious consequences.
452 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
453 return false;
454
[email protected]8d3132f62011-10-12 07:13:42455 // These may be NULL during tests. In that case, just assume any site can
456 // share any host.
[email protected]6f371442011-11-09 06:45:46457 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31458 return true;
459
[email protected]a8c269a2011-10-25 20:17:22460 // Experimental:
461 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
462 // to share a renderer process. (We could allow pages from the same site or
463 // extensions of the same type to share, if we knew what the given process
464 // was dedicated to. Allowing no sharing is simpler for now.) This may
465 // cause resource exhaustion issues if too many sites are open at once.
466 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
467 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
468 return false;
469
[email protected]eec0b33c2011-12-05 22:09:45470 // An isolated app is only allowed to share with the exact same app in order
471 // to provide complete renderer process isolation. This also works around
472 // issue http://crbug.com/85588, where different isolated apps in the same
473 // process would end up using the first app's storage contexts.
474 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42475 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45476 if (privilege_required == PRIV_ISOLATED)
477 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
478
479 // Otherwise, just make sure the process privilege matches the privilege
480 // required by the site.
481 return GetProcessPrivilege(process_host, process_map, service) ==
482 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31483}
484
[email protected]6f371442011-11-09 06:45:46485void ChromeContentBrowserClient::SiteInstanceGotProcess(
486 SiteInstance* site_instance) {
487 CHECK(site_instance->HasProcess());
488
489 Profile* profile = Profile::FromBrowserContext(
490 site_instance->browsing_instance()->browser_context());
491 ExtensionService* service = profile->GetExtensionService();
492 if (!service)
493 return;
494
495 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44496 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
497 site_instance->site()));
[email protected]6f371442011-11-09 06:45:46498 if (!extension)
499 return;
500
[email protected]6bc04fd82011-12-04 02:29:35501 service->process_map()->Insert(extension->id(),
502 site_instance->GetProcess()->GetID(),
503 site_instance->id());
[email protected]6f371442011-11-09 06:45:46504 BrowserThread::PostTask(
505 BrowserThread::IO, FROM_HERE,
506 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
507 profile->GetExtensionInfoMap(),
508 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35509 site_instance->GetProcess()->GetID(),
510 site_instance->id()));
[email protected]6f371442011-11-09 06:45:46511}
512
513void ChromeContentBrowserClient::SiteInstanceDeleting(
514 SiteInstance* site_instance) {
515 if (!site_instance->HasProcess())
516 return;
517
518 Profile* profile = Profile::FromBrowserContext(
519 site_instance->browsing_instance()->browser_context());
520 ExtensionService* service = profile->GetExtensionService();
521 if (!service)
522 return;
523
524 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44525 service->extensions()->GetExtensionOrAppByURL(
526 ExtensionURLInfo(site_instance->site()));
[email protected]6f371442011-11-09 06:45:46527 if (!extension)
528 return;
529
[email protected]6bc04fd82011-12-04 02:29:35530 service->process_map()->Remove(extension->id(),
531 site_instance->GetProcess()->GetID(),
532 site_instance->id());
[email protected]6f371442011-11-09 06:45:46533 BrowserThread::PostTask(
534 BrowserThread::IO, FROM_HERE,
535 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
536 profile->GetExtensionInfoMap(),
537 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35538 site_instance->GetProcess()->GetID(),
539 site_instance->id()));
[email protected]6f371442011-11-09 06:45:46540}
541
[email protected]e3daf3c2011-10-05 21:17:08542bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
543 const GURL& current_url,
544 const GURL& new_url) {
545 if (current_url.is_empty()) {
546 // Always choose a new process when navigating to extension URLs. The
547 // process grouping logic will combine all of a given extension's pages
548 // into the same process.
549 if (new_url.SchemeIs(chrome::kExtensionScheme))
550 return true;
551
552 return false;
553 }
554
555 // Also, we must switch if one is an extension and the other is not the exact
556 // same extension.
557 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
558 new_url.SchemeIs(chrome::kExtensionScheme)) {
559 if (current_url.GetOrigin() != new_url.GetOrigin())
560 return true;
561 }
562
563 return false;
564}
565
[email protected]763ec4ca2011-04-29 15:48:12566std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
567 const std::string& alias_name) {
568 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
569}
570
[email protected]b80f68432011-05-02 17:22:30571void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
572 CommandLine* command_line, int child_process_id) {
573#if defined(USE_LINUX_BREAKPAD)
574 if (IsCrashReporterEnabled()) {
575 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
576 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
577 }
578#elif defined(OS_MACOSX)
579 if (IsCrashReporterEnabled()) {
580 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
581 child_process_logging::GetClientId());
582 }
583#endif // OS_MACOSX
584
[email protected]f1933792011-06-14 00:49:34585 if (logging::DialogsAreSuppressed())
586 command_line->AppendSwitch(switches::kNoErrorDialogs);
587
[email protected]b80f68432011-05-02 17:22:30588 std::string process_type =
589 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17590 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52591 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30592 FilePath user_data_dir =
593 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
594 if (!user_data_dir.empty())
595 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
596#if defined(OS_CHROMEOS)
597 const std::string& login_profile =
598 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
599 if (!login_profile.empty())
600 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
601#endif
602
[email protected]f3b1a082011-11-18 00:34:30603 content::RenderProcessHost* process =
604 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37605 if (process) {
606 Profile* profile = Profile::FromBrowserContext(
607 process->GetBrowserContext());
608 extensions::ProcessMap* process_map =
609 profile->GetExtensionService()->process_map();
610 if (process_map && process_map->Contains(process->GetID()))
611 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30612
[email protected]a8d851f82011-12-21 00:32:37613 PrefService* prefs = profile->GetPrefs();
614 // Currently this pref is only registered if applied via a policy.
615 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
616 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
617 // Turn this policy into a command line switch.
618 command_line->AppendSwitch(switches::kDisable3DAPIs);
619 }
[email protected]718eab62011-10-05 21:16:52620
[email protected]a8d851f82011-12-21 00:32:37621 // Disable client-side phishing detection in the renderer if it is
622 // disabled in the Profile preferences or the browser process.
623 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
624 !g_browser_process->safe_browsing_detection_service()) {
625 command_line->AppendSwitch(
626 switches::kDisableClientSidePhishingDetection);
627 }
[email protected]8c40da62011-07-13 22:58:46628 }
[email protected]4287a3d2011-06-13 23:56:51629
630 static const char* const kSwitchNames[] = {
631 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48632 switches::kAllowLegacyExtensionManifests,
[email protected]ef5e98e2011-12-06 09:49:18633 switches::kAllowNaClSocketAPI,
[email protected]4287a3d2011-06-13 23:56:51634 switches::kAllowScriptingGallery,
635 switches::kAppsCheckoutURL,
636 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31637 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51638 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51639 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51640 switches::kDomAutomationController,
641 switches::kDumpHistogramsOnExit,
642 switches::kEnableClickToPlay,
643 switches::kEnableCrxlessWebApps,
644 switches::kEnableExperimentalExtensionApis,
645 switches::kEnableInBrowserThumbnailing,
646 switches::kEnableIPCFuzzing,
[email protected]06024c62011-10-20 20:57:12647 switches::kEnableLazyBackgroundPages,
[email protected]4287a3d2011-06-13 23:56:51648 switches::kEnableNaCl,
[email protected]9776e82e2011-11-15 02:17:53649 switches::kEnablePlatformApps,
[email protected]5714ee32011-08-18 01:51:24650 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51651 switches::kEnableSearchProviderApiV2,
652 switches::kEnableWatchdog,
653 switches::kExperimentalSpellcheckerFeatures,
654 switches::kMemoryProfiling,
655 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04656 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51657 switches::kPpapiFlashArgs,
658 switches::kPpapiFlashInProcess,
659 switches::kPpapiFlashPath,
660 switches::kPpapiFlashVersion,
661 switches::kProfilingAtStart,
662 switches::kProfilingFile,
663 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51664 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03665 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51666 };
667
668 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
669 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17670 } else if (process_type == switches::kUtilityProcess) {
671 if (browser_command_line.HasSwitch(
672 switches::kEnableExperimentalExtensionApis)) {
673 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
674 }
[email protected]4287a3d2011-06-13 23:56:51675 } else if (process_type == switches::kPluginProcess) {
676 static const char* const kSwitchNames[] = {
677 #if defined(OS_CHROMEOS)
678 switches::kLoginProfile,
679 #endif
680 switches::kMemoryProfiling,
681 switches::kSilentDumpOnDCHECK,
682 switches::kUserDataDir,
683 };
684
685 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
686 arraysize(kSwitchNames));
687 } else if (process_type == switches::kZygoteProcess) {
688 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51689 switches::kUserDataDir, // Make logs go to the right file.
690 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
691 switches::kPpapiFlashInProcess,
692 switches::kPpapiFlashPath,
693 switches::kPpapiFlashVersion,
694 };
695
696 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
697 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30698 }
[email protected]6f08af82011-09-15 01:19:03699
700 // The command line switch kEnableBenchmarking needs to be specified along
701 // with the kEnableStatsTable switch to ensure that the stats table global
702 // is initialized correctly.
703 if (command_line->HasSwitch(switches::kEnableBenchmarking))
704 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30705}
706
707std::string ChromeContentBrowserClient::GetApplicationLocale() {
708 return g_browser_process->GetApplicationLocale();
709}
710
[email protected]597a867b2011-11-18 18:31:20711std::string ChromeContentBrowserClient::GetAcceptLangs(
712 content::BrowserContext* context) {
713 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37714 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08715}
716
[email protected]ac55e292011-06-24 05:16:08717SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22718 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08719 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
720}
721
[email protected]a2176792011-05-08 19:30:49722bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09723 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19724 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09725 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
727 ProfileIOData* io_data =
728 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05729 return io_data->GetCookieSettings()->
730 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49731}
732
[email protected]ed24fad2011-05-10 22:44:01733bool ChromeContentBrowserClient::AllowGetCookie(
734 const GURL& url,
735 const GURL& first_party,
736 const net::CookieList& cookie_list,
737 const content::ResourceContext& context,
738 int render_process_id,
739 int render_view_id) {
740 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32741 ProfileIOData* io_data =
742 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]30fde822011-10-28 09:49:05743 bool allow = io_data->GetCookieSettings()->
744 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01745
[email protected]8093a542011-05-13 07:29:32746 BrowserThread::PostTask(
747 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03748 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
749 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01750 return allow;
751}
752
753bool ChromeContentBrowserClient::AllowSetCookie(
754 const GURL& url,
755 const GURL& first_party,
756 const std::string& cookie_line,
757 const content::ResourceContext& context,
758 int render_process_id,
759 int render_view_id,
760 net::CookieOptions* options) {
761 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32762 ProfileIOData* io_data =
763 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]ed24fad2011-05-10 22:44:01764
[email protected]30fde822011-10-28 09:49:05765 CookieSettings* cookie_settings = io_data->GetCookieSettings();
766 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
767
768 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09769 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01770
[email protected]8093a542011-05-13 07:29:32771 BrowserThread::PostTask(
772 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03773 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
774 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01775 return allow;
776}
777
[email protected]d5a19162011-06-30 18:51:54778bool ChromeContentBrowserClient::AllowSaveLocalState(
779 const content::ResourceContext& context) {
780 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
781 ProfileIOData* io_data =
782 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
783 return !io_data->clear_local_state_on_exit()->GetValue();
784}
785
[email protected]5c5a88e2011-11-12 00:45:35786bool ChromeContentBrowserClient::AllowWorkerDatabase(
787 int worker_route_id,
788 const GURL& url,
789 const string16& name,
790 const string16& display_name,
791 unsigned long estimated_size,
792 WorkerProcessHost* worker_process_host) {
793 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
794 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
795 worker_process_host->resource_context()->GetUserData(NULL));
796 CookieSettings* cookie_settings = io_data->GetCookieSettings();
797 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
798
799 // Record access to database for potential display in UI: Find the worker
800 // instance and forward the message to all attached documents.
801 WorkerProcessHost::Instances::const_iterator i;
802 for (i = worker_process_host->instances().begin();
803 i != worker_process_host->instances().end(); ++i) {
804 if (i->worker_route_id() != worker_route_id)
805 continue;
806 const WorkerDocumentSet::DocumentInfoSet& documents =
807 i->worker_document_set()->documents();
808 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
809 documents.begin(); doc != documents.end(); ++doc) {
810 BrowserThread::PostTask(
811 BrowserThread::UI, FROM_HERE,
812 base::Bind(
813 &TabSpecificContentSettings::WebDatabaseAccessed,
814 doc->render_process_id(), doc->render_view_id(),
815 url, name, display_name, !allow));
816 }
817 break;
818 }
819
820 return allow;
821}
822
823bool ChromeContentBrowserClient::AllowWorkerFileSystem(
824 int worker_route_id,
825 const GURL& url,
826 WorkerProcessHost* worker_process_host) {
827 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
828 ProfileIOData* io_data = reinterpret_cast<ProfileIOData*>(
829 worker_process_host->resource_context()->GetUserData(NULL));
830 CookieSettings* cookie_settings = io_data->GetCookieSettings();
831 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
832
833 // Record access to file system for potential display in UI: Find the worker
834 // instance and forward the message to all attached documents.
835 WorkerProcessHost::Instances::const_iterator i;
836 for (i = worker_process_host->instances().begin();
837 i != worker_process_host->instances().end(); ++i) {
838 if (i->worker_route_id() != worker_route_id)
839 continue;
840 const WorkerDocumentSet::DocumentInfoSet& documents =
841 i->worker_document_set()->documents();
842 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc =
843 documents.begin(); doc != documents.end(); ++doc) {
844 BrowserThread::PostTask(
845 BrowserThread::UI, FROM_HERE,
846 base::Bind(
847 &TabSpecificContentSettings::FileSystemAccessed,
848 doc->render_process_id(), doc->render_view_id(), url, !allow));
849 }
850 break;
851 }
852
853 return allow;
854}
855
[email protected]6133f922011-07-01 21:34:34856net::URLRequestContext*
857ChromeContentBrowserClient::OverrideRequestContextForURL(
858 const GURL& url, const content::ResourceContext& context) {
859 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
860 if (url.SchemeIs(chrome::kExtensionScheme)) {
861 ProfileIOData* io_data =
862 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
863 return io_data->extensions_request_context();
864 }
865
866 return NULL;
867}
868
[email protected]317f96c92011-05-31 06:53:41869QuotaPermissionContext*
870ChromeContentBrowserClient::CreateQuotaPermissionContext() {
871 return new ChromeQuotaPermissionContext();
872}
873
[email protected]a0ce3282011-08-19 20:49:52874void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42875 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42876}
877
[email protected]a0ce3282011-08-19 20:49:52878void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52879 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52880}
881
[email protected]848dd042011-06-04 18:24:03882void ChromeContentBrowserClient::AllowCertificateError(
883 SSLCertErrorHandler* handler,
884 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58885 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41886 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:13887 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]f9034cf2011-07-21 12:43:41888 handler->render_process_host_id(),
889 handler->tab_contents_id());
890 if (!tab) {
891 NOTREACHED();
892 return;
893 }
894 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50895 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:30896 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:09897 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:41898 if (prerender_manager->prerender_tracker()->TryCancel(
899 handler->render_process_host_id(),
900 handler->tab_contents_id(),
901 prerender::FINAL_STATUS_SSL_ERROR)) {
902 handler->CancelRequest();
903 return;
904 }
905 }
906
907 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03908 SSLBlockingPage* blocking_page = new SSLBlockingPage(
909 handler, overridable, callback);
910 blocking_page->Show();
911}
912
[email protected]c99c442e2011-08-24 11:37:30913void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45914 int render_process_id,
915 int render_view_id,
916 SSLClientAuthHandler* handler) {
[email protected]83ff91c2012-01-05 20:54:13917 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:45918 render_process_id, render_view_id);
919 if (!tab) {
920 NOTREACHED();
921 return;
922 }
923
[email protected]6786bf402011-12-03 15:19:45924 net::SSLCertRequestInfo* cert_request_info = handler->cert_request_info();
925 GURL requesting_url("https://" + cert_request_info->host_and_port);
926 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
927 << cert_request_info->host_and_port;
928
[email protected]627e0512011-12-21 22:55:30929 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:45930 DCHECK(profile);
931 scoped_ptr<Value> filter(
932 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
933 requesting_url,
934 requesting_url,
935 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
936 std::string(), NULL));
937
938 if (filter.get()) {
939 // Try to automatically select a client certificate.
940 if (filter->IsType(Value::TYPE_DICTIONARY)) {
941 DictionaryValue* filter_dict =
942 static_cast<DictionaryValue*>(filter.get());
943
944 const std::vector<scoped_refptr<net::X509Certificate> >&
945 all_client_certs = cert_request_info->client_certs;
946 for (size_t i = 0; i < all_client_certs.size(); ++i) {
947 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
948 // Use the first certificate that is matched by the filter.
949 handler->CertificateSelected(all_client_certs[i]);
950 return;
951 }
952 }
953 } else {
954 NOTREACHED();
955 }
956 }
957
[email protected]8ec26472011-06-06 16:52:45958 TabContentsWrapper* wrapper =
959 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:45960 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:13961 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:45962 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:14963 // proceed with no client certificate.
[email protected]6786bf402011-12-03 15:19:45964 handler->CertificateSelected(NULL);
965 return;
966 }
967 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
[email protected]8ec26472011-06-06 16:52:45968}
969
970void ChromeContentBrowserClient::AddNewCertificate(
971 net::URLRequest* request,
972 net::X509Certificate* cert,
973 int render_process_id,
974 int render_view_id) {
975 // The handler will run the UI and delete itself when it's finished.
976 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
977}
978
[email protected]941623e2011-06-07 23:06:04979void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
980 const GURL& source_origin,
981 int callback_context,
982 int render_process_id,
983 int render_view_id) {
984 RenderViewHost* rvh = RenderViewHost::FromID(
985 render_process_id, render_view_id);
986 if (!rvh) {
987 NOTREACHED();
988 return;
989 }
990
[email protected]f3b1a082011-11-18 00:34:30991 content::RenderProcessHost* process = rvh->process();
992 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:04993 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37994 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04995 service->RequestPermission(
996 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:13997 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]941623e2011-06-07 23:06:04998}
999
1000WebKit::WebNotificationPresenter::Permission
1001 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021002 const GURL& source_origin,
1003 const content::ResourceContext& context,
1004 int render_process_id) {
[email protected]941623e2011-06-07 23:06:041005 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1006 ProfileIOData* io_data =
1007 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1008
[email protected]34eec7ffe32011-11-02 23:49:021009 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1010 source_origin, render_process_id,
1011 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041012 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041013
1014 // Fall back to the regular notification preferences, which works on an
1015 // origin basis.
1016 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371017 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041018 WebKit::WebNotificationPresenter::PermissionNotAllowed;
1019}
1020
1021void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171022 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041023 int render_process_id,
1024 int render_view_id,
1025 bool worker) {
1026 RenderViewHost* rvh = RenderViewHost::FromID(
1027 render_process_id, render_view_id);
1028 if (!rvh) {
1029 NOTREACHED();
1030 return;
1031 }
1032
[email protected]f3b1a082011-11-18 00:34:301033 content::RenderProcessHost* process = rvh->process();
1034 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041035 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371036 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041037 service->ShowDesktopNotification(
1038 params, render_process_id, render_view_id,
1039 worker ? DesktopNotificationService::WorkerNotification :
1040 DesktopNotificationService::PageNotification);
1041}
1042
1043void ChromeContentBrowserClient::CancelDesktopNotification(
1044 int render_process_id,
1045 int render_view_id,
1046 int notification_id) {
1047 RenderViewHost* rvh = RenderViewHost::FromID(
1048 render_process_id, render_view_id);
1049 if (!rvh) {
1050 NOTREACHED();
1051 return;
1052 }
1053
[email protected]f3b1a082011-11-18 00:34:301054 content::RenderProcessHost* process = rvh->process();
1055 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041056 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371057 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041058 service->CancelDesktopNotification(
1059 render_process_id, render_view_id, notification_id);
1060}
1061
[email protected]9f3fba52011-06-08 20:37:191062bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:021063 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191064 WindowContainerType container_type,
[email protected]34eec7ffe32011-11-02 23:49:021065 const content::ResourceContext& context,
1066 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191067 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1068 // If the opener is trying to create a background window but doesn't have
1069 // the appropriate permission, fail the attempt.
1070 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
1071 ProfileIOData* io_data =
1072 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]34eec7ffe32011-11-02 23:49:021073 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1074 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191075 }
1076 return true;
1077}
1078
1079std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
1080 const GURL& url, const content::ResourceContext& context) {
1081 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1082 // Check if it's an extension-created worker, in which case we want to use
1083 // the name of the extension.
1084 ProfileIOData* io_data =
1085 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
1086 const Extension* extension =
1087 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1088 return extension ? extension->name() : std::string();
1089}
1090
[email protected]3cb054e62011-06-13 05:21:171091ResourceDispatcherHost*
1092 ChromeContentBrowserClient::GetResourceDispatcherHost() {
1093 return g_browser_process->resource_dispatcher_host();
1094}
1095
1096ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1097 return g_browser_process->clipboard();
1098}
1099
[email protected]8f6a3b852011-07-19 16:48:561100MHTMLGenerationManager*
1101 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
1102 return g_browser_process->mhtml_generation_manager();
1103}
1104
[email protected]ae6e9912011-07-27 01:18:281105net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1106 return g_browser_process->net_log();
1107}
1108
[email protected]3bc0b562011-08-24 23:51:041109speech_input::SpeechInputManager*
1110 ChromeContentBrowserClient::GetSpeechInputManager() {
1111 return speech_input::ChromeSpeechInputManager::GetInstance();
1112}
1113
[email protected]32538d92011-08-25 00:09:231114AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1115 return new ChromeAccessTokenStore();
1116}
1117
[email protected]dbae6b02011-06-29 23:51:411118bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1119 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1120 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1121}
1122
[email protected]5092c282011-10-29 21:48:371123WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061124 Profile* profile = Profile::FromBrowserContext(
1125 rvh->process()->GetBrowserContext());
1126 PrefService* prefs = profile->GetPrefs();
1127 WebPreferences web_prefs;
1128
1129 web_prefs.standard_font_family =
1130 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
1131 web_prefs.fixed_font_family =
1132 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
1133 web_prefs.serif_font_family =
1134 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
1135 web_prefs.sans_serif_font_family =
1136 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
1137 web_prefs.cursive_font_family =
1138 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
1139 web_prefs.fantasy_font_family =
1140 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1141
1142 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
1143 &web_prefs.standard_font_family_map);
1144 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
1145 &web_prefs.fixed_font_family_map);
1146 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
1147 &web_prefs.serif_font_family_map);
1148 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
1149 &web_prefs.sans_serif_font_family_map);
1150 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
1151 &web_prefs.cursive_font_family_map);
1152 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
1153 &web_prefs.fantasy_font_family_map);
1154
1155 web_prefs.default_font_size =
1156 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
1157 web_prefs.default_fixed_font_size =
1158 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
1159 web_prefs.minimum_font_size =
1160 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
1161 web_prefs.minimum_logical_font_size =
1162 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1163
1164 web_prefs.default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
1165
1166 web_prefs.javascript_can_open_windows_automatically =
1167 prefs->GetBoolean(
1168 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
1169 web_prefs.dom_paste_enabled =
1170 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
1171 web_prefs.shrinks_standalone_images_to_fit =
1172 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1173 const DictionaryValue* inspector_settings =
1174 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1175 if (inspector_settings) {
1176 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1177 iter != inspector_settings->end_keys(); ++iter) {
1178 std::string value;
1179 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
1180 web_prefs.inspector_settings.push_back(
1181 std::make_pair(*iter, value));
1182 }
1183 }
1184 web_prefs.tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
1185
1186 { // Command line switches are used for preferences with no user interface.
1187 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
1188 web_prefs.developer_extras_enabled = true;
1189 web_prefs.javascript_enabled =
1190 !command_line.HasSwitch(switches::kDisableJavaScript) &&
1191 prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled);
1192 web_prefs.dart_enabled = !command_line.HasSwitch(switches::kDisableDart);
1193 web_prefs.web_security_enabled =
1194 !command_line.HasSwitch(switches::kDisableWebSecurity) &&
1195 prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled);
1196 web_prefs.plugins_enabled =
1197 !command_line.HasSwitch(switches::kDisablePlugins) &&
1198 prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled);
1199 web_prefs.java_enabled =
1200 !command_line.HasSwitch(switches::kDisableJava) &&
1201 prefs->GetBoolean(prefs::kWebKitJavaEnabled);
1202 web_prefs.loads_images_automatically =
1203 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
1204 web_prefs.uses_page_cache =
1205 command_line.HasSwitch(switches::kEnableFastback);
1206 web_prefs.remote_fonts_enabled =
1207 !command_line.HasSwitch(switches::kDisableRemoteFonts);
1208 web_prefs.xss_auditor_enabled =
1209 !command_line.HasSwitch(switches::kDisableXSSAuditor);
1210 web_prefs.application_cache_enabled =
1211 !command_line.HasSwitch(switches::kDisableApplicationCache);
1212
1213 web_prefs.local_storage_enabled =
1214 !command_line.HasSwitch(switches::kDisableLocalStorage);
1215 web_prefs.databases_enabled =
1216 !command_line.HasSwitch(switches::kDisableDatabases);
1217 web_prefs.webaudio_enabled =
1218 !command_line.HasSwitch(switches::kDisableWebAudio);
1219 web_prefs.experimental_webgl_enabled =
1220 GpuProcessHost::gpu_enabled() &&
1221 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
1222 !prefs->GetBoolean(prefs::kDisable3DAPIs) &&
1223 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
1224 web_prefs.gl_multisampling_enabled =
1225 !command_line.HasSwitch(switches::kDisableGLMultisampling);
1226 web_prefs.privileged_webgl_extensions_enabled =
1227 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
1228 web_prefs.site_specific_quirks_enabled =
1229 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
1230 web_prefs.allow_file_access_from_file_urls =
1231 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
1232 web_prefs.show_composited_layer_borders =
1233 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
1234 web_prefs.show_composited_layer_tree =
1235 command_line.HasSwitch(switches::kShowCompositedLayerTree);
1236 web_prefs.show_fps_counter =
1237 command_line.HasSwitch(switches::kShowFPSCounter);
1238 web_prefs.accelerated_compositing_enabled =
1239 GpuProcessHost::gpu_enabled() &&
1240 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
1241 web_prefs.threaded_compositing_enabled =
1242 command_line.HasSwitch(switches::kEnableThreadedCompositing);
1243 web_prefs.force_compositing_mode =
1244 command_line.HasSwitch(switches::kForceCompositingMode);
1245 web_prefs.fixed_position_compositing_enabled =
1246 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
1247 web_prefs.allow_webui_compositing =
1248 command_line.HasSwitch(switches::kAllowWebUICompositing);
1249 web_prefs.accelerated_2d_canvas_enabled =
1250 GpuProcessHost::gpu_enabled() &&
1251 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
1252 web_prefs.accelerated_painting_enabled =
1253 GpuProcessHost::gpu_enabled() &&
1254 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
1255 web_prefs.accelerated_filters_enabled =
1256 GpuProcessHost::gpu_enabled() &&
1257 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
1258 web_prefs.accelerated_layers_enabled =
1259 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
1260 web_prefs.composite_to_texture_enabled =
1261 command_line.HasSwitch(switches::kEnableCompositeToTexture);
1262 web_prefs.accelerated_plugins_enabled =
1263 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
1264 web_prefs.accelerated_video_enabled =
1265 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
1266 web_prefs.partial_swap_enabled =
1267 command_line.HasSwitch(switches::kEnablePartialSwap);
1268 web_prefs.memory_info_enabled =
1269 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1270 web_prefs.interactive_form_validation_enabled =
1271 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
1272 web_prefs.fullscreen_enabled =
1273 !command_line.HasSwitch(switches::kDisableFullScreen);
1274 web_prefs.allow_displaying_insecure_content =
1275 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1276 web_prefs.allow_running_insecure_content =
1277 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
1278
1279#if defined(OS_MACOSX)
1280 bool default_enable_scroll_animator = true;
1281#else
1282 // On CrOS, the launcher always passes in the --enable flag.
1283 bool default_enable_scroll_animator = false;
1284#endif
1285 web_prefs.enable_scroll_animator = default_enable_scroll_animator;
1286 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
1287 web_prefs.enable_scroll_animator = true;
1288 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
1289 web_prefs.enable_scroll_animator = false;
1290
1291 // The user stylesheet watcher may not exist in a testing profile.
1292 if (profile->GetUserStyleSheetWatcher()) {
1293 web_prefs.user_style_sheet_enabled = true;
1294 web_prefs.user_style_sheet_location =
1295 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1296 } else {
1297 web_prefs.user_style_sheet_enabled = false;
1298 }
1299
1300 web_prefs.visual_word_movement_enabled =
1301 command_line.HasSwitch(switches::kEnableVisualWordMovement);
1302 web_prefs.unified_textchecker_enabled =
1303 command_line.HasSwitch(switches::kExperimentalSpellcheckerFeatures);
1304 web_prefs.per_tile_painting_enabled =
1305 command_line.HasSwitch(switches::kEnablePerTilePainting);
1306 }
1307
1308 { // Certain GPU features might have been blacklisted.
1309 GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance();
1310 DCHECK(gpu_data_manager);
1311 uint32 blacklist_flags = gpu_data_manager->GetGpuFeatureFlags().flags();
1312 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)
1313 web_prefs.accelerated_compositing_enabled = false;
1314 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureWebgl)
1315 web_prefs.experimental_webgl_enabled = false;
1316 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)
1317 web_prefs.accelerated_2d_canvas_enabled = false;
1318 if (blacklist_flags & GpuFeatureFlags::kGpuFeatureMultisampling)
1319 web_prefs.gl_multisampling_enabled = false;
1320 }
1321
1322 web_prefs.uses_universal_detector =
1323 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
1324 web_prefs.text_areas_are_resizable =
1325 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
1326 web_prefs.hyperlink_auditing_enabled =
1327 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1328
1329 // Make sure we will set the default_encoding with canonical encoding name.
1330 web_prefs.default_encoding =
1331 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
1332 web_prefs.default_encoding);
1333 if (web_prefs.default_encoding.empty()) {
1334 prefs->ClearPref(prefs::kGlobalDefaultCharset);
1335 web_prefs.default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
1336 }
1337 DCHECK(!web_prefs.default_encoding.empty());
1338
1339 if (ChildProcessSecurityPolicy::GetInstance()->HasWebUIBindings(
1340 rvh->process()->GetID())) {
1341 web_prefs.loads_images_automatically = true;
1342 web_prefs.javascript_enabled = true;
1343 }
1344
1345 web_prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
1346
1347 ExtensionService* service = profile->GetExtensionService();
1348 if (service) {
1349 const Extension* extension = service->extensions()->GetByID(
1350 rvh->site_instance()->site().host());
1351 extension_webkit_preferences::SetPreferences(
1352 extension, rvh->delegate()->GetRenderViewType(), &web_prefs);
1353 }
1354
1355 if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) {
1356 web_prefs.allow_scripts_to_close_windows = true;
1357 } else if (rvh->delegate()->GetRenderViewType() ==
1358 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1359 // Disable all kinds of acceleration for background pages.
1360 // See http://crbug.com/96005 and http://crbug.com/96006
1361 web_prefs.force_compositing_mode = false;
1362 web_prefs.accelerated_compositing_enabled = false;
1363 web_prefs.accelerated_2d_canvas_enabled = false;
1364 web_prefs.accelerated_video_enabled = false;
1365 web_prefs.accelerated_painting_enabled = false;
1366 web_prefs.accelerated_plugins_enabled = false;
1367 }
1368
1369 return web_prefs;
[email protected]181a95ee2011-07-12 19:26:361370}
1371
1372void ChromeContentBrowserClient::UpdateInspectorSetting(
1373 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061374 content::BrowserContext* browser_context =
1375 rvh->process()->GetBrowserContext();
1376 DictionaryPrefUpdate update(
1377 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1378 prefs::kWebKitInspectorSettings);
1379 DictionaryValue* inspector_settings = update.Get();
1380 inspector_settings->SetWithoutPathExpansion(key,
1381 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361382}
1383
1384void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061385 content::BrowserContext* browser_context =
1386 rvh->process()->GetBrowserContext();
1387 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1388 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361389}
1390
[email protected]b8148ac2011-07-13 22:03:251391void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1392 BrowserURLHandler* handler) {
1393 // Add the default URL handlers.
1394 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1395 BrowserURLHandler::null_handler());
1396 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1397 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1398
[email protected]b3adbd02011-11-30 22:23:271399 // about: handler. Must come before chrome: handler, since it will
1400 // rewrite about: urls to chrome: URLs and then expect chrome: to
1401 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251402 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1403 BrowserURLHandler::null_handler());
1404 // chrome: & friends.
1405 handler->AddHandlerPair(&HandleWebUI,
1406 BrowserURLHandler::null_handler());
1407}
1408
1409void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371410 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301411 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251412 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1413 BrowsingDataRemover::EVERYTHING,
1414 base::Time());
1415 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1416 // BrowsingDataRemover takes care of deleting itself when done.
1417}
1418
1419void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371420 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301421 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251422 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1423 BrowsingDataRemover::EVERYTHING,
1424 base::Time());
[email protected]dceaa912011-09-06 17:17:231425 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251426 remover->Remove(remove_mask);
1427 // BrowsingDataRemover takes care of deleting itself when done.
1428}
1429
[email protected]e1d16eb92011-08-18 23:19:321430FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1431 return download_util::GetDefaultDownloadDirectory();
1432}
1433
[email protected]c9b6eb62011-10-18 20:49:391434std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1435 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1436}
1437
[email protected]e60c0232011-11-11 19:56:351438#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301439int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521440 const CommandLine& command_line) {
1441 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071442 ExtensionCrashHandlerHostLinux* crash_handler =
1443 ExtensionCrashHandlerHostLinux::GetInstance();
1444 return crash_handler->GetDeathSignalSocket();
1445 }
1446
[email protected]718eab62011-10-05 21:16:521447 std::string process_type =
1448 command_line.GetSwitchValueASCII(switches::kProcessType);
1449
1450 if (process_type == switches::kRendererProcess)
1451 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1452
[email protected]b80f68432011-05-02 17:22:301453 if (process_type == switches::kPluginProcess)
1454 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1455
1456 if (process_type == switches::kPpapiPluginProcess)
1457 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1458
1459 if (process_type == switches::kGpuProcess)
1460 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1461
1462 return -1;
1463}
[email protected]e60c0232011-11-11 19:56:351464#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301465
[email protected]4a65826d2011-08-25 16:04:011466#if defined(OS_WIN)
1467const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1468 return chrome::kBrowserResourcesDll;
1469}
1470#endif
1471
[email protected]37a72af2011-06-13 05:42:011472#if defined(USE_NSS)
1473crypto::CryptoModuleBlockingPasswordDelegate*
1474 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1475 const GURL& url) {
1476 return browser::NewCryptoModuleBlockingDialogDelegate(
1477 browser::kCryptoModulePasswordKeygen, url.host());
1478}
1479#endif
1480
[email protected]d977f9c2011-03-14 16:10:261481} // namespace chrome