blob: dc3625fb5e7f74bf2b5116061df8855f729ebfd0 [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]e1d16eb92011-08-18 23:19:3226#include "chrome/browser/download/download_util.h"
[email protected]6e672df2012-01-25 10:39:4727#include "chrome/browser/extensions/api/webrequest/webrequest_api.h"
[email protected]941623e2011-06-07 23:06:0428#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1029#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2630#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2531#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]f3986f82012-01-03 20:00:0632#include "chrome/browser/extensions/extension_webkit_preferences.h"
[email protected]32538d92011-08-25 00:09:2333#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1234#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2835#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0436#include "chrome/browser/notifications/desktop_notification_service.h"
37#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4238#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1239#include "chrome/browser/prefs/pref_service.h"
[email protected]f3986f82012-01-03 20:00:0640#include "chrome/browser/prefs/scoped_user_pref_update.h"
[email protected]f9034cf2011-07-21 12:43:4141#include "chrome/browser/prerender/prerender_manager.h"
[email protected]3085c502011-10-05 17:50:5042#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4143#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1444#include "chrome/browser/printing/printing_message_filter.h"
45#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3246#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1447#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3348#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]8aa7a412011-11-07 12:33:4249#include "chrome/browser/renderer_host/plugin_info_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1450#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0451#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4652#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4553#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0354#include "chrome/browser/ssl/ssl_blocking_page.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]863f70a2012-01-27 02:05:5058#include "chrome/browser/ui/webui/chrome_web_ui_controller_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]d977f9c2011-03-14 16:10:2670#include "content/browser/renderer_host/render_view_host.h"
[email protected]b48c9182011-10-26 18:03:3071#include "content/public/browser/browser_main_parts.h"
[email protected]b9535422012-02-09 01:47:5972#include "content/public/browser/child_process_security_policy.h"
[email protected]f3b1a082011-11-18 00:34:3073#include "content/public/browser/render_process_host.h"
[email protected]ce967862012-02-09 22:47:0574#include "content/public/browser/resource_context.h"
[email protected]b6583592012-01-25 19:52:3375#include "content/public/browser/site_instance.h"
[email protected]91ee3682012-01-19 15:02:1976#include "content/public/browser/web_contents.h"
[email protected]8643e6d2012-01-18 20:26:1077#include "content/public/browser/web_contents_view.h"
[email protected]c9b6eb62011-10-18 20:49:3978#include "grit/generated_resources.h"
[email protected]29b25d092011-06-29 20:57:3479#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0180#include "net/base/cookie_monster.h"
81#include "net/base/cookie_options.h"
[email protected]7a593db2012-02-13 21:19:4082#include "net/base/ssl_cert_request_info.h"
[email protected]c9b6eb62011-10-18 20:49:3983#include "ui/base/l10n/l10n_util.h"
[email protected]ac55e292011-06-24 05:16:0884#include "ui/base/resource/resource_bundle.h"
[email protected]4fdf6742012-01-10 20:14:3685#include "webkit/glue/webpreferences.h"
[email protected]d977f9c2011-03-14 16:10:2686
[email protected]b48c9182011-10-26 18:03:3087#if defined(OS_WIN)
[email protected]199fc7a2011-09-28 22:45:3888#include "chrome/browser/chrome_browser_main_win.h"
89#elif defined(OS_MACOSX)
90#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]7ceb99012011-12-21 08:05:5691#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h"
[email protected]b48c9182011-10-26 18:03:3092#elif defined(OS_CHROMEOS)
93#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]e60c0232011-11-11 19:56:3594#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b48c9182011-10-26 18:03:3095#include "chrome/browser/chrome_browser_main_linux.h"
96#elif defined(OS_POSIX)
97#include "chrome/browser/chrome_browser_main_posix.h"
98#endif
99
[email protected]b48c9182011-10-26 18:03:30100#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31101#include "chrome/browser/chrome_browser_main_extra_parts_gtk.h"
[email protected]199fc7a2011-09-28 22:45:38102#endif
103
[email protected]c7480942011-11-08 19:18:27104#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31105#include "chrome/browser/chrome_browser_main_extra_parts_views.h"
[email protected]c7480942011-11-08 19:18:27106#endif
107
108#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31109#include "chrome/browser/chrome_browser_main_extra_parts_aura.h"
110#endif
111
[email protected]e60c0232011-11-11 19:56:35112#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]b80f68432011-05-02 17:22:30113#include "base/linux_util.h"
114#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:43115#endif
[email protected]b80f68432011-05-02 17:22:30116
[email protected]080f34f2011-09-20 05:39:26117#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32118#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
[email protected]c92f4ed2011-10-21 19:50:21119#elif defined(TOOLKIT_USES_GTK)
[email protected]9bce7772011-11-16 01:24:45120#include "chrome/browser/tab_contents/chrome_tab_contents_view_wrapper_gtk.h"
[email protected]90580422012-01-12 00:26:22121#include "content/browser/tab_contents/tab_contents_view_gtk.h"
[email protected]74313b42011-08-24 16:51:32122#elif defined(OS_MACOSX)
[email protected]cce3ab72012-02-04 18:05:16123#include "chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.h"
[email protected]eb668c92012-02-06 15:35:29124#include "content/browser/tab_contents/web_contents_view_mac.h"
[email protected]6e677a342012-02-11 01:21:14125#elif defined(OS_ANDROID)
[email protected]82c9f44b2012-02-14 21:02:52126#include "content/browser/tab_contents/web_contents_view_android.h"
[email protected]74313b42011-08-24 16:51:32127#endif
128
[email protected]37a72af2011-06-13 05:42:01129#if defined(USE_NSS)
130#include "chrome/browser/ui/crypto_module_password_dialog.h"
131#endif
132
[email protected]c8c77182011-12-21 15:04:47133using content::AccessTokenStore;
[email protected]631bb742011-11-02 11:29:39134using content::BrowserThread;
[email protected]b9535422012-02-09 01:47:59135using content::ChildProcessSecurityPolicy;
[email protected]b6583592012-01-25 19:52:33136using content::SiteInstance;
[email protected]83ff91c2012-01-05 20:54:13137using content::WebContents;
[email protected]631bb742011-11-02 11:29:39138
[email protected]c5dbef02011-05-13 05:06:09139namespace {
140
[email protected]e461da2f2012-02-16 19:06:40141const char* kPredefinedAllowedSocketOrigins[] = {
142 "okddffdblfhhnmhodogpojmfkjmhinfp", // Test SSH Client
143 "pnhechapfaindjhompbnflcldabbghjo" // HTerm App (SSH Client)
144};
145
[email protected]b8148ac2011-07-13 22:03:25146// Handles rewriting Web UI URLs.
[email protected]8d3132f62011-10-12 07:13:42147bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
[email protected]863f70a2012-01-27 02:05:50148 if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL(
149 browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25150 return false;
151
152 // Special case the new tab page. In older versions of Chrome, the new tab
153 // page was hosted at chrome-internal:<blah>. This might be in people's saved
154 // sessions or bookmarks, so we say any URL with that scheme triggers the new
155 // tab page.
156 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
157 // Rewrite it with the proper new tab URL.
158 *url = GURL(chrome::kChromeUINewTabURL);
159 }
160
161 return true;
162}
163
[email protected]8d3132f62011-10-12 07:13:42164// Used by the GetPrivilegeRequiredByUrl() and GetProcessPrivilege() functions
165// below. Extension, and isolated apps require different privileges to be
166// granted to their RenderProcessHosts. This classification allows us to make
167// sure URLs are served by hosts with the right set of privileges.
168enum RenderProcessHostPrivilege {
169 PRIV_NORMAL,
[email protected]eec0b33c2011-12-05 22:09:45170 PRIV_HOSTED,
[email protected]8d3132f62011-10-12 07:13:42171 PRIV_ISOLATED,
[email protected]eec0b33c2011-12-05 22:09:45172 PRIV_EXTENSION,
[email protected]8d3132f62011-10-12 07:13:42173};
174
175RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
176 const GURL& url,
177 ExtensionService* service) {
178 // Default to a normal renderer cause it is lower privileged. This should only
179 // occur if the URL on a site instance is either malformed, or uninitialized.
180 // If it is malformed, then there is no need for better privileges anyways.
181 // If it is uninitialized, but eventually settles on being an a scheme other
182 // than normal webrenderer, the navigation logic will correct us out of band
183 // anyways.
184 if (!url.is_valid())
185 return PRIV_NORMAL;
186
187 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]615d88f2011-12-13 01:47:44188 const Extension* extension =
189 service->extensions()->GetByID(url.host());
[email protected]eec0b33c2011-12-05 22:09:45190 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42191 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45192 if (extension && extension->is_hosted_app())
193 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42194
195 return PRIV_EXTENSION;
196 }
197
198 return PRIV_NORMAL;
199}
200
201RenderProcessHostPrivilege GetProcessPrivilege(
[email protected]f3b1a082011-11-18 00:34:30202 content::RenderProcessHost* process_host,
[email protected]6f371442011-11-09 06:45:46203 extensions::ProcessMap* process_map,
204 ExtensionService* service) {
[email protected]6f371442011-11-09 06:45:46205 std::set<std::string> extension_ids =
[email protected]f3b1a082011-11-18 00:34:30206 process_map->GetExtensionsInProcess(process_host->GetID());
[email protected]6f371442011-11-09 06:45:46207 if (extension_ids.empty())
[email protected]676f6ab2011-10-19 20:23:21208 return PRIV_NORMAL;
209
[email protected]6f371442011-11-09 06:45:46210 for (std::set<std::string>::iterator iter = extension_ids.begin();
211 iter != extension_ids.end(); ++iter) {
212 const Extension* extension = service->GetExtensionById(*iter, false);
213 if (extension && extension->is_storage_isolated())
[email protected]8d3132f62011-10-12 07:13:42214 return PRIV_ISOLATED;
[email protected]eec0b33c2011-12-05 22:09:45215 if (extension && extension->is_hosted_app())
216 return PRIV_HOSTED;
[email protected]8d3132f62011-10-12 07:13:42217 }
218
[email protected]676f6ab2011-10-19 20:23:21219 return PRIV_EXTENSION;
[email protected]8d3132f62011-10-12 07:13:42220}
221
[email protected]eec0b33c2011-12-05 22:09:45222bool IsIsolatedAppInProcess(const GURL& site_url,
223 content::RenderProcessHost* process_host,
224 extensions::ProcessMap* process_map,
225 ExtensionService* service) {
226 std::set<std::string> extension_ids =
227 process_map->GetExtensionsInProcess(process_host->GetID());
228 if (extension_ids.empty())
229 return false;
230
231 for (std::set<std::string>::iterator iter = extension_ids.begin();
232 iter != extension_ids.end(); ++iter) {
233 const Extension* extension = service->GetExtensionById(*iter, false);
234 if (extension &&
235 extension->is_storage_isolated() &&
236 extension->url() == site_url)
237 return true;
238 }
239
240 return false;
241}
242
[email protected]6786bf402011-12-03 15:19:45243bool CertMatchesFilter(const net::X509Certificate& cert,
244 const base::DictionaryValue& filter) {
245 // TODO(markusheintz): This is the minimal required filter implementation.
246 // Implement a better matcher.
247
248 // An empty filter matches any client certificate since no requirements are
249 // specified at all.
250 if (filter.empty())
251 return true;
252
253 std::string common_name;
254 if (filter.GetString("ISSUER.CN", &common_name) &&
255 (cert.issuer().common_name == common_name)) {
256 return true;
257 }
258 return false;
259}
260
[email protected]f3986f82012-01-03 20:00:06261// Fills |map| with the per-script font prefs under path |map_name|.
262void FillFontFamilyMap(const PrefService* prefs,
263 const char* map_name,
264 WebPreferences::ScriptFontFamilyMap* map) {
265 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
266 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
267 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
268 std::string font_family = prefs->GetString(pref_name.c_str());
269 if (!font_family.empty())
270 map->push_back(std::make_pair(script, UTF8ToUTF16(font_family)));
271 }
272}
273
[email protected]9dbfff12011-07-01 19:37:07274} // namespace
[email protected]c5dbef02011-05-13 05:06:09275
[email protected]d977f9c2011-03-14 16:10:26276namespace chrome {
277
[email protected]e461da2f2012-02-16 19:06:40278ChromeContentBrowserClient::ChromeContentBrowserClient() {
279 for (size_t i = 0; i < arraysize(kPredefinedAllowedSocketOrigins); ++i)
280 allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]);
281
282 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
283 std::string allowed_list =
284 command_line.GetSwitchValueASCII(switches::kAllowNaClSocketAPI);
285 if (!allowed_list.empty()) {
286 StringTokenizer t(allowed_list, ",");
287 while (t.GetNext()) {
288 allowed_socket_origins_.insert(t.token());
289 }
290 }
291}
292
293ChromeContentBrowserClient::~ChromeContentBrowserClient() {
294}
295
[email protected]50462bf02011-11-21 19:13:31296content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
297 const content::MainFunctionParams& parameters) {
298 ChromeBrowserMainParts* main_parts;
[email protected]b48c9182011-10-26 18:03:30299 // Construct the Main browser parts based on the OS type.
300#if defined(OS_WIN)
[email protected]50462bf02011-11-21 19:13:31301 main_parts = new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04302#elif defined(OS_MACOSX)
[email protected]50462bf02011-11-21 19:13:31303 main_parts = new ChromeBrowserMainPartsMac(parameters);
[email protected]b48c9182011-10-26 18:03:30304#elif defined(OS_CHROMEOS)
[email protected]50462bf02011-11-21 19:13:31305 main_parts = new ChromeBrowserMainPartsChromeos(parameters);
[email protected]e60c0232011-11-11 19:56:35306#elif defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]50462bf02011-11-21 19:13:31307 main_parts = new ChromeBrowserMainPartsLinux(parameters);
[email protected]6e677a342012-02-11 01:21:14308#elif defined(OS_ANDROID)
309 // Do nothing for Android.
310 // TODO(klobag): Android initialization should use the
311 // *BrowserMainParts class-hierarchy for setting up custom initialization.
312 main_parts = NULL;
[email protected]b48c9182011-10-26 18:03:30313#elif defined(OS_POSIX)
[email protected]50462bf02011-11-21 19:13:31314 main_parts = new ChromeBrowserMainPartsPosix(parameters);
[email protected]f967b722011-09-07 00:58:04315#else
[email protected]b48c9182011-10-26 18:03:30316 NOTREACHED();
[email protected]50462bf02011-11-21 19:13:31317 main_parts = new ChromeBrowserMainParts(parameters);
[email protected]b48c9182011-10-26 18:03:30318#endif
319
[email protected]c7480942011-11-08 19:18:27320 // Construct additional browser parts. Stages are called in the order in
321 // which they are added.
[email protected]b48c9182011-10-26 18:03:30322#if defined(TOOLKIT_USES_GTK)
[email protected]50462bf02011-11-21 19:13:31323 main_parts->AddParts(new ChromeBrowserMainExtraPartsGtk());
[email protected]f967b722011-09-07 00:58:04324#endif
[email protected]c7480942011-11-08 19:18:27325
326#if defined(TOOLKIT_VIEWS)
[email protected]50462bf02011-11-21 19:13:31327 main_parts->AddParts(new ChromeBrowserMainExtraPartsViews());
[email protected]c7480942011-11-08 19:18:27328#endif
329
330#if defined(USE_AURA)
[email protected]50462bf02011-11-21 19:13:31331 main_parts->AddParts(new ChromeBrowserMainExtraPartsAura());
[email protected]c7480942011-11-08 19:18:27332#endif
333
[email protected]50462bf02011-11-21 19:13:31334 return main_parts;
[email protected]f967b722011-09-07 00:58:04335}
336
[email protected]8643e6d2012-01-18 20:26:10337content::WebContentsView* ChromeContentBrowserClient::CreateWebContentsView(
[email protected]8dad546b2012-01-17 21:47:35338 WebContents* web_contents) {
[email protected]080f34f2011-09-20 05:39:26339#if defined(TOOLKIT_VIEWS)
[email protected]8dad546b2012-01-17 21:47:35340 return new TabContentsViewViews(web_contents);
[email protected]c92f4ed2011-10-21 19:50:21341#elif defined(TOOLKIT_USES_GTK)
[email protected]8dad546b2012-01-17 21:47:35342 return new content::TabContentsViewGtk(web_contents,
[email protected]90580422012-01-12 00:26:22343 new ChromeTabContentsViewWrapperGtk);
[email protected]74313b42011-08-24 16:51:32344#elif defined(OS_MACOSX)
[email protected]eb668c92012-02-06 15:35:29345 return web_contents_view_mac::CreateWebContentsView(
[email protected]cce3ab72012-02-04 18:05:16346 web_contents,
347 chrome_web_contents_view_mac_delegate::CreateWebContentsViewMacDelegate(
348 web_contents));
[email protected]6e677a342012-02-11 01:21:14349#elif defined(OS_ANDROID)
[email protected]82c9f44b2012-02-14 21:02:52350 return new WebContentsViewAndroid(web_contents);
[email protected]74313b42011-08-24 16:51:32351#else
[email protected]8643e6d2012-01-18 20:26:10352#error Need to create your platform WebContentsView here.
[email protected]74313b42011-08-24 16:51:32353#endif
354}
355
[email protected]f364d1392011-04-08 21:03:10356void ChromeContentBrowserClient::RenderViewHostCreated(
357 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46358
359 SiteInstance* site_instance = render_view_host->site_instance();
360 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02361 site_instance->GetBrowserContext());
[email protected]67372ecf2011-09-10 01:30:46362
363 new ChromeRenderViewHostObserver(render_view_host,
364 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10365 new ExtensionMessageHandler(render_view_host);
[email protected]85f0a572012-02-07 22:20:13366
367 if (render_view_host->delegate()->GetRenderViewType() ==
368 content::VIEW_TYPE_INTERSTITIAL_PAGE) {
369 render_view_host->Send(new ChromeViewMsg_SetAsInterstitial(
370 render_view_host->routing_id()));
371 }
[email protected]d977f9c2011-03-14 16:10:26372}
373
[email protected]f3b1a082011-11-18 00:34:30374void ChromeContentBrowserClient::RenderProcessHostCreated(
375 content::RenderProcessHost* host) {
376 int id = host->GetID();
377 Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext());
378 host->GetChannel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02379 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]f3b1a082011-11-18 00:34:30380 host->GetChannel()->AddFilter(new PluginInfoMessageFilter(id, profile));
381 host->GetChannel()->AddFilter(new PrintingMessageFilter());
382 host->GetChannel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02383 new SearchProviderInstallStateMessageFilter(id, profile));
[email protected]f3b1a082011-11-18 00:34:30384 host->GetChannel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]7ceb99012011-12-21 08:05:56385#if defined(OS_MACOSX)
386 host->GetChannel()->AddFilter(new SpellCheckMessageFilterMac());
387#endif
[email protected]f3b1a082011-11-18 00:34:30388 host->GetChannel()->AddFilter(new ChromeBenchmarkingMessageFilter(
[email protected]6f08af82011-09-15 01:19:03389 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38390
[email protected]2ccf45c2011-08-19 23:35:50391 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
392 profile->IsOffTheRecord()));
[email protected]39a5b532011-10-22 01:47:07393
394 SendExtensionWebRequestStatusToHost(host);
[email protected]edece212011-11-16 11:56:56395
396 RendererContentSettingRules rules;
397 GetRendererContentSettingRules(profile->GetHostContentSettingsMap(), &rules);
398 host->Send(new ChromeViewMsg_SetContentSettingRules(rules));
[email protected]05fcf982011-04-19 00:44:14399}
400
[email protected]863f70a2012-01-27 02:05:50401content::WebUIControllerFactory*
402 ChromeContentBrowserClient::GetWebUIControllerFactory() {
403 return ChromeWebUIControllerFactory::GetInstance();
[email protected]1fd1a502011-03-30 16:55:56404}
405
[email protected]3d7474ff2011-07-27 17:47:37406GURL ChromeContentBrowserClient::GetEffectiveURL(
407 content::BrowserContext* browser_context, const GURL& url) {
408 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08409 // Get the effective URL for the given actual URL. If the URL is part of an
410 // installed app, the effective URL is an extension URL with the ID of that
411 // extension as the host. This has the effect of grouping apps together in
412 // a common SiteInstance.
413 if (!profile || !profile->GetExtensionService())
414 return url;
415
[email protected]615d88f2011-12-13 01:47:44416 const Extension* extension = profile->GetExtensionService()->extensions()->
417 GetHostedAppByURL(ExtensionURLInfo(url));
[email protected]36fb2c7c2011-04-04 15:49:08418 if (!extension)
419 return url;
420
[email protected]15877ca2011-11-18 22:40:52421 // Bookmark apps do not use the hosted app process model, and should be
422 // treated as normal URLs.
423 if (extension->from_bookmark())
424 return url;
425
[email protected]36fb2c7c2011-04-04 15:49:08426 // If the URL is part of an extension's web extent, convert it to an
427 // extension URL.
428 return extension->GetResourceURL(url.path());
429}
430
[email protected]056ad2a2011-07-12 02:13:55431bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37432 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55433 // Non-extension URLs should generally use process-per-site-instance.
[email protected]15877ca2011-11-18 22:40:52434 // Because we expect to use the effective URL, URLs for hosted apps (apart
435 // from bookmark apps) should have an extension scheme by now.
[email protected]056ad2a2011-07-12 02:13:55436 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
437 return false;
438
[email protected]3d7474ff2011-07-27 17:47:37439 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55440 if (!profile || !profile->GetExtensionService())
441 return false;
442
[email protected]615d88f2011-12-13 01:47:44443 const Extension* extension = profile->GetExtensionService()->extensions()->
444 GetExtensionOrAppByURL(ExtensionURLInfo(effective_url));
[email protected]056ad2a2011-07-12 02:13:55445 if (!extension)
446 return false;
447
448 // If the URL is part of a hosted app that does not have the background
449 // permission, we want to give each instance its own process to improve
450 // responsiveness.
451 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
452 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
453 return false;
454
455 // Hosted apps that have the background permission must use process per site,
456 // since all instances can make synchronous calls to the background window.
457 // Other extensions should use process per site as well.
458 return true;
459}
460
[email protected]46fb9442011-12-09 17:57:47461bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) {
462 return ProfileIOData::IsHandledURL(url);
463}
464
[email protected]2a5221b2011-09-27 23:07:31465bool ChromeContentBrowserClient::IsSuitableHost(
[email protected]f3b1a082011-11-18 00:34:30466 content::RenderProcessHost* process_host,
[email protected]2a5221b2011-09-27 23:07:31467 const GURL& site_url) {
468 Profile* profile =
[email protected]f3b1a082011-11-18 00:34:30469 Profile::FromBrowserContext(process_host->GetBrowserContext());
[email protected]8d3132f62011-10-12 07:13:42470 ExtensionService* service = profile->GetExtensionService();
[email protected]6f371442011-11-09 06:45:46471 extensions::ProcessMap* process_map = service->process_map();
[email protected]2a5221b2011-09-27 23:07:31472
[email protected]ffa97602011-11-17 17:55:52473 // Don't allow the Task Manager to share a process with anything else.
474 // Otherwise it can affect the renderers it is observing.
475 // Note: we could create another RenderProcessHostPrivilege bucket for
476 // this to allow multiple chrome://tasks instances to share, but that's
477 // a very unlikely case without serious consequences.
478 if (site_url.GetOrigin() == GURL(chrome::kChromeUITaskManagerURL).GetOrigin())
479 return false;
480
[email protected]8d3132f62011-10-12 07:13:42481 // These may be NULL during tests. In that case, just assume any site can
482 // share any host.
[email protected]6f371442011-11-09 06:45:46483 if (!service || !process_map)
[email protected]2a5221b2011-09-27 23:07:31484 return true;
485
[email protected]a8c269a2011-10-25 20:17:22486 // Experimental:
487 // If --enable-strict-site-isolation is enabled, do not allow non-WebUI pages
488 // to share a renderer process. (We could allow pages from the same site or
489 // extensions of the same type to share, if we knew what the given process
490 // was dedicated to. Allowing no sharing is simpler for now.) This may
491 // cause resource exhaustion issues if too many sites are open at once.
492 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
493 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation))
494 return false;
495
[email protected]eec0b33c2011-12-05 22:09:45496 // An isolated app is only allowed to share with the exact same app in order
497 // to provide complete renderer process isolation. This also works around
498 // issue http://crbug.com/85588, where different isolated apps in the same
499 // process would end up using the first app's storage contexts.
500 RenderProcessHostPrivilege privilege_required =
[email protected]8d3132f62011-10-12 07:13:42501 GetPrivilegeRequiredByUrl(site_url, service);
[email protected]eec0b33c2011-12-05 22:09:45502 if (privilege_required == PRIV_ISOLATED)
503 return IsIsolatedAppInProcess(site_url, process_host, process_map, service);
504
505 // Otherwise, just make sure the process privilege matches the privilege
506 // required by the site.
507 return GetProcessPrivilege(process_host, process_map, service) ==
508 privilege_required;
[email protected]2a5221b2011-09-27 23:07:31509}
510
[email protected]6f371442011-11-09 06:45:46511void ChromeContentBrowserClient::SiteInstanceGotProcess(
512 SiteInstance* site_instance) {
513 CHECK(site_instance->HasProcess());
514
515 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02516 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46517 ExtensionService* service = profile->GetExtensionService();
518 if (!service)
519 return;
520
521 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44522 service->extensions()->GetExtensionOrAppByURL(ExtensionURLInfo(
[email protected]b6583592012-01-25 19:52:33523 site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46524 if (!extension)
525 return;
526
[email protected]6bc04fd82011-12-04 02:29:35527 service->process_map()->Insert(extension->id(),
528 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33529 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46530 BrowserThread::PostTask(
531 BrowserThread::IO, FROM_HERE,
532 base::Bind(&ExtensionInfoMap::RegisterExtensionProcess,
533 profile->GetExtensionInfoMap(),
534 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35535 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33536 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46537}
538
539void ChromeContentBrowserClient::SiteInstanceDeleting(
540 SiteInstance* site_instance) {
541 if (!site_instance->HasProcess())
542 return;
543
544 Profile* profile = Profile::FromBrowserContext(
[email protected]72daaa92012-01-18 13:39:02545 site_instance->GetBrowserContext());
[email protected]6f371442011-11-09 06:45:46546 ExtensionService* service = profile->GetExtensionService();
547 if (!service)
548 return;
549
550 const Extension* extension =
[email protected]615d88f2011-12-13 01:47:44551 service->extensions()->GetExtensionOrAppByURL(
[email protected]b6583592012-01-25 19:52:33552 ExtensionURLInfo(site_instance->GetSite()));
[email protected]6f371442011-11-09 06:45:46553 if (!extension)
554 return;
555
[email protected]6bc04fd82011-12-04 02:29:35556 service->process_map()->Remove(extension->id(),
557 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33558 site_instance->GetId());
[email protected]6f371442011-11-09 06:45:46559 BrowserThread::PostTask(
560 BrowserThread::IO, FROM_HERE,
561 base::Bind(&ExtensionInfoMap::UnregisterExtensionProcess,
562 profile->GetExtensionInfoMap(),
563 extension->id(),
[email protected]6bc04fd82011-12-04 02:29:35564 site_instance->GetProcess()->GetID(),
[email protected]b6583592012-01-25 19:52:33565 site_instance->GetId()));
[email protected]6f371442011-11-09 06:45:46566}
567
[email protected]e3daf3c2011-10-05 21:17:08568bool ChromeContentBrowserClient::ShouldSwapProcessesForNavigation(
569 const GURL& current_url,
570 const GURL& new_url) {
571 if (current_url.is_empty()) {
572 // Always choose a new process when navigating to extension URLs. The
573 // process grouping logic will combine all of a given extension's pages
574 // into the same process.
575 if (new_url.SchemeIs(chrome::kExtensionScheme))
576 return true;
577
578 return false;
579 }
580
581 // Also, we must switch if one is an extension and the other is not the exact
582 // same extension.
583 if (current_url.SchemeIs(chrome::kExtensionScheme) ||
584 new_url.SchemeIs(chrome::kExtensionScheme)) {
585 if (current_url.GetOrigin() != new_url.GetOrigin())
586 return true;
587 }
588
589 return false;
590}
591
[email protected]763ec4ca2011-04-29 15:48:12592std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
593 const std::string& alias_name) {
594 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
595}
596
[email protected]b80f68432011-05-02 17:22:30597void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
598 CommandLine* command_line, int child_process_id) {
599#if defined(USE_LINUX_BREAKPAD)
600 if (IsCrashReporterEnabled()) {
601 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
602 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
603 }
604#elif defined(OS_MACOSX)
605 if (IsCrashReporterEnabled()) {
606 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
607 child_process_logging::GetClientId());
608 }
609#endif // OS_MACOSX
610
[email protected]f1933792011-06-14 00:49:34611 if (logging::DialogsAreSuppressed())
612 command_line->AppendSwitch(switches::kNoErrorDialogs);
613
[email protected]b80f68432011-05-02 17:22:30614 std::string process_type =
615 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17616 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]718eab62011-10-05 21:16:52617 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30618 FilePath user_data_dir =
619 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
620 if (!user_data_dir.empty())
621 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
622#if defined(OS_CHROMEOS)
623 const std::string& login_profile =
624 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
625 if (!login_profile.empty())
626 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
627#endif
628
[email protected]f3b1a082011-11-18 00:34:30629 content::RenderProcessHost* process =
630 content::RenderProcessHost::FromID(child_process_id);
[email protected]a8d851f82011-12-21 00:32:37631 if (process) {
632 Profile* profile = Profile::FromBrowserContext(
633 process->GetBrowserContext());
634 extensions::ProcessMap* process_map =
635 profile->GetExtensionService()->process_map();
636 if (process_map && process_map->Contains(process->GetID()))
637 command_line->AppendSwitch(switches::kExtensionProcess);
[email protected]b80f68432011-05-02 17:22:30638
[email protected]a8d851f82011-12-21 00:32:37639 PrefService* prefs = profile->GetPrefs();
640 // Currently this pref is only registered if applied via a policy.
641 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
642 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
643 // Turn this policy into a command line switch.
644 command_line->AppendSwitch(switches::kDisable3DAPIs);
645 }
[email protected]718eab62011-10-05 21:16:52646
[email protected]a8d851f82011-12-21 00:32:37647 // Disable client-side phishing detection in the renderer if it is
648 // disabled in the Profile preferences or the browser process.
649 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
650 !g_browser_process->safe_browsing_detection_service()) {
651 command_line->AppendSwitch(
652 switches::kDisableClientSidePhishingDetection);
653 }
[email protected]8c40da62011-07-13 22:58:46654 }
[email protected]47c7ec82012-01-18 03:29:21655 {
656 PrefService* local_state = g_browser_process->local_state();
657 if (local_state &&
658 !local_state->GetBoolean(prefs::kPrintPreviewDisabled)) {
659 command_line->AppendSwitch(switches::kRendererPrintPreview);
660 }
661 }
[email protected]4287a3d2011-06-13 23:56:51662
[email protected]47c7ec82012-01-18 03:29:21663 // Please keep this in alphabetical order.
[email protected]4287a3d2011-06-13 23:56:51664 static const char* const kSwitchNames[] = {
665 switches::kAllowHTTPBackgroundPage,
[email protected]70f48c02011-12-02 21:27:48666 switches::kAllowLegacyExtensionManifests,
[email protected]4287a3d2011-06-13 23:56:51667 switches::kAllowScriptingGallery,
668 switches::kAppsCheckoutURL,
669 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31670 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51671 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51672 switches::kDumpHistogramsOnExit,
[email protected]b7e44ff2012-02-16 03:37:34673 switches::kEnableAsynchronousSpellChecking,
[email protected]47c7ec82012-01-18 03:29:21674 switches::kEnableBenchmarking,
[email protected]b50368b2012-02-18 00:02:13675 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51676 switches::kEnableCrxlessWebApps,
677 switches::kEnableExperimentalExtensionApis,
678 switches::kEnableInBrowserThumbnailing,
679 switches::kEnableIPCFuzzing,
680 switches::kEnableNaCl,
[email protected]bcbe7652012-02-22 00:08:48681 switches::kEnablePasswordGeneration,
[email protected]9776e82e2011-11-15 02:17:53682 switches::kEnablePlatformApps,
[email protected]4287a3d2011-06-13 23:56:51683 switches::kEnableWatchdog,
684 switches::kExperimentalSpellcheckerFeatures,
685 switches::kMemoryProfiling,
686 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04687 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51688 switches::kPpapiFlashArgs,
689 switches::kPpapiFlashInProcess,
690 switches::kPpapiFlashPath,
691 switches::kPpapiFlashVersion,
692 switches::kProfilingAtStart,
693 switches::kProfilingFile,
694 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51695 switches::kSilentDumpOnDCHECK,
[email protected]a446534d2012-02-09 00:07:38696 switches::kWhitelistedExtensionID,
[email protected]4287a3d2011-06-13 23:56:51697 };
698
699 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
700 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17701 } else if (process_type == switches::kUtilityProcess) {
[email protected]a446534d2012-02-09 00:07:38702 static const char* const kSwitchNames[] = {
703 switches::kEnableExperimentalExtensionApis,
704 switches::kWhitelistedExtensionID,
705 };
706
707 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
708 arraysize(kSwitchNames));
[email protected]4287a3d2011-06-13 23:56:51709 } else if (process_type == switches::kPluginProcess) {
710 static const char* const kSwitchNames[] = {
711 #if defined(OS_CHROMEOS)
712 switches::kLoginProfile,
713 #endif
714 switches::kMemoryProfiling,
715 switches::kSilentDumpOnDCHECK,
716 switches::kUserDataDir,
717 };
718
719 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
720 arraysize(kSwitchNames));
721 } else if (process_type == switches::kZygoteProcess) {
722 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51723 switches::kUserDataDir, // Make logs go to the right file.
724 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
[email protected]b50368b2012-02-18 00:02:13725 switches::kEnableBundledPpapiFlash,
[email protected]4287a3d2011-06-13 23:56:51726 switches::kPpapiFlashInProcess,
727 switches::kPpapiFlashPath,
728 switches::kPpapiFlashVersion,
729 };
730
731 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
732 arraysize(kSwitchNames));
[email protected]d56ecf922012-02-15 16:03:11733 } else if (process_type == switches::kGpuProcess) {
734 // If --ignore-gpu-blacklist is passed in, don't send in crash reports
735 // because GPU is expected to be unreliable.
736 if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) &&
737 !command_line->HasSwitch(switches::kDisableBreakpad))
738 command_line->AppendSwitch(switches::kDisableBreakpad);
[email protected]b80f68432011-05-02 17:22:30739 }
[email protected]6f08af82011-09-15 01:19:03740
741 // The command line switch kEnableBenchmarking needs to be specified along
742 // with the kEnableStatsTable switch to ensure that the stats table global
743 // is initialized correctly.
744 if (command_line->HasSwitch(switches::kEnableBenchmarking))
745 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30746}
747
748std::string ChromeContentBrowserClient::GetApplicationLocale() {
749 return g_browser_process->GetApplicationLocale();
750}
751
[email protected]597a867b2011-11-18 18:31:20752std::string ChromeContentBrowserClient::GetAcceptLangs(
753 content::BrowserContext* context) {
754 Profile* profile = Profile::FromBrowserContext(context);
[email protected]3d7474ff2011-07-27 17:47:37755 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08756}
757
[email protected]ac55e292011-06-24 05:16:08758SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
[email protected]7c3228a2011-11-11 21:35:22759 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
[email protected]ac55e292011-06-24 05:16:08760 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
761}
762
[email protected]a2176792011-05-08 19:30:49763bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09764 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19765 const GURL& first_party,
[email protected]df02aca2012-02-09 21:03:20766 content::ResourceContext* context) {
[email protected]8093a542011-05-13 07:29:32767 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20768 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05769 return io_data->GetCookieSettings()->
770 IsSettingCookieAllowed(manifest_url, first_party);
[email protected]a2176792011-05-08 19:30:49771}
772
[email protected]ed24fad2011-05-10 22:44:01773bool ChromeContentBrowserClient::AllowGetCookie(
774 const GURL& url,
775 const GURL& first_party,
776 const net::CookieList& cookie_list,
[email protected]df02aca2012-02-09 21:03:20777 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01778 int render_process_id,
779 int render_view_id) {
780 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20781 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05782 bool allow = io_data->GetCookieSettings()->
783 IsReadingCookieAllowed(url, first_party);
[email protected]ed24fad2011-05-10 22:44:01784
[email protected]8093a542011-05-13 07:29:32785 BrowserThread::PostTask(
786 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03787 base::Bind(&TabSpecificContentSettings::CookiesRead, render_process_id,
788 render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01789 return allow;
790}
791
792bool ChromeContentBrowserClient::AllowSetCookie(
793 const GURL& url,
794 const GURL& first_party,
795 const std::string& cookie_line,
[email protected]df02aca2012-02-09 21:03:20796 content::ResourceContext* context,
[email protected]ed24fad2011-05-10 22:44:01797 int render_process_id,
798 int render_view_id,
799 net::CookieOptions* options) {
800 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20801 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]30fde822011-10-28 09:49:05802 CookieSettings* cookie_settings = io_data->GetCookieSettings();
803 bool allow = cookie_settings->IsSettingCookieAllowed(url, first_party);
804
805 if (cookie_settings->IsCookieSessionOnly(url))
[email protected]5b52ad42011-05-26 14:26:09806 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01807
[email protected]8093a542011-05-13 07:29:32808 BrowserThread::PostTask(
809 BrowserThread::UI, FROM_HERE,
[email protected]317c58f02011-11-09 02:15:03810 base::Bind(&TabSpecificContentSettings::CookieChanged, render_process_id,
811 render_view_id, url, cookie_line, *options, !allow));
[email protected]ed24fad2011-05-10 22:44:01812 return allow;
813}
814
[email protected]d5a19162011-06-30 18:51:54815bool ChromeContentBrowserClient::AllowSaveLocalState(
[email protected]df02aca2012-02-09 21:03:20816 content::ResourceContext* context) {
[email protected]d5a19162011-06-30 18:51:54817 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20818 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]1848cdc2012-02-17 10:48:26819
820 if (!io_data->clear_local_state_on_exit()->GetValue())
821 return true;
822
823 // Disable clearning the local state on exit if the browsing session is going
824 // to be restored on the next startup.
825 SessionStartupPref::Type startup_pref =
826 SessionStartupPref::PrefValueToType(
827 io_data->session_startup_pref()->GetValue());
828 return (startup_pref == SessionStartupPref::LAST &&
829 CommandLine::ForCurrentProcess()->HasSwitch(
830 switches::kEnableRestoreSessionState));
[email protected]d5a19162011-06-30 18:51:54831}
832
[email protected]5c5a88e2011-11-12 00:45:35833bool ChromeContentBrowserClient::AllowWorkerDatabase(
[email protected]5c5a88e2011-11-12 00:45:35834 const GURL& url,
835 const string16& name,
836 const string16& display_name,
837 unsigned long estimated_size,
[email protected]df02aca2012-02-09 21:03:20838 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48839 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35840 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20841 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35842 CookieSettings* cookie_settings = io_data->GetCookieSettings();
843 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
844
[email protected]62151052012-02-01 18:40:48845 // Record access to database for potential display in UI.
846 std::vector<std::pair<int, int> >::const_iterator i;
847 for (i = render_views.begin(); i != render_views.end(); ++i) {
848 BrowserThread::PostTask(
849 BrowserThread::UI, FROM_HERE,
850 base::Bind(&TabSpecificContentSettings::WebDatabaseAccessed,
851 i->first, i->second, url, name, display_name, !allow));
[email protected]5c5a88e2011-11-12 00:45:35852 }
853
854 return allow;
855}
856
857bool ChromeContentBrowserClient::AllowWorkerFileSystem(
[email protected]5c5a88e2011-11-12 00:45:35858 const GURL& url,
[email protected]df02aca2012-02-09 21:03:20859 content::ResourceContext* context,
[email protected]62151052012-02-01 18:40:48860 const std::vector<std::pair<int, int> >& render_views) {
[email protected]5c5a88e2011-11-12 00:45:35861 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:20862 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]5c5a88e2011-11-12 00:45:35863 CookieSettings* cookie_settings = io_data->GetCookieSettings();
864 bool allow = cookie_settings->IsSettingCookieAllowed(url, url);
865
[email protected]62151052012-02-01 18:40:48866 // Record access to file system for potential display in UI.
867 std::vector<std::pair<int, int> >::const_iterator i;
868 for (i = render_views.begin(); i != render_views.end(); ++i) {
869 BrowserThread::PostTask(
870 BrowserThread::UI, FROM_HERE,
871 base::Bind(&TabSpecificContentSettings::FileSystemAccessed,
872 i->first, i->second, url, !allow));
[email protected]5c5a88e2011-11-12 00:45:35873 }
874
875 return allow;
876}
877
[email protected]6133f922011-07-01 21:34:34878net::URLRequestContext*
879ChromeContentBrowserClient::OverrideRequestContextForURL(
[email protected]df02aca2012-02-09 21:03:20880 const GURL& url, content::ResourceContext* context) {
[email protected]6133f922011-07-01 21:34:34881 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
882 if (url.SchemeIs(chrome::kExtensionScheme)) {
[email protected]df02aca2012-02-09 21:03:20883 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]6133f922011-07-01 21:34:34884 return io_data->extensions_request_context();
885 }
886
887 return NULL;
888}
889
[email protected]317f96c92011-05-31 06:53:41890QuotaPermissionContext*
891ChromeContentBrowserClient::CreateQuotaPermissionContext() {
892 return new ChromeQuotaPermissionContext();
893}
894
[email protected]a0ce3282011-08-19 20:49:52895void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42896 platform_util::OpenItem(path);
[email protected]0609b17f2011-05-31 20:13:42897}
898
[email protected]a0ce3282011-08-19 20:49:52899void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
[email protected]a0ce3282011-08-19 20:49:52900 platform_util::ShowItemInFolder(path);
[email protected]a0ce3282011-08-19 20:49:52901}
902
[email protected]848dd042011-06-04 18:24:03903void ChromeContentBrowserClient::AllowCertificateError(
[email protected]4cf611e32012-02-13 16:06:17904 int render_process_id,
905 int render_view_id,
906 int cert_error,
907 const net::SSLInfo& ssl_info,
908 const GURL& request_url,
[email protected]848dd042011-06-04 18:24:03909 bool overridable,
[email protected]4cf611e32012-02-13 16:06:17910 const base::Callback<void(bool)>& callback,
911 bool* cancel_request) {
[email protected]f9034cf2011-07-21 12:43:41912 // If the tab is being prerendered, cancel the prerender and the request.
[email protected]83ff91c2012-01-05 20:54:13913 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]4cf611e32012-02-13 16:06:17914 render_process_id, render_view_id);
[email protected]f9034cf2011-07-21 12:43:41915 if (!tab) {
916 NOTREACHED();
917 return;
918 }
919 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50920 prerender::PrerenderManagerFactory::GetForProfile(
[email protected]627e0512011-12-21 22:55:30921 Profile::FromBrowserContext(tab->GetBrowserContext()));
[email protected]ea049a02011-12-25 21:37:09922 if (prerender_manager && prerender_manager->IsWebContentsPrerendering(tab)) {
[email protected]f9034cf2011-07-21 12:43:41923 if (prerender_manager->prerender_tracker()->TryCancel(
[email protected]4cf611e32012-02-13 16:06:17924 render_process_id, render_view_id,
[email protected]f9034cf2011-07-21 12:43:41925 prerender::FINAL_STATUS_SSL_ERROR)) {
[email protected]4cf611e32012-02-13 16:06:17926 *cancel_request = true;
[email protected]f9034cf2011-07-21 12:43:41927 return;
928 }
929 }
930
931 // Otherwise, display an SSL blocking page.
[email protected]4cf611e32012-02-13 16:06:17932 new SSLBlockingPage(
933 tab, cert_error, ssl_info, request_url, overridable, callback);
[email protected]848dd042011-06-04 18:24:03934}
935
[email protected]c99c442e2011-08-24 11:37:30936void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45937 int render_process_id,
938 int render_view_id,
[email protected]7a593db2012-02-13 21:19:40939 const net::HttpNetworkSession* network_session,
940 net::SSLCertRequestInfo* cert_request_info,
941 const base::Callback<void(net::X509Certificate*)>& callback) {
[email protected]83ff91c2012-01-05 20:54:13942 WebContents* tab = tab_util::GetWebContentsByID(
[email protected]8ec26472011-06-06 16:52:45943 render_process_id, render_view_id);
944 if (!tab) {
945 NOTREACHED();
946 return;
947 }
948
[email protected]6786bf402011-12-03 15:19:45949 GURL requesting_url("https://" + cert_request_info->host_and_port);
950 DCHECK(requesting_url.is_valid()) << "Invalid URL string: https://"
951 << cert_request_info->host_and_port;
952
[email protected]627e0512011-12-21 22:55:30953 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
[email protected]6786bf402011-12-03 15:19:45954 scoped_ptr<Value> filter(
955 profile->GetHostContentSettingsMap()->GetWebsiteSetting(
956 requesting_url,
957 requesting_url,
958 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
959 std::string(), NULL));
960
961 if (filter.get()) {
962 // Try to automatically select a client certificate.
963 if (filter->IsType(Value::TYPE_DICTIONARY)) {
964 DictionaryValue* filter_dict =
965 static_cast<DictionaryValue*>(filter.get());
966
967 const std::vector<scoped_refptr<net::X509Certificate> >&
968 all_client_certs = cert_request_info->client_certs;
969 for (size_t i = 0; i < all_client_certs.size(); ++i) {
970 if (CertMatchesFilter(*all_client_certs[i], *filter_dict)) {
971 // Use the first certificate that is matched by the filter.
[email protected]7a593db2012-02-13 21:19:40972 callback.Run(all_client_certs[i]);
[email protected]6786bf402011-12-03 15:19:45973 return;
974 }
975 }
976 } else {
977 NOTREACHED();
978 }
979 }
980
[email protected]8ec26472011-06-06 16:52:45981 TabContentsWrapper* wrapper =
982 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]6786bf402011-12-03 15:19:45983 if (!wrapper) {
[email protected]83ff91c2012-01-05 20:54:13984 // If there is no TabContentsWrapper for the given WebContents then we can't
[email protected]6786bf402011-12-03 15:19:45985 // show the user a dialog to select a client certificate. So we simply
[email protected]2a349e92011-12-07 12:00:14986 // proceed with no client certificate.
[email protected]7a593db2012-02-13 21:19:40987 callback.Run(NULL);
[email protected]6786bf402011-12-03 15:19:45988 return;
989 }
[email protected]7a593db2012-02-13 21:19:40990 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(
991 network_session, cert_request_info, callback);
[email protected]8ec26472011-06-06 16:52:45992}
993
994void ChromeContentBrowserClient::AddNewCertificate(
995 net::URLRequest* request,
996 net::X509Certificate* cert,
997 int render_process_id,
998 int render_view_id) {
999 // The handler will run the UI and delete itself when it's finished.
1000 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
1001}
1002
[email protected]941623e2011-06-07 23:06:041003void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
1004 const GURL& source_origin,
1005 int callback_context,
1006 int render_process_id,
1007 int render_view_id) {
1008 RenderViewHost* rvh = RenderViewHost::FromID(
1009 render_process_id, render_view_id);
1010 if (!rvh) {
1011 NOTREACHED();
1012 return;
1013 }
1014
[email protected]f3b1a082011-11-18 00:34:301015 content::RenderProcessHost* process = rvh->process();
1016 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041017 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371018 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041019 service->RequestPermission(
1020 source_origin, render_process_id, render_view_id, callback_context,
[email protected]83ff91c2012-01-05 20:54:131021 tab_util::GetWebContentsByID(render_process_id, render_view_id));
[email protected]941623e2011-06-07 23:06:041022}
1023
1024WebKit::WebNotificationPresenter::Permission
1025 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
[email protected]34eec7ffe32011-11-02 23:49:021026 const GURL& source_origin,
[email protected]df02aca2012-02-09 21:03:201027 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021028 int render_process_id) {
[email protected]941623e2011-06-07 23:06:041029 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]df02aca2012-02-09 21:03:201030 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021031 if (io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1032 source_origin, render_process_id,
1033 ExtensionAPIPermission::kNotification))
[email protected]941623e2011-06-07 23:06:041034 return WebKit::WebNotificationPresenter::PermissionAllowed;
[email protected]941623e2011-06-07 23:06:041035
1036 // Fall back to the regular notification preferences, which works on an
1037 // origin basis.
1038 return io_data->GetNotificationService() ?
[email protected]c7df61b2011-11-07 22:06:371039 io_data->GetNotificationService()->HasPermission(source_origin) :
[email protected]941623e2011-06-07 23:06:041040 WebKit::WebNotificationPresenter::PermissionNotAllowed;
1041}
1042
1043void ChromeContentBrowserClient::ShowDesktopNotification(
[email protected]0ee57e22011-11-12 01:59:171044 const content::ShowDesktopNotificationHostMsgParams& params,
[email protected]941623e2011-06-07 23:06:041045 int render_process_id,
1046 int render_view_id,
1047 bool worker) {
1048 RenderViewHost* rvh = RenderViewHost::FromID(
1049 render_process_id, render_view_id);
1050 if (!rvh) {
1051 NOTREACHED();
1052 return;
1053 }
1054
[email protected]f3b1a082011-11-18 00:34:301055 content::RenderProcessHost* process = rvh->process();
1056 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041057 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371058 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041059 service->ShowDesktopNotification(
1060 params, render_process_id, render_view_id,
1061 worker ? DesktopNotificationService::WorkerNotification :
1062 DesktopNotificationService::PageNotification);
1063}
1064
1065void ChromeContentBrowserClient::CancelDesktopNotification(
1066 int render_process_id,
1067 int render_view_id,
1068 int notification_id) {
1069 RenderViewHost* rvh = RenderViewHost::FromID(
1070 render_process_id, render_view_id);
1071 if (!rvh) {
1072 NOTREACHED();
1073 return;
1074 }
1075
[email protected]f3b1a082011-11-18 00:34:301076 content::RenderProcessHost* process = rvh->process();
1077 Profile* profile = Profile::FromBrowserContext(process->GetBrowserContext());
[email protected]941623e2011-06-07 23:06:041078 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:371079 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:041080 service->CancelDesktopNotification(
1081 render_process_id, render_view_id, notification_id);
1082}
1083
[email protected]9f3fba52011-06-08 20:37:191084bool ChromeContentBrowserClient::CanCreateWindow(
[email protected]34eec7ffe32011-11-02 23:49:021085 const GURL& source_origin,
[email protected]9f3fba52011-06-08 20:37:191086 WindowContainerType container_type,
[email protected]df02aca2012-02-09 21:03:201087 content::ResourceContext* context,
[email protected]34eec7ffe32011-11-02 23:49:021088 int render_process_id) {
[email protected]9f3fba52011-06-08 20:37:191089 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1090 // If the opener is trying to create a background window but doesn't have
1091 // the appropriate permission, fail the attempt.
1092 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
[email protected]df02aca2012-02-09 21:03:201093 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]34eec7ffe32011-11-02 23:49:021094 return io_data->GetExtensionInfoMap()->SecurityOriginHasAPIPermission(
1095 source_origin, render_process_id, ExtensionAPIPermission::kBackground);
[email protected]9f3fba52011-06-08 20:37:191096 }
1097 return true;
1098}
1099
1100std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
[email protected]df02aca2012-02-09 21:03:201101 const GURL& url, content::ResourceContext* context) {
[email protected]9f3fba52011-06-08 20:37:191102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1103 // Check if it's an extension-created worker, in which case we want to use
1104 // the name of the extension.
[email protected]df02aca2012-02-09 21:03:201105 ProfileIOData* io_data = ProfileIOData::FromResourceContext(context);
[email protected]9f3fba52011-06-08 20:37:191106 const Extension* extension =
1107 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
1108 return extension ? extension->name() : std::string();
1109}
1110
[email protected]99907362012-01-11 05:41:401111void ChromeContentBrowserClient::ResourceDispatcherHostCreated() {
1112 return g_browser_process->ResourceDispatcherHostCreated();
[email protected]3cb054e62011-06-13 05:21:171113}
1114
1115ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
1116 return g_browser_process->clipboard();
1117}
1118
[email protected]8f6a3b852011-07-19 16:48:561119MHTMLGenerationManager*
1120 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
1121 return g_browser_process->mhtml_generation_manager();
1122}
1123
[email protected]ae6e9912011-07-27 01:18:281124net::NetLog* ChromeContentBrowserClient::GetNetLog() {
1125 return g_browser_process->net_log();
1126}
1127
[email protected]3bc0b562011-08-24 23:51:041128speech_input::SpeechInputManager*
1129 ChromeContentBrowserClient::GetSpeechInputManager() {
[email protected]3297132a2012-02-21 23:27:591130#if defined(ENABLE_INPUT_SPEECH)
[email protected]3bc0b562011-08-24 23:51:041131 return speech_input::ChromeSpeechInputManager::GetInstance();
[email protected]3297132a2012-02-21 23:27:591132#else
1133 return NULL;
1134#endif
[email protected]3bc0b562011-08-24 23:51:041135}
1136
[email protected]32538d92011-08-25 00:09:231137AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
1138 return new ChromeAccessTokenStore();
1139}
1140
[email protected]dbae6b02011-06-29 23:51:411141bool ChromeContentBrowserClient::IsFastShutdownPossible() {
1142 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
1143 return !browser_command_line.HasSwitch(switches::kChromeFrame);
1144}
1145
[email protected]64d69de42012-02-06 00:19:541146void ChromeContentBrowserClient::OverrideWebkitPrefs(
1147 RenderViewHost* rvh, WebPreferences* web_prefs) {
[email protected]f3986f82012-01-03 20:00:061148 Profile* profile = Profile::FromBrowserContext(
1149 rvh->process()->GetBrowserContext());
1150 PrefService* prefs = profile->GetPrefs();
[email protected]f3986f82012-01-03 20:00:061151
[email protected]64d69de42012-02-06 00:19:541152 web_prefs->standard_font_family =
[email protected]f3986f82012-01-03 20:00:061153 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalStandardFontFamily));
[email protected]64d69de42012-02-06 00:19:541154 web_prefs->fixed_font_family =
[email protected]f3986f82012-01-03 20:00:061155 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFixedFontFamily));
[email protected]64d69de42012-02-06 00:19:541156 web_prefs->serif_font_family =
[email protected]f3986f82012-01-03 20:00:061157 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541158 web_prefs->sans_serif_font_family =
[email protected]f3986f82012-01-03 20:00:061159 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalSansSerifFontFamily));
[email protected]64d69de42012-02-06 00:19:541160 web_prefs->cursive_font_family =
[email protected]f3986f82012-01-03 20:00:061161 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalCursiveFontFamily));
[email protected]64d69de42012-02-06 00:19:541162 web_prefs->fantasy_font_family =
[email protected]f3986f82012-01-03 20:00:061163 UTF8ToUTF16(prefs->GetString(prefs::kWebKitGlobalFantasyFontFamily));
1164
1165 FillFontFamilyMap(prefs, prefs::kWebKitStandardFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541166 &web_prefs->standard_font_family_map);
[email protected]f3986f82012-01-03 20:00:061167 FillFontFamilyMap(prefs, prefs::kWebKitFixedFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541168 &web_prefs->fixed_font_family_map);
[email protected]f3986f82012-01-03 20:00:061169 FillFontFamilyMap(prefs, prefs::kWebKitSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541170 &web_prefs->serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061171 FillFontFamilyMap(prefs, prefs::kWebKitSansSerifFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541172 &web_prefs->sans_serif_font_family_map);
[email protected]f3986f82012-01-03 20:00:061173 FillFontFamilyMap(prefs, prefs::kWebKitCursiveFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541174 &web_prefs->cursive_font_family_map);
[email protected]f3986f82012-01-03 20:00:061175 FillFontFamilyMap(prefs, prefs::kWebKitFantasyFontFamilyMap,
[email protected]64d69de42012-02-06 00:19:541176 &web_prefs->fantasy_font_family_map);
[email protected]f3986f82012-01-03 20:00:061177
[email protected]64d69de42012-02-06 00:19:541178 web_prefs->default_font_size =
[email protected]f3986f82012-01-03 20:00:061179 prefs->GetInteger(prefs::kWebKitGlobalDefaultFontSize);
[email protected]64d69de42012-02-06 00:19:541180 web_prefs->default_fixed_font_size =
[email protected]f3986f82012-01-03 20:00:061181 prefs->GetInteger(prefs::kWebKitGlobalDefaultFixedFontSize);
[email protected]64d69de42012-02-06 00:19:541182 web_prefs->minimum_font_size =
[email protected]f3986f82012-01-03 20:00:061183 prefs->GetInteger(prefs::kWebKitGlobalMinimumFontSize);
[email protected]64d69de42012-02-06 00:19:541184 web_prefs->minimum_logical_font_size =
[email protected]f3986f82012-01-03 20:00:061185 prefs->GetInteger(prefs::kWebKitGlobalMinimumLogicalFontSize);
1186
[email protected]64d69de42012-02-06 00:19:541187 web_prefs->default_encoding = prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061188
[email protected]64d69de42012-02-06 00:19:541189 web_prefs->javascript_can_open_windows_automatically =
[email protected]f3986f82012-01-03 20:00:061190 prefs->GetBoolean(
1191 prefs::kWebKitGlobalJavascriptCanOpenWindowsAutomatically);
[email protected]64d69de42012-02-06 00:19:541192 web_prefs->dom_paste_enabled =
[email protected]f3986f82012-01-03 20:00:061193 prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
[email protected]64d69de42012-02-06 00:19:541194 web_prefs->shrinks_standalone_images_to_fit =
[email protected]f3986f82012-01-03 20:00:061195 prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
1196 const DictionaryValue* inspector_settings =
1197 prefs->GetDictionary(prefs::kWebKitInspectorSettings);
1198 if (inspector_settings) {
1199 for (DictionaryValue::key_iterator iter(inspector_settings->begin_keys());
1200 iter != inspector_settings->end_keys(); ++iter) {
1201 std::string value;
1202 if (inspector_settings->GetStringWithoutPathExpansion(*iter, &value))
[email protected]64d69de42012-02-06 00:19:541203 web_prefs->inspector_settings.push_back(
[email protected]f3986f82012-01-03 20:00:061204 std::make_pair(*iter, value));
1205 }
1206 }
[email protected]64d69de42012-02-06 00:19:541207 web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks);
[email protected]f3986f82012-01-03 20:00:061208
[email protected]64d69de42012-02-06 00:19:541209 if (!prefs->GetBoolean(prefs::kWebKitGlobalJavascriptEnabled))
1210 web_prefs->javascript_enabled = false;
1211 if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled))
1212 web_prefs->web_security_enabled = false;
1213 if (!prefs->GetBoolean(prefs::kWebKitGlobalPluginsEnabled))
1214 web_prefs->plugins_enabled = false;
1215 if (!prefs->GetBoolean(prefs::kWebKitJavaEnabled))
1216 web_prefs->java_enabled = false;
1217 web_prefs->loads_images_automatically =
1218 prefs->GetBoolean(prefs::kWebKitGlobalLoadsImagesAutomatically);
[email protected]f3986f82012-01-03 20:00:061219
[email protected]64d69de42012-02-06 00:19:541220 if (prefs->GetBoolean(prefs::kDisable3DAPIs))
1221 web_prefs->experimental_webgl_enabled = false;
[email protected]f3986f82012-01-03 20:00:061222
[email protected]64d69de42012-02-06 00:19:541223 web_prefs->memory_info_enabled =
1224 prefs->GetBoolean(prefs::kEnableMemoryInfo);
1225 web_prefs->allow_displaying_insecure_content =
1226 prefs->GetBoolean(prefs::kWebKitAllowDisplayingInsecureContent);
1227 web_prefs->allow_running_insecure_content =
1228 prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent);
[email protected]f3986f82012-01-03 20:00:061229
[email protected]64d69de42012-02-06 00:19:541230 // The user stylesheet watcher may not exist in a testing profile.
1231 if (profile->GetUserStyleSheetWatcher()) {
1232 web_prefs->user_style_sheet_enabled = true;
1233 web_prefs->user_style_sheet_location =
1234 profile->GetUserStyleSheetWatcher()->user_style_sheet();
1235 } else {
1236 web_prefs->user_style_sheet_enabled = false;
[email protected]f3986f82012-01-03 20:00:061237 }
1238
[email protected]b7e44ff2012-02-16 03:37:341239 web_prefs->asynchronous_spell_checking_enabled =
1240 CommandLine::ForCurrentProcess()->
1241 HasSwitch(switches::kEnableAsynchronousSpellChecking);
1242 web_prefs->unified_textchecker_enabled =
1243 web_prefs->asynchronous_spell_checking_enabled ||
1244 CommandLine::ForCurrentProcess()->
1245 HasSwitch(switches::kExperimentalSpellcheckerFeatures);
[email protected]dd5d0fb2012-01-18 03:37:571246
[email protected]64d69de42012-02-06 00:19:541247 web_prefs->uses_universal_detector =
[email protected]f3986f82012-01-03 20:00:061248 prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
[email protected]64d69de42012-02-06 00:19:541249 web_prefs->text_areas_are_resizable =
[email protected]f3986f82012-01-03 20:00:061250 prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
[email protected]64d69de42012-02-06 00:19:541251 web_prefs->hyperlink_auditing_enabled =
[email protected]f3986f82012-01-03 20:00:061252 prefs->GetBoolean(prefs::kEnableHyperlinkAuditing);
1253
1254 // Make sure we will set the default_encoding with canonical encoding name.
[email protected]64d69de42012-02-06 00:19:541255 web_prefs->default_encoding =
[email protected]f3986f82012-01-03 20:00:061256 CharacterEncoding::GetCanonicalEncodingNameByAliasName(
[email protected]64d69de42012-02-06 00:19:541257 web_prefs->default_encoding);
1258 if (web_prefs->default_encoding.empty()) {
[email protected]f3986f82012-01-03 20:00:061259 prefs->ClearPref(prefs::kGlobalDefaultCharset);
[email protected]64d69de42012-02-06 00:19:541260 web_prefs->default_encoding =
1261 prefs->GetString(prefs::kGlobalDefaultCharset);
[email protected]f3986f82012-01-03 20:00:061262 }
[email protected]64d69de42012-02-06 00:19:541263 DCHECK(!web_prefs->default_encoding.empty());
[email protected]f3986f82012-01-03 20:00:061264
1265 ExtensionService* service = profile->GetExtensionService();
1266 if (service) {
1267 const Extension* extension = service->extensions()->GetByID(
[email protected]b6583592012-01-25 19:52:331268 rvh->site_instance()->GetSite().host());
[email protected]f3986f82012-01-03 20:00:061269 extension_webkit_preferences::SetPreferences(
[email protected]64d69de42012-02-06 00:19:541270 extension, rvh->delegate()->GetRenderViewType(), web_prefs);
[email protected]f3986f82012-01-03 20:00:061271 }
1272
1273 if (rvh->delegate()->GetRenderViewType() == chrome::VIEW_TYPE_NOTIFICATION) {
[email protected]64d69de42012-02-06 00:19:541274 web_prefs->allow_scripts_to_close_windows = true;
[email protected]f3986f82012-01-03 20:00:061275 } else if (rvh->delegate()->GetRenderViewType() ==
1276 chrome::VIEW_TYPE_BACKGROUND_CONTENTS) {
1277 // Disable all kinds of acceleration for background pages.
1278 // See http://crbug.com/96005 and http://crbug.com/96006
[email protected]64d69de42012-02-06 00:19:541279 web_prefs->force_compositing_mode = false;
1280 web_prefs->accelerated_compositing_enabled = false;
1281 web_prefs->accelerated_2d_canvas_enabled = false;
1282 web_prefs->accelerated_video_enabled = false;
1283 web_prefs->accelerated_painting_enabled = false;
1284 web_prefs->accelerated_plugins_enabled = false;
[email protected]f3986f82012-01-03 20:00:061285 }
[email protected]181a95ee2011-07-12 19:26:361286}
1287
1288void ChromeContentBrowserClient::UpdateInspectorSetting(
1289 RenderViewHost* rvh, const std::string& key, const std::string& value) {
[email protected]f3986f82012-01-03 20:00:061290 content::BrowserContext* browser_context =
1291 rvh->process()->GetBrowserContext();
1292 DictionaryPrefUpdate update(
1293 Profile::FromBrowserContext(browser_context)->GetPrefs(),
1294 prefs::kWebKitInspectorSettings);
1295 DictionaryValue* inspector_settings = update.Get();
1296 inspector_settings->SetWithoutPathExpansion(key,
1297 Value::CreateStringValue(value));
[email protected]181a95ee2011-07-12 19:26:361298}
1299
1300void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
[email protected]f3986f82012-01-03 20:00:061301 content::BrowserContext* browser_context =
1302 rvh->process()->GetBrowserContext();
1303 Profile::FromBrowserContext(browser_context)->GetPrefs()->
1304 ClearPref(prefs::kWebKitInspectorSettings);
[email protected]181a95ee2011-07-12 19:26:361305}
1306
[email protected]b8148ac2011-07-13 22:03:251307void ChromeContentBrowserClient::BrowserURLHandlerCreated(
1308 BrowserURLHandler* handler) {
1309 // Add the default URL handlers.
1310 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
1311 BrowserURLHandler::null_handler());
1312 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
1313 &ExtensionWebUI::HandleChromeURLOverrideReverse);
1314
[email protected]b3adbd02011-11-30 22:23:271315 // about: handler. Must come before chrome: handler, since it will
1316 // rewrite about: urls to chrome: URLs and then expect chrome: to
1317 // actually handle them.
[email protected]b8148ac2011-07-13 22:03:251318 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
1319 BrowserURLHandler::null_handler());
1320 // chrome: & friends.
1321 handler->AddHandlerPair(&HandleWebUI,
1322 BrowserURLHandler::null_handler());
1323}
1324
1325void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371326 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301327 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251328 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1329 BrowsingDataRemover::EVERYTHING,
1330 base::Time());
1331 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
1332 // BrowsingDataRemover takes care of deleting itself when done.
1333}
1334
1335void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:371336 Profile* profile = Profile::FromBrowserContext(
[email protected]f3b1a082011-11-18 00:34:301337 rvh->site_instance()->GetProcess()->GetBrowserContext());
[email protected]b8148ac2011-07-13 22:03:251338 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
1339 BrowsingDataRemover::EVERYTHING,
1340 base::Time());
[email protected]dceaa912011-09-06 17:17:231341 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:251342 remover->Remove(remove_mask);
1343 // BrowsingDataRemover takes care of deleting itself when done.
1344}
1345
[email protected]e1d16eb92011-08-18 23:19:321346FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
1347 return download_util::GetDefaultDownloadDirectory();
1348}
1349
[email protected]c9b6eb62011-10-18 20:49:391350std::string ChromeContentBrowserClient::GetDefaultDownloadName() {
1351 return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME);
1352}
1353
[email protected]e461da2f2012-02-16 19:06:401354bool ChromeContentBrowserClient::AllowSocketAPI(const GURL& url) {
1355 return url.is_valid() &&
1356 allowed_socket_origins_.find(url.host()) != allowed_socket_origins_.end();
1357}
1358
[email protected]e60c0232011-11-11 19:56:351359#if defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301360int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:521361 const CommandLine& command_line) {
[email protected]6e677a342012-02-11 01:21:141362#if defined(OS_ANDROID)
1363 // TODO(carlosvaldivia): Upstream breakpad code for Android and remove this
1364 // fork. http://crbug.com/113560
1365 NOTIMPLEMENTED();
1366#else
[email protected]718eab62011-10-05 21:16:521367 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:071368 ExtensionCrashHandlerHostLinux* crash_handler =
1369 ExtensionCrashHandlerHostLinux::GetInstance();
1370 return crash_handler->GetDeathSignalSocket();
1371 }
1372
[email protected]718eab62011-10-05 21:16:521373 std::string process_type =
1374 command_line.GetSwitchValueASCII(switches::kProcessType);
1375
1376 if (process_type == switches::kRendererProcess)
1377 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1378
[email protected]b80f68432011-05-02 17:22:301379 if (process_type == switches::kPluginProcess)
1380 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1381
1382 if (process_type == switches::kPpapiPluginProcess)
1383 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
1384
1385 if (process_type == switches::kGpuProcess)
1386 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
[email protected]6e677a342012-02-11 01:21:141387#endif // defined(OS_ANDROID)
[email protected]b80f68432011-05-02 17:22:301388
1389 return -1;
1390}
[email protected]e60c0232011-11-11 19:56:351391#endif // defined(OS_POSIX) && !defined(OS_MACOSX)
[email protected]b80f68432011-05-02 17:22:301392
[email protected]4a65826d2011-08-25 16:04:011393#if defined(OS_WIN)
1394const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
1395 return chrome::kBrowserResourcesDll;
1396}
1397#endif
1398
[email protected]37a72af2011-06-13 05:42:011399#if defined(USE_NSS)
1400crypto::CryptoModuleBlockingPasswordDelegate*
1401 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
1402 const GURL& url) {
1403 return browser::NewCryptoModuleBlockingDialogDelegate(
1404 browser::kCryptoModulePasswordKeygen, url.host());
1405}
1406#endif
1407
[email protected]d977f9c2011-03-14 16:10:261408} // namespace chrome