blob: 1c8d9cea2407f7331097609640b3a79bc1b0927f [file] [log] [blame]
[email protected]d977f9c2011-03-14 16:10:261// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// 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]b80f68432011-05-02 17:22:307#include "base/command_line.h"
8#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:259#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3010#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2311#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1212#include "chrome/browser/character_encoding.h"
[email protected]97e6c4c2011-05-18 16:08:5113#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4114#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]5327dfb2011-05-03 17:50:3615#include "chrome/browser/chrome_worker_message_filter.h"
[email protected]a2176792011-05-08 19:30:4916#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3217#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]e1d16eb92011-08-18 23:19:3218#include "chrome/browser/download/download_util.h"
[email protected]941623e2011-06-07 23:06:0419#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1020#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2621#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2522#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]32538d92011-08-25 00:09:2323#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1224#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2825#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0426#include "chrome/browser/notifications/desktop_notification_service.h"
27#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4228#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1229#include "chrome/browser/prefs/pref_service.h"
[email protected]f9034cf2011-07-21 12:43:4130#include "chrome/browser/prerender/prerender_manager.h"
31#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1432#include "chrome/browser/printing/printing_message_filter.h"
33#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3234#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1435#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3336#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]d4cff272011-05-02 15:46:0137#include "chrome/browser/renderer_host/text_input_client_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1438#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0439#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4640#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4541#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0342#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3643#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4544#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
45#include "chrome/browser/tab_contents/tab_util.h"
46#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5647#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3048#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0149#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3050#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0451#include "chrome/common/extensions/extension.h"
[email protected]f1933792011-06-14 00:49:3452#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1253#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3854#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0955#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2556#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0957#include "content/browser/browsing_instance.h"
[email protected]97e6c4c2011-05-18 16:08:5158#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1459#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2660#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4961#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0962#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4163#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4564#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1265#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3266#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3667#include "content/browser/worker_host/worker_process_host.h"
[email protected]941623e2011-06-07 23:06:0468#include "content/common/desktop_notification_messages.h"
[email protected]29b25d092011-06-29 20:57:3469#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0170#include "net/base/cookie_monster.h"
71#include "net/base/cookie_options.h"
[email protected]ac55e292011-06-24 05:16:0872#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2673
[email protected]b80f68432011-05-02 17:22:3074#if defined(OS_LINUX)
75#include "base/linux_util.h"
76#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:4377#endif
[email protected]b80f68432011-05-02 17:22:3078
[email protected]bb6dcbb2011-08-24 17:05:2079#if defined(TOUCH_UI)
80#include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h"
81#elif defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:3282#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
83#elif defined(OS_LINUX)
84#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
85#elif defined(OS_MACOSX)
86#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:3287#endif
88
[email protected]37a72af2011-06-13 05:42:0189#if defined(USE_NSS)
90#include "chrome/browser/ui/crypto_module_password_dialog.h"
91#endif
92
[email protected]c5dbef02011-05-13 05:06:0993namespace {
94
[email protected]b8148ac2011-07-13 22:03:2595// Handles rewriting Web UI URLs.
[email protected]3d7474ff2011-07-27 17:47:3796static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
97 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:2598 return false;
99
100 // Special case the new tab page. In older versions of Chrome, the new tab
101 // page was hosted at chrome-internal:<blah>. This might be in people's saved
102 // sessions or bookmarks, so we say any URL with that scheme triggers the new
103 // tab page.
104 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
105 // Rewrite it with the proper new tab URL.
106 *url = GURL(chrome::kChromeUINewTabURL);
107 }
108
109 return true;
110}
111
[email protected]9dbfff12011-07-01 19:37:07112} // namespace
[email protected]c5dbef02011-05-13 05:06:09113
[email protected]d977f9c2011-03-14 16:10:26114namespace chrome {
115
[email protected]74313b42011-08-24 16:51:32116TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
117 TabContents* tab_contents) {
[email protected]bb6dcbb2011-08-24 17:05:20118#if defined(TOUCH_UI)
119 return new TabContentsViewTouch(tab_contents);
120#elif defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32121 return new TabContentsViewViews(tab_contents);
122#elif defined(OS_LINUX)
123 return new TabContentsViewGtk(tab_contents);
124#elif defined(OS_MACOSX)
125 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32126#else
127#error Need to create your platform TabContentsView here.
128#endif
129}
130
[email protected]f364d1392011-04-08 21:03:10131void ChromeContentBrowserClient::RenderViewHostCreated(
132 RenderViewHost* render_view_host) {
[email protected]b503914162011-08-19 16:02:50133 new ChromeRenderViewHostObserver(render_view_host);
[email protected]f364d1392011-04-08 21:03:10134 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26135}
136
[email protected]05fcf982011-04-19 00:44:14137void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
138 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02139 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37140 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14141 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02142 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14143 host->channel()->AddFilter(new PrintingMessageFilter());
144 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02145 new SearchProviderInstallStateMessageFilter(id, profile));
146 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]d4cff272011-05-02 15:46:01147#if defined(OS_MACOSX)
148 host->channel()->AddFilter(new TextInputClientMessageFilter(host->id()));
149#endif
[email protected]3e69bc82011-05-26 23:22:38150
[email protected]2ccf45c2011-08-19 23:35:50151 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
152 profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14153}
154
[email protected]97e6c4c2011-05-18 16:08:51155void ChromeContentBrowserClient::PluginProcessHostCreated(
156 PluginProcessHost* host) {
157 host->AddFilter(new ChromePluginMessageFilter(host));
158}
159
[email protected]5327dfb2011-05-03 17:50:36160void ChromeContentBrowserClient::WorkerProcessHostCreated(
161 WorkerProcessHost* host) {
162 host->AddFilter(new ChromeWorkerMessageFilter(host));
163}
164
[email protected]1fd1a502011-03-30 16:55:56165content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
166 return ChromeWebUIFactory::GetInstance();
167}
168
[email protected]3d7474ff2011-07-27 17:47:37169GURL ChromeContentBrowserClient::GetEffectiveURL(
170 content::BrowserContext* browser_context, const GURL& url) {
171 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08172 // Get the effective URL for the given actual URL. If the URL is part of an
173 // installed app, the effective URL is an extension URL with the ID of that
174 // extension as the host. This has the effect of grouping apps together in
175 // a common SiteInstance.
176 if (!profile || !profile->GetExtensionService())
177 return url;
178
179 const Extension* extension =
180 profile->GetExtensionService()->GetExtensionByWebExtent(url);
181 if (!extension)
182 return url;
183
184 // If the URL is part of an extension's web extent, convert it to an
185 // extension URL.
186 return extension->GetResourceURL(url.path());
187}
188
[email protected]056ad2a2011-07-12 02:13:55189bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37190 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55191 // Non-extension URLs should generally use process-per-site-instance.
192 // Because we expect to use the effective URL, hosted apps URLs should have
193 // an extension scheme by now.
194 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
195 return false;
196
[email protected]3d7474ff2011-07-27 17:47:37197 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55198 if (!profile || !profile->GetExtensionService())
199 return false;
200
201 const Extension* extension =
202 profile->GetExtensionService()->GetExtensionByURL(effective_url);
203 if (!extension)
204 return false;
205
206 // If the URL is part of a hosted app that does not have the background
207 // permission, we want to give each instance its own process to improve
208 // responsiveness.
209 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
210 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
211 return false;
212
213 // Hosted apps that have the background permission must use process per site,
214 // since all instances can make synchronous calls to the background window.
215 // Other extensions should use process per site as well.
216 return true;
217}
218
[email protected]0f012df82011-05-19 14:15:29219bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03220 return url == GURL(chrome::kChromeUICrashURL) ||
221 url == GURL(chrome::kChromeUIKillURL) ||
222 url == GURL(chrome::kChromeUIHangURL) ||
223 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29224}
225
[email protected]763ec4ca2011-04-29 15:48:12226std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
227 const std::string& alias_name) {
228 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
229}
230
[email protected]b80f68432011-05-02 17:22:30231void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
232 CommandLine* command_line, int child_process_id) {
233#if defined(USE_LINUX_BREAKPAD)
234 if (IsCrashReporterEnabled()) {
235 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
236 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
237 }
238#elif defined(OS_MACOSX)
239 if (IsCrashReporterEnabled()) {
240 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
241 child_process_logging::GetClientId());
242 }
243#endif // OS_MACOSX
244
[email protected]f1933792011-06-14 00:49:34245 if (logging::DialogsAreSuppressed())
246 command_line->AppendSwitch(switches::kNoErrorDialogs);
247
[email protected]b80f68432011-05-02 17:22:30248 std::string process_type =
249 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17250 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30251 if (process_type == switches::kExtensionProcess ||
252 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30253 FilePath user_data_dir =
254 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
255 if (!user_data_dir.empty())
256 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
257#if defined(OS_CHROMEOS)
258 const std::string& login_profile =
259 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
260 if (!login_profile.empty())
261 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
262#endif
263
264 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
265
[email protected]3d7474ff2011-07-27 17:47:37266 Profile* profile = Profile::FromBrowserContext(process->browser_context());
267 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30268 // Currently this pref is only registered if applied via a policy.
269 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
270 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
271 // Turn this policy into a command line switch.
272 command_line->AppendSwitch(switches::kDisable3DAPIs);
273 }
274
275 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46276 // in the Profile preferences or the browser process.
277 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
278 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30279 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46280 }
[email protected]4287a3d2011-06-13 23:56:51281
282 static const char* const kSwitchNames[] = {
283 switches::kAllowHTTPBackgroundPage,
284 switches::kAllowScriptingGallery,
285 switches::kAppsCheckoutURL,
286 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31287 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51288 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51289 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51290 switches::kDomAutomationController,
291 switches::kDumpHistogramsOnExit,
292 switches::kEnableClickToPlay,
293 switches::kEnableCrxlessWebApps,
294 switches::kEnableExperimentalExtensionApis,
295 switches::kEnableInBrowserThumbnailing,
[email protected]d0cf438c2011-08-18 03:08:52296 switches::kEnableInlineWebstoreInstall,
[email protected]4287a3d2011-06-13 23:56:51297 switches::kEnableIPCFuzzing,
298 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24299 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51300 switches::kEnableResourceContentSettings,
301 switches::kEnableSearchProviderApiV2,
302 switches::kEnableWatchdog,
303 switches::kExperimentalSpellcheckerFeatures,
304 switches::kMemoryProfiling,
305 switches::kMessageLoopHistogrammer,
306 switches::kPpapiFlashArgs,
307 switches::kPpapiFlashInProcess,
308 switches::kPpapiFlashPath,
309 switches::kPpapiFlashVersion,
310 switches::kProfilingAtStart,
311 switches::kProfilingFile,
312 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51313 switches::kSilentDumpOnDCHECK,
314 };
315
316 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
317 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17318 } else if (process_type == switches::kUtilityProcess) {
319 if (browser_command_line.HasSwitch(
320 switches::kEnableExperimentalExtensionApis)) {
321 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
322 }
[email protected]4287a3d2011-06-13 23:56:51323 } else if (process_type == switches::kPluginProcess) {
324 static const char* const kSwitchNames[] = {
325 #if defined(OS_CHROMEOS)
326 switches::kLoginProfile,
327 #endif
328 switches::kMemoryProfiling,
329 switches::kSilentDumpOnDCHECK,
330 switches::kUserDataDir,
331 };
332
333 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
334 arraysize(kSwitchNames));
335 } else if (process_type == switches::kZygoteProcess) {
336 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51337 switches::kUserDataDir, // Make logs go to the right file.
338 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
339 switches::kPpapiFlashInProcess,
340 switches::kPpapiFlashPath,
341 switches::kPpapiFlashVersion,
342 };
343
344 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
345 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30346 }
347}
348
349std::string ChromeContentBrowserClient::GetApplicationLocale() {
350 return g_browser_process->GetApplicationLocale();
351}
352
[email protected]b5cca982011-05-26 04:42:08353std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37354 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
355 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08356}
357
[email protected]ac55e292011-06-24 05:16:08358SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
359 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
360 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
361}
362
[email protected]a2176792011-05-08 19:30:49363bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09364 const GURL& manifest_url,
365 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
367 ProfileIOData* io_data =
368 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09369 // FIXME(jochen): get the correct top-level origin.
[email protected]efa55212011-05-13 16:19:38370 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]5b52ad42011-05-26 14:26:09371 GetCookieContentSetting(manifest_url, manifest_url, true);
[email protected]a2176792011-05-08 19:30:49372 DCHECK(setting != CONTENT_SETTING_DEFAULT);
373 return setting != CONTENT_SETTING_BLOCK;
374}
375
[email protected]ed24fad2011-05-10 22:44:01376bool ChromeContentBrowserClient::AllowGetCookie(
377 const GURL& url,
378 const GURL& first_party,
379 const net::CookieList& cookie_list,
380 const content::ResourceContext& context,
381 int render_process_id,
382 int render_view_id) {
383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32384 ProfileIOData* io_data =
385 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09386 ContentSetting setting = io_data->GetHostContentSettingsMap()->
387 GetCookieContentSetting(url, first_party, false);
388 bool allow = setting == CONTENT_SETTING_ALLOW ||
389 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01390
[email protected]8093a542011-05-13 07:29:32391 BrowserThread::PostTask(
392 BrowserThread::UI, FROM_HERE,
393 NewRunnableFunction(
394 &TabSpecificContentSettings::CookiesRead,
395 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01396 return allow;
397}
398
399bool ChromeContentBrowserClient::AllowSetCookie(
400 const GURL& url,
401 const GURL& first_party,
402 const std::string& cookie_line,
403 const content::ResourceContext& context,
404 int render_process_id,
405 int render_view_id,
406 net::CookieOptions* options) {
407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32408 ProfileIOData* io_data =
409 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09410 ContentSetting setting = io_data->GetHostContentSettingsMap()->
411 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01412
[email protected]5b52ad42011-05-26 14:26:09413 if (setting == CONTENT_SETTING_SESSION_ONLY)
414 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01415
[email protected]5b52ad42011-05-26 14:26:09416 bool allow = setting == CONTENT_SETTING_ALLOW ||
417 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01418
[email protected]8093a542011-05-13 07:29:32419 BrowserThread::PostTask(
420 BrowserThread::UI, FROM_HERE,
421 NewRunnableFunction(
422 &TabSpecificContentSettings::CookieChanged,
423 render_process_id, render_view_id, url, cookie_line, *options,
424 !allow));
[email protected]ed24fad2011-05-10 22:44:01425 return allow;
426}
427
[email protected]d5a19162011-06-30 18:51:54428bool ChromeContentBrowserClient::AllowSaveLocalState(
429 const content::ResourceContext& context) {
430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
431 ProfileIOData* io_data =
432 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
433 return !io_data->clear_local_state_on_exit()->GetValue();
434}
435
[email protected]6133f922011-07-01 21:34:34436net::URLRequestContext*
437ChromeContentBrowserClient::OverrideRequestContextForURL(
438 const GURL& url, const content::ResourceContext& context) {
439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
440 if (url.SchemeIs(chrome::kExtensionScheme)) {
441 ProfileIOData* io_data =
442 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
443 return io_data->extensions_request_context();
444 }
445
446 return NULL;
447}
448
[email protected]317f96c92011-05-31 06:53:41449QuotaPermissionContext*
450ChromeContentBrowserClient::CreateQuotaPermissionContext() {
451 return new ChromeQuotaPermissionContext();
452}
453
[email protected]a0ce3282011-08-19 20:49:52454void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42455 // On Mac, this call needs to be done on the UI thread. On other platforms,
456 // do it on the FILE thread so we don't slow down UI.
457#if defined(OS_MACOSX)
458 platform_util::OpenItem(path);
459#else
460 BrowserThread::PostTask(
461 BrowserThread::FILE, FROM_HERE,
462 NewRunnableFunction(&platform_util::OpenItem, path));
463#endif
464}
465
[email protected]a0ce3282011-08-19 20:49:52466void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
467#if defined(OS_MACOSX)
468 // Mac needs to run this operation on the UI thread.
469 platform_util::ShowItemInFolder(path);
470#else
471 BrowserThread::PostTask(
472 BrowserThread::FILE, FROM_HERE,
473 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
474#endif
475}
476
[email protected]848dd042011-06-04 18:24:03477void ChromeContentBrowserClient::AllowCertificateError(
478 SSLCertErrorHandler* handler,
479 bool overridable,
480 Callback2<SSLCertErrorHandler*, bool>::Type* callback) {
[email protected]f9034cf2011-07-21 12:43:41481 // If the tab is being prerendered, cancel the prerender and the request.
482 TabContents* tab = tab_util::GetTabContentsByID(
483 handler->render_process_host_id(),
484 handler->tab_contents_id());
485 if (!tab) {
486 NOTREACHED();
487 return;
488 }
489 prerender::PrerenderManager* prerender_manager =
[email protected]cafe4ad2011-07-28 18:34:56490 Profile::FromBrowserContext(tab->browser_context())->
491 GetPrerenderManager();
[email protected]f9034cf2011-07-21 12:43:41492 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
493 if (prerender_manager->prerender_tracker()->TryCancel(
494 handler->render_process_host_id(),
495 handler->tab_contents_id(),
496 prerender::FINAL_STATUS_SSL_ERROR)) {
497 handler->CancelRequest();
498 return;
499 }
500 }
501
502 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03503 SSLBlockingPage* blocking_page = new SSLBlockingPage(
504 handler, overridable, callback);
505 blocking_page->Show();
506}
507
[email protected]c99c442e2011-08-24 11:37:30508void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45509 int render_process_id,
510 int render_view_id,
511 SSLClientAuthHandler* handler) {
512 TabContents* tab = tab_util::GetTabContentsByID(
513 render_process_id, render_view_id);
514 if (!tab) {
515 NOTREACHED();
516 return;
517 }
518
519 TabContentsWrapper* wrapper =
520 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30521 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45522}
523
524void ChromeContentBrowserClient::AddNewCertificate(
525 net::URLRequest* request,
526 net::X509Certificate* cert,
527 int render_process_id,
528 int render_view_id) {
529 // The handler will run the UI and delete itself when it's finished.
530 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
531}
532
[email protected]941623e2011-06-07 23:06:04533void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
534 const GURL& source_origin,
535 int callback_context,
536 int render_process_id,
537 int render_view_id) {
538 RenderViewHost* rvh = RenderViewHost::FromID(
539 render_process_id, render_view_id);
540 if (!rvh) {
541 NOTREACHED();
542 return;
543 }
544
545 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37546 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04547 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37548 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04549 service->RequestPermission(
550 source_origin, render_process_id, render_view_id, callback_context,
551 tab_util::GetTabContentsByID(render_process_id, render_view_id));
552}
553
554WebKit::WebNotificationPresenter::Permission
555 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
556 const GURL& source_url,
557 const content::ResourceContext& context) {
558 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
559 ProfileIOData* io_data =
560 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
561
562 const Extension* extension =
563 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
564 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52565 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04566 return WebKit::WebNotificationPresenter::PermissionAllowed;
567 }
568
569 // Fall back to the regular notification preferences, which works on an
570 // origin basis.
571 return io_data->GetNotificationService() ?
572 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
573 WebKit::WebNotificationPresenter::PermissionNotAllowed;
574}
575
576void ChromeContentBrowserClient::ShowDesktopNotification(
577 const DesktopNotificationHostMsg_Show_Params& params,
578 int render_process_id,
579 int render_view_id,
580 bool worker) {
581 RenderViewHost* rvh = RenderViewHost::FromID(
582 render_process_id, render_view_id);
583 if (!rvh) {
584 NOTREACHED();
585 return;
586 }
587
588 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37589 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04590 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37591 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04592 service->ShowDesktopNotification(
593 params, render_process_id, render_view_id,
594 worker ? DesktopNotificationService::WorkerNotification :
595 DesktopNotificationService::PageNotification);
596}
597
598void ChromeContentBrowserClient::CancelDesktopNotification(
599 int render_process_id,
600 int render_view_id,
601 int notification_id) {
602 RenderViewHost* rvh = RenderViewHost::FromID(
603 render_process_id, render_view_id);
604 if (!rvh) {
605 NOTREACHED();
606 return;
607 }
608
609 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37610 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04611 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37612 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04613 service->CancelDesktopNotification(
614 render_process_id, render_view_id, notification_id);
615}
616
[email protected]9f3fba52011-06-08 20:37:19617bool ChromeContentBrowserClient::CanCreateWindow(
618 const GURL& source_url,
619 WindowContainerType container_type,
620 const content::ResourceContext& context) {
621 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
622 // If the opener is trying to create a background window but doesn't have
623 // the appropriate permission, fail the attempt.
624 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
625 ProfileIOData* io_data =
626 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
627 const Extension* extension =
628 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
629 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52630 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19631 }
632 return true;
633}
634
635std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
636 const GURL& url, const content::ResourceContext& context) {
637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
638 // Check if it's an extension-created worker, in which case we want to use
639 // the name of the extension.
640 ProfileIOData* io_data =
641 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
642 const Extension* extension =
643 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
644 return extension ? extension->name() : std::string();
645}
646
[email protected]3cb054e62011-06-13 05:21:17647ResourceDispatcherHost*
648 ChromeContentBrowserClient::GetResourceDispatcherHost() {
649 return g_browser_process->resource_dispatcher_host();
650}
651
652ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
653 return g_browser_process->clipboard();
654}
655
[email protected]8f6a3b852011-07-19 16:48:56656MHTMLGenerationManager*
657 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
658 return g_browser_process->mhtml_generation_manager();
659}
660
[email protected]dce502762011-07-20 08:53:49661DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
662 return g_browser_process->devtools_manager();
663}
664
[email protected]ae6e9912011-07-27 01:18:28665net::NetLog* ChromeContentBrowserClient::GetNetLog() {
666 return g_browser_process->net_log();
667}
668
[email protected]3bc0b562011-08-24 23:51:04669speech_input::SpeechInputManager*
670 ChromeContentBrowserClient::GetSpeechInputManager() {
671 return speech_input::ChromeSpeechInputManager::GetInstance();
672}
673
[email protected]32538d92011-08-25 00:09:23674AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
675 return new ChromeAccessTokenStore();
676}
677
[email protected]dbae6b02011-06-29 23:51:41678bool ChromeContentBrowserClient::IsFastShutdownPossible() {
679 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
680 return !browser_command_line.HasSwitch(switches::kChromeFrame);
681}
682
[email protected]3d7474ff2011-07-27 17:47:37683WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
684 content::BrowserContext* browser_context, bool is_web_ui) {
685 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
686 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36687}
688
689void ChromeContentBrowserClient::UpdateInspectorSetting(
690 RenderViewHost* rvh, const std::string& key, const std::string& value) {
691 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37692 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36693}
694
695void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
696 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37697 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36698}
699
[email protected]b8148ac2011-07-13 22:03:25700void ChromeContentBrowserClient::BrowserURLHandlerCreated(
701 BrowserURLHandler* handler) {
702 // Add the default URL handlers.
703 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
704 BrowserURLHandler::null_handler());
705 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
706 &ExtensionWebUI::HandleChromeURLOverrideReverse);
707
708 // about:
709 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
710 BrowserURLHandler::null_handler());
711 // chrome: & friends.
712 handler->AddHandlerPair(&HandleWebUI,
713 BrowserURLHandler::null_handler());
714}
715
716void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37717 Profile* profile = Profile::FromBrowserContext(
718 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25719 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
720 BrowsingDataRemover::EVERYTHING,
721 base::Time());
722 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
723 // BrowsingDataRemover takes care of deleting itself when done.
724}
725
726void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37727 Profile* profile = Profile::FromBrowserContext(
728 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25729 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
730 BrowsingDataRemover::EVERYTHING,
731 base::Time());
[email protected]dceaa912011-09-06 17:17:23732 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:25733 remover->Remove(remove_mask);
734 // BrowsingDataRemover takes care of deleting itself when done.
735}
736
[email protected]e1d16eb92011-08-18 23:19:32737FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
738 return download_util::GetDefaultDownloadDirectory();
739}
740
[email protected]b68bf3892011-08-23 15:03:58741net::URLRequestContextGetter*
742ChromeContentBrowserClient::GetDefaultRequestContextDeprecatedCrBug64339() {
743 return Profile::Deprecated::GetDefaultRequestContext();
744}
745
[email protected]c8571ea2011-08-26 17:22:17746net::URLRequestContextGetter*
747ChromeContentBrowserClient::GetSystemRequestContext() {
748 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
749 return g_browser_process->system_request_context();
750}
751
[email protected]b80f68432011-05-02 17:22:30752#if defined(OS_LINUX)
753int ChromeContentBrowserClient::GetCrashSignalFD(
754 const std::string& process_type) {
755 if (process_type == switches::kRendererProcess)
756 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
757
[email protected]9dbfff12011-07-01 19:37:07758 if (process_type == switches::kExtensionProcess) {
759 ExtensionCrashHandlerHostLinux* crash_handler =
760 ExtensionCrashHandlerHostLinux::GetInstance();
761 return crash_handler->GetDeathSignalSocket();
762 }
763
[email protected]b80f68432011-05-02 17:22:30764 if (process_type == switches::kPluginProcess)
765 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
766
767 if (process_type == switches::kPpapiPluginProcess)
768 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
769
770 if (process_type == switches::kGpuProcess)
771 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
772
773 return -1;
774}
[email protected]9dbfff12011-07-01 19:37:07775#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30776
[email protected]4a65826d2011-08-25 16:04:01777#if defined(OS_WIN)
778const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
779 return chrome::kBrowserResourcesDll;
780}
781#endif
782
[email protected]37a72af2011-06-13 05:42:01783#if defined(USE_NSS)
784crypto::CryptoModuleBlockingPasswordDelegate*
785 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
786 const GURL& url) {
787 return browser::NewCryptoModuleBlockingDialogDelegate(
788 browser::kCryptoModulePasswordKeygen, url.host());
789}
790#endif
791
[email protected]d977f9c2011-03-14 16:10:26792} // namespace chrome