blob: 8c6aeaf4001dc7d3b77f70744f882cfffbcf6fa7 [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]5327dfb2011-05-03 17:50:3664#include "content/browser/worker_host/worker_process_host.h"
[email protected]941623e2011-06-07 23:06:0465#include "content/common/desktop_notification_messages.h"
[email protected]29b25d092011-06-29 20:57:3466#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0167#include "net/base/cookie_monster.h"
68#include "net/base/cookie_options.h"
[email protected]ac55e292011-06-24 05:16:0869#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2670
[email protected]b80f68432011-05-02 17:22:3071#if defined(OS_LINUX)
72#include "base/linux_util.h"
73#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:4374#endif
[email protected]b80f68432011-05-02 17:22:3075
[email protected]37a72af2011-06-13 05:42:0176#if defined(USE_NSS)
77#include "chrome/browser/ui/crypto_module_password_dialog.h"
78#endif
79
[email protected]c5dbef02011-05-13 05:06:0980namespace {
81
[email protected]b8148ac2011-07-13 22:03:2582// Handles rewriting Web UI URLs.
[email protected]3d7474ff2011-07-27 17:47:3783static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
84 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:2585 return false;
86
87 // Special case the new tab page. In older versions of Chrome, the new tab
88 // page was hosted at chrome-internal:<blah>. This might be in people's saved
89 // sessions or bookmarks, so we say any URL with that scheme triggers the new
90 // tab page.
91 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
92 // Rewrite it with the proper new tab URL.
93 *url = GURL(chrome::kChromeUINewTabURL);
94 }
95
96 return true;
97}
98
[email protected]9dbfff12011-07-01 19:37:0799} // namespace
[email protected]c5dbef02011-05-13 05:06:09100
[email protected]d977f9c2011-03-14 16:10:26101namespace chrome {
102
[email protected]f364d1392011-04-08 21:03:10103void ChromeContentBrowserClient::RenderViewHostCreated(
104 RenderViewHost* render_view_host) {
[email protected]b503914162011-08-19 16:02:50105 new ChromeRenderViewHostObserver(render_view_host);
[email protected]f364d1392011-04-08 21:03:10106 new DevToolsHandler(render_view_host);
107 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26108}
109
[email protected]05fcf982011-04-19 00:44:14110void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
111 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02112 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37113 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14114 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02115 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14116 host->channel()->AddFilter(new PrintingMessageFilter());
117 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02118 new SearchProviderInstallStateMessageFilter(id, profile));
119 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]d4cff272011-05-02 15:46:01120#if defined(OS_MACOSX)
121 host->channel()->AddFilter(new TextInputClientMessageFilter(host->id()));
122#endif
[email protected]3e69bc82011-05-26 23:22:38123
[email protected]2ccf45c2011-08-19 23:35:50124 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
125 profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14126}
127
[email protected]97e6c4c2011-05-18 16:08:51128void ChromeContentBrowserClient::PluginProcessHostCreated(
129 PluginProcessHost* host) {
130 host->AddFilter(new ChromePluginMessageFilter(host));
131}
132
[email protected]5327dfb2011-05-03 17:50:36133void ChromeContentBrowserClient::WorkerProcessHostCreated(
134 WorkerProcessHost* host) {
135 host->AddFilter(new ChromeWorkerMessageFilter(host));
136}
137
[email protected]1fd1a502011-03-30 16:55:56138content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
139 return ChromeWebUIFactory::GetInstance();
140}
141
[email protected]3d7474ff2011-07-27 17:47:37142GURL ChromeContentBrowserClient::GetEffectiveURL(
143 content::BrowserContext* browser_context, const GURL& url) {
144 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08145 // Get the effective URL for the given actual URL. If the URL is part of an
146 // installed app, the effective URL is an extension URL with the ID of that
147 // extension as the host. This has the effect of grouping apps together in
148 // a common SiteInstance.
149 if (!profile || !profile->GetExtensionService())
150 return url;
151
152 const Extension* extension =
153 profile->GetExtensionService()->GetExtensionByWebExtent(url);
154 if (!extension)
155 return url;
156
157 // If the URL is part of an extension's web extent, convert it to an
158 // extension URL.
159 return extension->GetResourceURL(url.path());
160}
161
[email protected]056ad2a2011-07-12 02:13:55162bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37163 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55164 // Non-extension URLs should generally use process-per-site-instance.
165 // Because we expect to use the effective URL, hosted apps URLs should have
166 // an extension scheme by now.
167 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
168 return false;
169
[email protected]3d7474ff2011-07-27 17:47:37170 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55171 if (!profile || !profile->GetExtensionService())
172 return false;
173
174 const Extension* extension =
175 profile->GetExtensionService()->GetExtensionByURL(effective_url);
176 if (!extension)
177 return false;
178
179 // If the URL is part of a hosted app that does not have the background
180 // permission, we want to give each instance its own process to improve
181 // responsiveness.
182 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
183 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
184 return false;
185
186 // Hosted apps that have the background permission must use process per site,
187 // since all instances can make synchronous calls to the background window.
188 // Other extensions should use process per site as well.
189 return true;
190}
191
[email protected]0f012df82011-05-19 14:15:29192bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03193 return url == GURL(chrome::kChromeUICrashURL) ||
194 url == GURL(chrome::kChromeUIKillURL) ||
195 url == GURL(chrome::kChromeUIHangURL) ||
196 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29197}
198
[email protected]763ec4ca2011-04-29 15:48:12199std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
200 const std::string& alias_name) {
201 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
202}
203
[email protected]b80f68432011-05-02 17:22:30204void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
205 CommandLine* command_line, int child_process_id) {
206#if defined(USE_LINUX_BREAKPAD)
207 if (IsCrashReporterEnabled()) {
208 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
209 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
210 }
211#elif defined(OS_MACOSX)
212 if (IsCrashReporterEnabled()) {
213 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
214 child_process_logging::GetClientId());
215 }
216#endif // OS_MACOSX
217
[email protected]f1933792011-06-14 00:49:34218 if (logging::DialogsAreSuppressed())
219 command_line->AppendSwitch(switches::kNoErrorDialogs);
220
[email protected]b80f68432011-05-02 17:22:30221 std::string process_type =
222 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17223 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30224 if (process_type == switches::kExtensionProcess ||
225 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30226 FilePath user_data_dir =
227 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
228 if (!user_data_dir.empty())
229 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
230#if defined(OS_CHROMEOS)
231 const std::string& login_profile =
232 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
233 if (!login_profile.empty())
234 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
235#endif
236
237 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
238
[email protected]3d7474ff2011-07-27 17:47:37239 Profile* profile = Profile::FromBrowserContext(process->browser_context());
240 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30241 // Currently this pref is only registered if applied via a policy.
242 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
243 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
244 // Turn this policy into a command line switch.
245 command_line->AppendSwitch(switches::kDisable3DAPIs);
246 }
247
248 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46249 // in the Profile preferences or the browser process.
250 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
251 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30252 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46253 }
[email protected]4287a3d2011-06-13 23:56:51254
255 static const char* const kSwitchNames[] = {
256 switches::kAllowHTTPBackgroundPage,
257 switches::kAllowScriptingGallery,
258 switches::kAppsCheckoutURL,
259 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31260 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51261 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51262 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51263 switches::kDomAutomationController,
264 switches::kDumpHistogramsOnExit,
265 switches::kEnableClickToPlay,
266 switches::kEnableCrxlessWebApps,
267 switches::kEnableExperimentalExtensionApis,
268 switches::kEnableInBrowserThumbnailing,
[email protected]d0cf438c2011-08-18 03:08:52269 switches::kEnableInlineWebstoreInstall,
[email protected]4287a3d2011-06-13 23:56:51270 switches::kEnableIPCFuzzing,
271 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24272 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51273 switches::kEnableResourceContentSettings,
274 switches::kEnableSearchProviderApiV2,
275 switches::kEnableWatchdog,
276 switches::kExperimentalSpellcheckerFeatures,
277 switches::kMemoryProfiling,
278 switches::kMessageLoopHistogrammer,
279 switches::kPpapiFlashArgs,
280 switches::kPpapiFlashInProcess,
281 switches::kPpapiFlashPath,
282 switches::kPpapiFlashVersion,
283 switches::kProfilingAtStart,
284 switches::kProfilingFile,
285 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51286 switches::kSilentDumpOnDCHECK,
287 };
288
289 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
290 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17291 } else if (process_type == switches::kUtilityProcess) {
292 if (browser_command_line.HasSwitch(
293 switches::kEnableExperimentalExtensionApis)) {
294 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
295 }
[email protected]4287a3d2011-06-13 23:56:51296 } else if (process_type == switches::kPluginProcess) {
297 static const char* const kSwitchNames[] = {
298 #if defined(OS_CHROMEOS)
299 switches::kLoginProfile,
300 #endif
301 switches::kMemoryProfiling,
302 switches::kSilentDumpOnDCHECK,
303 switches::kUserDataDir,
304 };
305
306 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
307 arraysize(kSwitchNames));
308 } else if (process_type == switches::kZygoteProcess) {
309 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51310 switches::kUserDataDir, // Make logs go to the right file.
311 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
312 switches::kPpapiFlashInProcess,
313 switches::kPpapiFlashPath,
314 switches::kPpapiFlashVersion,
315 };
316
317 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
318 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30319 }
320}
321
322std::string ChromeContentBrowserClient::GetApplicationLocale() {
323 return g_browser_process->GetApplicationLocale();
324}
325
[email protected]b5cca982011-05-26 04:42:08326std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37327 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
328 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08329}
330
[email protected]ac55e292011-06-24 05:16:08331SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
332 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
333 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
334}
335
[email protected]a2176792011-05-08 19:30:49336bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09337 const GURL& manifest_url,
338 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
340 ProfileIOData* io_data =
341 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09342 // FIXME(jochen): get the correct top-level origin.
[email protected]efa55212011-05-13 16:19:38343 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]5b52ad42011-05-26 14:26:09344 GetCookieContentSetting(manifest_url, manifest_url, true);
[email protected]a2176792011-05-08 19:30:49345 DCHECK(setting != CONTENT_SETTING_DEFAULT);
346 return setting != CONTENT_SETTING_BLOCK;
347}
348
[email protected]ed24fad2011-05-10 22:44:01349bool ChromeContentBrowserClient::AllowGetCookie(
350 const GURL& url,
351 const GURL& first_party,
352 const net::CookieList& cookie_list,
353 const content::ResourceContext& context,
354 int render_process_id,
355 int render_view_id) {
356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32357 ProfileIOData* io_data =
358 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09359 ContentSetting setting = io_data->GetHostContentSettingsMap()->
360 GetCookieContentSetting(url, first_party, false);
361 bool allow = setting == CONTENT_SETTING_ALLOW ||
362 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01363
[email protected]8093a542011-05-13 07:29:32364 BrowserThread::PostTask(
365 BrowserThread::UI, FROM_HERE,
366 NewRunnableFunction(
367 &TabSpecificContentSettings::CookiesRead,
368 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01369 return allow;
370}
371
372bool ChromeContentBrowserClient::AllowSetCookie(
373 const GURL& url,
374 const GURL& first_party,
375 const std::string& cookie_line,
376 const content::ResourceContext& context,
377 int render_process_id,
378 int render_view_id,
379 net::CookieOptions* options) {
380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32381 ProfileIOData* io_data =
382 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09383 ContentSetting setting = io_data->GetHostContentSettingsMap()->
384 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01385
[email protected]5b52ad42011-05-26 14:26:09386 if (setting == CONTENT_SETTING_SESSION_ONLY)
387 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01388
[email protected]5b52ad42011-05-26 14:26:09389 bool allow = setting == CONTENT_SETTING_ALLOW ||
390 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01391
[email protected]8093a542011-05-13 07:29:32392 BrowserThread::PostTask(
393 BrowserThread::UI, FROM_HERE,
394 NewRunnableFunction(
395 &TabSpecificContentSettings::CookieChanged,
396 render_process_id, render_view_id, url, cookie_line, *options,
397 !allow));
[email protected]ed24fad2011-05-10 22:44:01398 return allow;
399}
400
[email protected]d5a19162011-06-30 18:51:54401bool ChromeContentBrowserClient::AllowSaveLocalState(
402 const content::ResourceContext& context) {
403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
404 ProfileIOData* io_data =
405 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
406 return !io_data->clear_local_state_on_exit()->GetValue();
407}
408
[email protected]6133f922011-07-01 21:34:34409net::URLRequestContext*
410ChromeContentBrowserClient::OverrideRequestContextForURL(
411 const GURL& url, const content::ResourceContext& context) {
412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
413 if (url.SchemeIs(chrome::kExtensionScheme)) {
414 ProfileIOData* io_data =
415 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
416 return io_data->extensions_request_context();
417 }
418
419 return NULL;
420}
421
[email protected]317f96c92011-05-31 06:53:41422QuotaPermissionContext*
423ChromeContentBrowserClient::CreateQuotaPermissionContext() {
424 return new ChromeQuotaPermissionContext();
425}
426
[email protected]a0ce3282011-08-19 20:49:52427void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42428 // On Mac, this call needs to be done on the UI thread. On other platforms,
429 // do it on the FILE thread so we don't slow down UI.
430#if defined(OS_MACOSX)
431 platform_util::OpenItem(path);
432#else
433 BrowserThread::PostTask(
434 BrowserThread::FILE, FROM_HERE,
435 NewRunnableFunction(&platform_util::OpenItem, path));
436#endif
437}
438
[email protected]a0ce3282011-08-19 20:49:52439void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
440#if defined(OS_MACOSX)
441 // Mac needs to run this operation on the UI thread.
442 platform_util::ShowItemInFolder(path);
443#else
444 BrowserThread::PostTask(
445 BrowserThread::FILE, FROM_HERE,
446 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
447#endif
448}
449
[email protected]848dd042011-06-04 18:24:03450void ChromeContentBrowserClient::AllowCertificateError(
451 SSLCertErrorHandler* handler,
452 bool overridable,
453 Callback2<SSLCertErrorHandler*, bool>::Type* callback) {
[email protected]f9034cf2011-07-21 12:43:41454 // If the tab is being prerendered, cancel the prerender and the request.
455 TabContents* tab = tab_util::GetTabContentsByID(
456 handler->render_process_host_id(),
457 handler->tab_contents_id());
458 if (!tab) {
459 NOTREACHED();
460 return;
461 }
462 prerender::PrerenderManager* prerender_manager =
[email protected]cafe4ad2011-07-28 18:34:56463 Profile::FromBrowserContext(tab->browser_context())->
464 GetPrerenderManager();
[email protected]f9034cf2011-07-21 12:43:41465 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
466 if (prerender_manager->prerender_tracker()->TryCancel(
467 handler->render_process_host_id(),
468 handler->tab_contents_id(),
469 prerender::FINAL_STATUS_SSL_ERROR)) {
470 handler->CancelRequest();
471 return;
472 }
473 }
474
475 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03476 SSLBlockingPage* blocking_page = new SSLBlockingPage(
477 handler, overridable, callback);
478 blocking_page->Show();
479}
480
[email protected]8ec26472011-06-06 16:52:45481void ChromeContentBrowserClient::ShowClientCertificateRequestDialog(
482 int render_process_id,
483 int render_view_id,
484 SSLClientAuthHandler* handler) {
485 TabContents* tab = tab_util::GetTabContentsByID(
486 render_process_id, render_view_id);
487 if (!tab) {
488 NOTREACHED();
489 return;
490 }
491
492 TabContentsWrapper* wrapper =
493 TabContentsWrapper::GetCurrentWrapperForContents(tab);
494 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
495}
496
497void ChromeContentBrowserClient::AddNewCertificate(
498 net::URLRequest* request,
499 net::X509Certificate* cert,
500 int render_process_id,
501 int render_view_id) {
502 // The handler will run the UI and delete itself when it's finished.
503 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
504}
505
[email protected]941623e2011-06-07 23:06:04506void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
507 const GURL& source_origin,
508 int callback_context,
509 int render_process_id,
510 int render_view_id) {
511 RenderViewHost* rvh = RenderViewHost::FromID(
512 render_process_id, render_view_id);
513 if (!rvh) {
514 NOTREACHED();
515 return;
516 }
517
518 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37519 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04520 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37521 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04522 service->RequestPermission(
523 source_origin, render_process_id, render_view_id, callback_context,
524 tab_util::GetTabContentsByID(render_process_id, render_view_id));
525}
526
527WebKit::WebNotificationPresenter::Permission
528 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
529 const GURL& source_url,
530 const content::ResourceContext& context) {
531 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
532 ProfileIOData* io_data =
533 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
534
535 const Extension* extension =
536 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
537 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52538 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04539 return WebKit::WebNotificationPresenter::PermissionAllowed;
540 }
541
542 // Fall back to the regular notification preferences, which works on an
543 // origin basis.
544 return io_data->GetNotificationService() ?
545 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
546 WebKit::WebNotificationPresenter::PermissionNotAllowed;
547}
548
549void ChromeContentBrowserClient::ShowDesktopNotification(
550 const DesktopNotificationHostMsg_Show_Params& params,
551 int render_process_id,
552 int render_view_id,
553 bool worker) {
554 RenderViewHost* rvh = RenderViewHost::FromID(
555 render_process_id, render_view_id);
556 if (!rvh) {
557 NOTREACHED();
558 return;
559 }
560
561 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37562 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04563 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37564 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04565 service->ShowDesktopNotification(
566 params, render_process_id, render_view_id,
567 worker ? DesktopNotificationService::WorkerNotification :
568 DesktopNotificationService::PageNotification);
569}
570
571void ChromeContentBrowserClient::CancelDesktopNotification(
572 int render_process_id,
573 int render_view_id,
574 int notification_id) {
575 RenderViewHost* rvh = RenderViewHost::FromID(
576 render_process_id, render_view_id);
577 if (!rvh) {
578 NOTREACHED();
579 return;
580 }
581
582 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37583 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04584 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37585 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04586 service->CancelDesktopNotification(
587 render_process_id, render_view_id, notification_id);
588}
589
[email protected]9f3fba52011-06-08 20:37:19590bool ChromeContentBrowserClient::CanCreateWindow(
591 const GURL& source_url,
592 WindowContainerType container_type,
593 const content::ResourceContext& context) {
594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
595 // If the opener is trying to create a background window but doesn't have
596 // the appropriate permission, fail the attempt.
597 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
598 ProfileIOData* io_data =
599 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
600 const Extension* extension =
601 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
602 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52603 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19604 }
605 return true;
606}
607
608std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
609 const GURL& url, const content::ResourceContext& context) {
610 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
611 // Check if it's an extension-created worker, in which case we want to use
612 // the name of the extension.
613 ProfileIOData* io_data =
614 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
615 const Extension* extension =
616 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
617 return extension ? extension->name() : std::string();
618}
619
[email protected]3cb054e62011-06-13 05:21:17620ResourceDispatcherHost*
621 ChromeContentBrowserClient::GetResourceDispatcherHost() {
622 return g_browser_process->resource_dispatcher_host();
623}
624
625ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
626 return g_browser_process->clipboard();
627}
628
[email protected]8f6a3b852011-07-19 16:48:56629MHTMLGenerationManager*
630 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
631 return g_browser_process->mhtml_generation_manager();
632}
633
[email protected]dce502762011-07-20 08:53:49634DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
635 return g_browser_process->devtools_manager();
636}
637
[email protected]ae6e9912011-07-27 01:18:28638net::NetLog* ChromeContentBrowserClient::GetNetLog() {
639 return g_browser_process->net_log();
640}
641
[email protected]dbae6b02011-06-29 23:51:41642bool ChromeContentBrowserClient::IsFastShutdownPossible() {
643 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
644 return !browser_command_line.HasSwitch(switches::kChromeFrame);
645}
646
[email protected]3d7474ff2011-07-27 17:47:37647WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
648 content::BrowserContext* browser_context, bool is_web_ui) {
649 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
650 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36651}
652
653void ChromeContentBrowserClient::UpdateInspectorSetting(
654 RenderViewHost* rvh, const std::string& key, const std::string& value) {
655 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37656 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36657}
658
659void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
660 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37661 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36662}
663
[email protected]b8148ac2011-07-13 22:03:25664void ChromeContentBrowserClient::BrowserURLHandlerCreated(
665 BrowserURLHandler* handler) {
666 // Add the default URL handlers.
667 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
668 BrowserURLHandler::null_handler());
669 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
670 &ExtensionWebUI::HandleChromeURLOverrideReverse);
671
672 // about:
673 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
674 BrowserURLHandler::null_handler());
675 // chrome: & friends.
676 handler->AddHandlerPair(&HandleWebUI,
677 BrowserURLHandler::null_handler());
678}
679
680void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37681 Profile* profile = Profile::FromBrowserContext(
682 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25683 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
684 BrowsingDataRemover::EVERYTHING,
685 base::Time());
686 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
687 // BrowsingDataRemover takes care of deleting itself when done.
688}
689
690void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37691 Profile* profile = Profile::FromBrowserContext(
692 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25693 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
694 BrowsingDataRemover::EVERYTHING,
695 base::Time());
696 int remove_mask = BrowsingDataRemover::REMOVE_COOKIES;
697 remover->Remove(remove_mask);
698 // BrowsingDataRemover takes care of deleting itself when done.
699}
700
[email protected]e1d16eb92011-08-18 23:19:32701FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
702 return download_util::GetDefaultDownloadDirectory();
703}
704
[email protected]b80f68432011-05-02 17:22:30705#if defined(OS_LINUX)
706int ChromeContentBrowserClient::GetCrashSignalFD(
707 const std::string& process_type) {
708 if (process_type == switches::kRendererProcess)
709 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
710
[email protected]9dbfff12011-07-01 19:37:07711 if (process_type == switches::kExtensionProcess) {
712 ExtensionCrashHandlerHostLinux* crash_handler =
713 ExtensionCrashHandlerHostLinux::GetInstance();
714 return crash_handler->GetDeathSignalSocket();
715 }
716
[email protected]b80f68432011-05-02 17:22:30717 if (process_type == switches::kPluginProcess)
718 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
719
720 if (process_type == switches::kPpapiPluginProcess)
721 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
722
723 if (process_type == switches::kGpuProcess)
724 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
725
726 return -1;
727}
[email protected]9dbfff12011-07-01 19:37:07728#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30729
[email protected]37a72af2011-06-13 05:42:01730#if defined(USE_NSS)
731crypto::CryptoModuleBlockingPasswordDelegate*
732 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
733 const GURL& url) {
734 return browser::NewCryptoModuleBlockingDialogDelegate(
735 browser::kCryptoModulePasswordKeygen, url.host());
736}
737#endif
738
[email protected]d977f9c2011-03-14 16:10:26739} // namespace chrome