blob: 6c14cd8f041f2e347aa28f6b26185cc0ea2fe5df [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]763ec4ca2011-04-29 15:48:1223#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2824#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0425#include "chrome/browser/notifications/desktop_notification_service.h"
26#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4227#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1228#include "chrome/browser/prefs/pref_service.h"
[email protected]f9034cf2011-07-21 12:43:4129#include "chrome/browser/prerender/prerender_manager.h"
30#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1431#include "chrome/browser/printing/printing_message_filter.h"
32#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3233#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1434#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3335#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]d4cff272011-05-02 15:46:0136#include "chrome/browser/renderer_host/text_input_client_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1437#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]8ec71262011-07-28 08:12:4638#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4539#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0340#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3641#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4542#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
43#include "chrome/browser/tab_contents/tab_util.h"
44#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5645#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3046#include "chrome/common/child_process_logging.h"
47#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0448#include "chrome/common/extensions/extension.h"
[email protected]f1933792011-06-14 00:49:3449#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1250#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3851#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0952#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2553#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0954#include "content/browser/browsing_instance.h"
[email protected]b46442d7e2011-06-29 02:16:0655#include "content/browser/debugger/devtools_handler.h"
[email protected]97e6c4c2011-05-18 16:08:5156#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1457#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2658#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4959#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0960#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4161#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4562#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1263#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3264#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3665#include "content/browser/worker_host/worker_process_host.h"
[email protected]941623e2011-06-07 23:06:0466#include "content/common/desktop_notification_messages.h"
[email protected]29b25d092011-06-29 20:57:3467#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0168#include "net/base/cookie_monster.h"
69#include "net/base/cookie_options.h"
[email protected]ac55e292011-06-24 05:16:0870#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2671
[email protected]b80f68432011-05-02 17:22:3072#if defined(OS_LINUX)
73#include "base/linux_util.h"
74#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:4375#endif
[email protected]b80f68432011-05-02 17:22:3076
[email protected]bb6dcbb2011-08-24 17:05:2077#if defined(TOUCH_UI)
78#include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h"
79#elif defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:3280#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
81#elif defined(OS_LINUX)
82#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
83#elif defined(OS_MACOSX)
84#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:3285#endif
86
[email protected]37a72af2011-06-13 05:42:0187#if defined(USE_NSS)
88#include "chrome/browser/ui/crypto_module_password_dialog.h"
89#endif
90
[email protected]c5dbef02011-05-13 05:06:0991namespace {
92
[email protected]b8148ac2011-07-13 22:03:2593// Handles rewriting Web UI URLs.
[email protected]3d7474ff2011-07-27 17:47:3794static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
95 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:2596 return false;
97
98 // Special case the new tab page. In older versions of Chrome, the new tab
99 // page was hosted at chrome-internal:<blah>. This might be in people's saved
100 // sessions or bookmarks, so we say any URL with that scheme triggers the new
101 // tab page.
102 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
103 // Rewrite it with the proper new tab URL.
104 *url = GURL(chrome::kChromeUINewTabURL);
105 }
106
107 return true;
108}
109
[email protected]9dbfff12011-07-01 19:37:07110} // namespace
[email protected]c5dbef02011-05-13 05:06:09111
[email protected]d977f9c2011-03-14 16:10:26112namespace chrome {
113
[email protected]74313b42011-08-24 16:51:32114TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
115 TabContents* tab_contents) {
[email protected]bb6dcbb2011-08-24 17:05:20116#if defined(TOUCH_UI)
117 return new TabContentsViewTouch(tab_contents);
118#elif defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32119 return new TabContentsViewViews(tab_contents);
120#elif defined(OS_LINUX)
121 return new TabContentsViewGtk(tab_contents);
122#elif defined(OS_MACOSX)
123 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32124#else
125#error Need to create your platform TabContentsView here.
126#endif
127}
128
[email protected]f364d1392011-04-08 21:03:10129void ChromeContentBrowserClient::RenderViewHostCreated(
130 RenderViewHost* render_view_host) {
[email protected]b503914162011-08-19 16:02:50131 new ChromeRenderViewHostObserver(render_view_host);
[email protected]f364d1392011-04-08 21:03:10132 new DevToolsHandler(render_view_host);
133 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26134}
135
[email protected]05fcf982011-04-19 00:44:14136void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
137 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02138 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37139 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14140 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02141 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14142 host->channel()->AddFilter(new PrintingMessageFilter());
143 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02144 new SearchProviderInstallStateMessageFilter(id, profile));
145 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]d4cff272011-05-02 15:46:01146#if defined(OS_MACOSX)
147 host->channel()->AddFilter(new TextInputClientMessageFilter(host->id()));
148#endif
[email protected]3e69bc82011-05-26 23:22:38149
[email protected]2ccf45c2011-08-19 23:35:50150 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
151 profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14152}
153
[email protected]97e6c4c2011-05-18 16:08:51154void ChromeContentBrowserClient::PluginProcessHostCreated(
155 PluginProcessHost* host) {
156 host->AddFilter(new ChromePluginMessageFilter(host));
157}
158
[email protected]5327dfb2011-05-03 17:50:36159void ChromeContentBrowserClient::WorkerProcessHostCreated(
160 WorkerProcessHost* host) {
161 host->AddFilter(new ChromeWorkerMessageFilter(host));
162}
163
[email protected]1fd1a502011-03-30 16:55:56164content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
165 return ChromeWebUIFactory::GetInstance();
166}
167
[email protected]3d7474ff2011-07-27 17:47:37168GURL ChromeContentBrowserClient::GetEffectiveURL(
169 content::BrowserContext* browser_context, const GURL& url) {
170 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08171 // Get the effective URL for the given actual URL. If the URL is part of an
172 // installed app, the effective URL is an extension URL with the ID of that
173 // extension as the host. This has the effect of grouping apps together in
174 // a common SiteInstance.
175 if (!profile || !profile->GetExtensionService())
176 return url;
177
178 const Extension* extension =
179 profile->GetExtensionService()->GetExtensionByWebExtent(url);
180 if (!extension)
181 return url;
182
183 // If the URL is part of an extension's web extent, convert it to an
184 // extension URL.
185 return extension->GetResourceURL(url.path());
186}
187
[email protected]056ad2a2011-07-12 02:13:55188bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37189 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55190 // Non-extension URLs should generally use process-per-site-instance.
191 // Because we expect to use the effective URL, hosted apps URLs should have
192 // an extension scheme by now.
193 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
194 return false;
195
[email protected]3d7474ff2011-07-27 17:47:37196 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55197 if (!profile || !profile->GetExtensionService())
198 return false;
199
200 const Extension* extension =
201 profile->GetExtensionService()->GetExtensionByURL(effective_url);
202 if (!extension)
203 return false;
204
205 // If the URL is part of a hosted app that does not have the background
206 // permission, we want to give each instance its own process to improve
207 // responsiveness.
208 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
209 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
210 return false;
211
212 // Hosted apps that have the background permission must use process per site,
213 // since all instances can make synchronous calls to the background window.
214 // Other extensions should use process per site as well.
215 return true;
216}
217
[email protected]0f012df82011-05-19 14:15:29218bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03219 return url == GURL(chrome::kChromeUICrashURL) ||
220 url == GURL(chrome::kChromeUIKillURL) ||
221 url == GURL(chrome::kChromeUIHangURL) ||
222 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29223}
224
[email protected]763ec4ca2011-04-29 15:48:12225std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
226 const std::string& alias_name) {
227 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
228}
229
[email protected]b80f68432011-05-02 17:22:30230void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
231 CommandLine* command_line, int child_process_id) {
232#if defined(USE_LINUX_BREAKPAD)
233 if (IsCrashReporterEnabled()) {
234 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
235 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
236 }
237#elif defined(OS_MACOSX)
238 if (IsCrashReporterEnabled()) {
239 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
240 child_process_logging::GetClientId());
241 }
242#endif // OS_MACOSX
243
[email protected]f1933792011-06-14 00:49:34244 if (logging::DialogsAreSuppressed())
245 command_line->AppendSwitch(switches::kNoErrorDialogs);
246
[email protected]b80f68432011-05-02 17:22:30247 std::string process_type =
248 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17249 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30250 if (process_type == switches::kExtensionProcess ||
251 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30252 FilePath user_data_dir =
253 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
254 if (!user_data_dir.empty())
255 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
256#if defined(OS_CHROMEOS)
257 const std::string& login_profile =
258 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
259 if (!login_profile.empty())
260 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
261#endif
262
263 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
264
[email protected]3d7474ff2011-07-27 17:47:37265 Profile* profile = Profile::FromBrowserContext(process->browser_context());
266 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30267 // Currently this pref is only registered if applied via a policy.
268 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
269 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
270 // Turn this policy into a command line switch.
271 command_line->AppendSwitch(switches::kDisable3DAPIs);
272 }
273
274 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46275 // in the Profile preferences or the browser process.
276 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
277 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30278 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46279 }
[email protected]4287a3d2011-06-13 23:56:51280
281 static const char* const kSwitchNames[] = {
282 switches::kAllowHTTPBackgroundPage,
283 switches::kAllowScriptingGallery,
284 switches::kAppsCheckoutURL,
285 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31286 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51287 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51288 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51289 switches::kDomAutomationController,
290 switches::kDumpHistogramsOnExit,
291 switches::kEnableClickToPlay,
292 switches::kEnableCrxlessWebApps,
293 switches::kEnableExperimentalExtensionApis,
294 switches::kEnableInBrowserThumbnailing,
[email protected]d0cf438c2011-08-18 03:08:52295 switches::kEnableInlineWebstoreInstall,
[email protected]4287a3d2011-06-13 23:56:51296 switches::kEnableIPCFuzzing,
297 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24298 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51299 switches::kEnableResourceContentSettings,
300 switches::kEnableSearchProviderApiV2,
301 switches::kEnableWatchdog,
302 switches::kExperimentalSpellcheckerFeatures,
303 switches::kMemoryProfiling,
304 switches::kMessageLoopHistogrammer,
305 switches::kPpapiFlashArgs,
306 switches::kPpapiFlashInProcess,
307 switches::kPpapiFlashPath,
308 switches::kPpapiFlashVersion,
309 switches::kProfilingAtStart,
310 switches::kProfilingFile,
311 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51312 switches::kSilentDumpOnDCHECK,
313 };
314
315 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
316 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17317 } else if (process_type == switches::kUtilityProcess) {
318 if (browser_command_line.HasSwitch(
319 switches::kEnableExperimentalExtensionApis)) {
320 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
321 }
[email protected]4287a3d2011-06-13 23:56:51322 } else if (process_type == switches::kPluginProcess) {
323 static const char* const kSwitchNames[] = {
324 #if defined(OS_CHROMEOS)
325 switches::kLoginProfile,
326 #endif
327 switches::kMemoryProfiling,
328 switches::kSilentDumpOnDCHECK,
329 switches::kUserDataDir,
330 };
331
332 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
333 arraysize(kSwitchNames));
334 } else if (process_type == switches::kZygoteProcess) {
335 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51336 switches::kUserDataDir, // Make logs go to the right file.
337 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
338 switches::kPpapiFlashInProcess,
339 switches::kPpapiFlashPath,
340 switches::kPpapiFlashVersion,
341 };
342
343 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
344 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30345 }
346}
347
348std::string ChromeContentBrowserClient::GetApplicationLocale() {
349 return g_browser_process->GetApplicationLocale();
350}
351
[email protected]b5cca982011-05-26 04:42:08352std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37353 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
354 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08355}
356
[email protected]ac55e292011-06-24 05:16:08357SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
358 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
359 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
360}
361
[email protected]a2176792011-05-08 19:30:49362bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09363 const GURL& manifest_url,
364 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32365 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
366 ProfileIOData* io_data =
367 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09368 // FIXME(jochen): get the correct top-level origin.
[email protected]efa55212011-05-13 16:19:38369 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]5b52ad42011-05-26 14:26:09370 GetCookieContentSetting(manifest_url, manifest_url, true);
[email protected]a2176792011-05-08 19:30:49371 DCHECK(setting != CONTENT_SETTING_DEFAULT);
372 return setting != CONTENT_SETTING_BLOCK;
373}
374
[email protected]ed24fad2011-05-10 22:44:01375bool ChromeContentBrowserClient::AllowGetCookie(
376 const GURL& url,
377 const GURL& first_party,
378 const net::CookieList& cookie_list,
379 const content::ResourceContext& context,
380 int render_process_id,
381 int render_view_id) {
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32383 ProfileIOData* io_data =
384 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09385 ContentSetting setting = io_data->GetHostContentSettingsMap()->
386 GetCookieContentSetting(url, first_party, false);
387 bool allow = setting == CONTENT_SETTING_ALLOW ||
388 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01389
[email protected]8093a542011-05-13 07:29:32390 BrowserThread::PostTask(
391 BrowserThread::UI, FROM_HERE,
392 NewRunnableFunction(
393 &TabSpecificContentSettings::CookiesRead,
394 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01395 return allow;
396}
397
398bool ChromeContentBrowserClient::AllowSetCookie(
399 const GURL& url,
400 const GURL& first_party,
401 const std::string& cookie_line,
402 const content::ResourceContext& context,
403 int render_process_id,
404 int render_view_id,
405 net::CookieOptions* options) {
406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32407 ProfileIOData* io_data =
408 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09409 ContentSetting setting = io_data->GetHostContentSettingsMap()->
410 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01411
[email protected]5b52ad42011-05-26 14:26:09412 if (setting == CONTENT_SETTING_SESSION_ONLY)
413 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01414
[email protected]5b52ad42011-05-26 14:26:09415 bool allow = setting == CONTENT_SETTING_ALLOW ||
416 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01417
[email protected]8093a542011-05-13 07:29:32418 BrowserThread::PostTask(
419 BrowserThread::UI, FROM_HERE,
420 NewRunnableFunction(
421 &TabSpecificContentSettings::CookieChanged,
422 render_process_id, render_view_id, url, cookie_line, *options,
423 !allow));
[email protected]ed24fad2011-05-10 22:44:01424 return allow;
425}
426
[email protected]d5a19162011-06-30 18:51:54427bool ChromeContentBrowserClient::AllowSaveLocalState(
428 const content::ResourceContext& context) {
429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
430 ProfileIOData* io_data =
431 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
432 return !io_data->clear_local_state_on_exit()->GetValue();
433}
434
[email protected]6133f922011-07-01 21:34:34435net::URLRequestContext*
436ChromeContentBrowserClient::OverrideRequestContextForURL(
437 const GURL& url, const content::ResourceContext& context) {
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
439 if (url.SchemeIs(chrome::kExtensionScheme)) {
440 ProfileIOData* io_data =
441 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
442 return io_data->extensions_request_context();
443 }
444
445 return NULL;
446}
447
[email protected]317f96c92011-05-31 06:53:41448QuotaPermissionContext*
449ChromeContentBrowserClient::CreateQuotaPermissionContext() {
450 return new ChromeQuotaPermissionContext();
451}
452
[email protected]a0ce3282011-08-19 20:49:52453void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42454 // On Mac, this call needs to be done on the UI thread. On other platforms,
455 // do it on the FILE thread so we don't slow down UI.
456#if defined(OS_MACOSX)
457 platform_util::OpenItem(path);
458#else
459 BrowserThread::PostTask(
460 BrowserThread::FILE, FROM_HERE,
461 NewRunnableFunction(&platform_util::OpenItem, path));
462#endif
463}
464
[email protected]a0ce3282011-08-19 20:49:52465void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
466#if defined(OS_MACOSX)
467 // Mac needs to run this operation on the UI thread.
468 platform_util::ShowItemInFolder(path);
469#else
470 BrowserThread::PostTask(
471 BrowserThread::FILE, FROM_HERE,
472 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
473#endif
474}
475
[email protected]848dd042011-06-04 18:24:03476void ChromeContentBrowserClient::AllowCertificateError(
477 SSLCertErrorHandler* handler,
478 bool overridable,
479 Callback2<SSLCertErrorHandler*, bool>::Type* callback) {
[email protected]f9034cf2011-07-21 12:43:41480 // If the tab is being prerendered, cancel the prerender and the request.
481 TabContents* tab = tab_util::GetTabContentsByID(
482 handler->render_process_host_id(),
483 handler->tab_contents_id());
484 if (!tab) {
485 NOTREACHED();
486 return;
487 }
488 prerender::PrerenderManager* prerender_manager =
[email protected]cafe4ad2011-07-28 18:34:56489 Profile::FromBrowserContext(tab->browser_context())->
490 GetPrerenderManager();
[email protected]f9034cf2011-07-21 12:43:41491 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
492 if (prerender_manager->prerender_tracker()->TryCancel(
493 handler->render_process_host_id(),
494 handler->tab_contents_id(),
495 prerender::FINAL_STATUS_SSL_ERROR)) {
496 handler->CancelRequest();
497 return;
498 }
499 }
500
501 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03502 SSLBlockingPage* blocking_page = new SSLBlockingPage(
503 handler, overridable, callback);
504 blocking_page->Show();
505}
506
[email protected]c99c442e2011-08-24 11:37:30507void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45508 int render_process_id,
509 int render_view_id,
510 SSLClientAuthHandler* handler) {
511 TabContents* tab = tab_util::GetTabContentsByID(
512 render_process_id, render_view_id);
513 if (!tab) {
514 NOTREACHED();
515 return;
516 }
517
518 TabContentsWrapper* wrapper =
519 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30520 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45521}
522
523void ChromeContentBrowserClient::AddNewCertificate(
524 net::URLRequest* request,
525 net::X509Certificate* cert,
526 int render_process_id,
527 int render_view_id) {
528 // The handler will run the UI and delete itself when it's finished.
529 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
530}
531
[email protected]941623e2011-06-07 23:06:04532void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
533 const GURL& source_origin,
534 int callback_context,
535 int render_process_id,
536 int render_view_id) {
537 RenderViewHost* rvh = RenderViewHost::FromID(
538 render_process_id, render_view_id);
539 if (!rvh) {
540 NOTREACHED();
541 return;
542 }
543
544 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37545 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04546 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37547 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04548 service->RequestPermission(
549 source_origin, render_process_id, render_view_id, callback_context,
550 tab_util::GetTabContentsByID(render_process_id, render_view_id));
551}
552
553WebKit::WebNotificationPresenter::Permission
554 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
555 const GURL& source_url,
556 const content::ResourceContext& context) {
557 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
558 ProfileIOData* io_data =
559 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
560
561 const Extension* extension =
562 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
563 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52564 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04565 return WebKit::WebNotificationPresenter::PermissionAllowed;
566 }
567
568 // Fall back to the regular notification preferences, which works on an
569 // origin basis.
570 return io_data->GetNotificationService() ?
571 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
572 WebKit::WebNotificationPresenter::PermissionNotAllowed;
573}
574
575void ChromeContentBrowserClient::ShowDesktopNotification(
576 const DesktopNotificationHostMsg_Show_Params& params,
577 int render_process_id,
578 int render_view_id,
579 bool worker) {
580 RenderViewHost* rvh = RenderViewHost::FromID(
581 render_process_id, render_view_id);
582 if (!rvh) {
583 NOTREACHED();
584 return;
585 }
586
587 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37588 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04589 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37590 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04591 service->ShowDesktopNotification(
592 params, render_process_id, render_view_id,
593 worker ? DesktopNotificationService::WorkerNotification :
594 DesktopNotificationService::PageNotification);
595}
596
597void ChromeContentBrowserClient::CancelDesktopNotification(
598 int render_process_id,
599 int render_view_id,
600 int notification_id) {
601 RenderViewHost* rvh = RenderViewHost::FromID(
602 render_process_id, render_view_id);
603 if (!rvh) {
604 NOTREACHED();
605 return;
606 }
607
608 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37609 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04610 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37611 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04612 service->CancelDesktopNotification(
613 render_process_id, render_view_id, notification_id);
614}
615
[email protected]9f3fba52011-06-08 20:37:19616bool ChromeContentBrowserClient::CanCreateWindow(
617 const GURL& source_url,
618 WindowContainerType container_type,
619 const content::ResourceContext& context) {
620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
621 // If the opener is trying to create a background window but doesn't have
622 // the appropriate permission, fail the attempt.
623 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
624 ProfileIOData* io_data =
625 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
626 const Extension* extension =
627 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
628 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52629 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19630 }
631 return true;
632}
633
634std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
635 const GURL& url, const content::ResourceContext& context) {
636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
637 // Check if it's an extension-created worker, in which case we want to use
638 // the name of the extension.
639 ProfileIOData* io_data =
640 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
641 const Extension* extension =
642 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
643 return extension ? extension->name() : std::string();
644}
645
[email protected]3cb054e62011-06-13 05:21:17646ResourceDispatcherHost*
647 ChromeContentBrowserClient::GetResourceDispatcherHost() {
648 return g_browser_process->resource_dispatcher_host();
649}
650
651ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
652 return g_browser_process->clipboard();
653}
654
[email protected]8f6a3b852011-07-19 16:48:56655MHTMLGenerationManager*
656 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
657 return g_browser_process->mhtml_generation_manager();
658}
659
[email protected]dce502762011-07-20 08:53:49660DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
661 return g_browser_process->devtools_manager();
662}
663
[email protected]ae6e9912011-07-27 01:18:28664net::NetLog* ChromeContentBrowserClient::GetNetLog() {
665 return g_browser_process->net_log();
666}
667
[email protected]dbae6b02011-06-29 23:51:41668bool ChromeContentBrowserClient::IsFastShutdownPossible() {
669 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
670 return !browser_command_line.HasSwitch(switches::kChromeFrame);
671}
672
[email protected]3d7474ff2011-07-27 17:47:37673WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
674 content::BrowserContext* browser_context, bool is_web_ui) {
675 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
676 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36677}
678
679void ChromeContentBrowserClient::UpdateInspectorSetting(
680 RenderViewHost* rvh, const std::string& key, const std::string& value) {
681 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37682 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36683}
684
685void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
686 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37687 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36688}
689
[email protected]b8148ac2011-07-13 22:03:25690void ChromeContentBrowserClient::BrowserURLHandlerCreated(
691 BrowserURLHandler* handler) {
692 // Add the default URL handlers.
693 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
694 BrowserURLHandler::null_handler());
695 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
696 &ExtensionWebUI::HandleChromeURLOverrideReverse);
697
698 // about:
699 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
700 BrowserURLHandler::null_handler());
701 // chrome: & friends.
702 handler->AddHandlerPair(&HandleWebUI,
703 BrowserURLHandler::null_handler());
704}
705
706void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37707 Profile* profile = Profile::FromBrowserContext(
708 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25709 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
710 BrowsingDataRemover::EVERYTHING,
711 base::Time());
712 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
713 // BrowsingDataRemover takes care of deleting itself when done.
714}
715
716void ChromeContentBrowserClient::ClearCookies(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 int remove_mask = BrowsingDataRemover::REMOVE_COOKIES;
723 remover->Remove(remove_mask);
724 // BrowsingDataRemover takes care of deleting itself when done.
725}
726
[email protected]e1d16eb92011-08-18 23:19:32727FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
728 return download_util::GetDefaultDownloadDirectory();
729}
730
[email protected]b68bf3892011-08-23 15:03:58731net::URLRequestContextGetter*
732ChromeContentBrowserClient::GetDefaultRequestContextDeprecatedCrBug64339() {
733 return Profile::Deprecated::GetDefaultRequestContext();
734}
735
[email protected]b80f68432011-05-02 17:22:30736#if defined(OS_LINUX)
737int ChromeContentBrowserClient::GetCrashSignalFD(
738 const std::string& process_type) {
739 if (process_type == switches::kRendererProcess)
740 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
741
[email protected]9dbfff12011-07-01 19:37:07742 if (process_type == switches::kExtensionProcess) {
743 ExtensionCrashHandlerHostLinux* crash_handler =
744 ExtensionCrashHandlerHostLinux::GetInstance();
745 return crash_handler->GetDeathSignalSocket();
746 }
747
[email protected]b80f68432011-05-02 17:22:30748 if (process_type == switches::kPluginProcess)
749 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
750
751 if (process_type == switches::kPpapiPluginProcess)
752 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
753
754 if (process_type == switches::kGpuProcess)
755 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
756
757 return -1;
758}
[email protected]9dbfff12011-07-01 19:37:07759#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30760
[email protected]37a72af2011-06-13 05:42:01761#if defined(USE_NSS)
762crypto::CryptoModuleBlockingPasswordDelegate*
763 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
764 const GURL& url) {
765 return browser::NewCryptoModuleBlockingDialogDelegate(
766 browser::kCryptoModulePasswordKeygen, url.host());
767}
768#endif
769
[email protected]d977f9c2011-03-14 16:10:26770} // namespace chrome