blob: f6f3f1347f2153003fa17421edc90c0891f14e3e [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
124 host->Send(new ViewMsg_SetIsIncognitoProcess(profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14125}
126
[email protected]97e6c4c2011-05-18 16:08:51127void ChromeContentBrowserClient::PluginProcessHostCreated(
128 PluginProcessHost* host) {
129 host->AddFilter(new ChromePluginMessageFilter(host));
130}
131
[email protected]5327dfb2011-05-03 17:50:36132void ChromeContentBrowserClient::WorkerProcessHostCreated(
133 WorkerProcessHost* host) {
134 host->AddFilter(new ChromeWorkerMessageFilter(host));
135}
136
[email protected]1fd1a502011-03-30 16:55:56137content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
138 return ChromeWebUIFactory::GetInstance();
139}
140
[email protected]3d7474ff2011-07-27 17:47:37141GURL ChromeContentBrowserClient::GetEffectiveURL(
142 content::BrowserContext* browser_context, const GURL& url) {
143 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08144 // Get the effective URL for the given actual URL. If the URL is part of an
145 // installed app, the effective URL is an extension URL with the ID of that
146 // extension as the host. This has the effect of grouping apps together in
147 // a common SiteInstance.
148 if (!profile || !profile->GetExtensionService())
149 return url;
150
151 const Extension* extension =
152 profile->GetExtensionService()->GetExtensionByWebExtent(url);
153 if (!extension)
154 return url;
155
156 // If the URL is part of an extension's web extent, convert it to an
157 // extension URL.
158 return extension->GetResourceURL(url.path());
159}
160
[email protected]056ad2a2011-07-12 02:13:55161bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37162 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55163 // Non-extension URLs should generally use process-per-site-instance.
164 // Because we expect to use the effective URL, hosted apps URLs should have
165 // an extension scheme by now.
166 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
167 return false;
168
[email protected]3d7474ff2011-07-27 17:47:37169 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55170 if (!profile || !profile->GetExtensionService())
171 return false;
172
173 const Extension* extension =
174 profile->GetExtensionService()->GetExtensionByURL(effective_url);
175 if (!extension)
176 return false;
177
178 // If the URL is part of a hosted app that does not have the background
179 // permission, we want to give each instance its own process to improve
180 // responsiveness.
181 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
182 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
183 return false;
184
185 // Hosted apps that have the background permission must use process per site,
186 // since all instances can make synchronous calls to the background window.
187 // Other extensions should use process per site as well.
188 return true;
189}
190
[email protected]0f012df82011-05-19 14:15:29191bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03192 return url == GURL(chrome::kChromeUICrashURL) ||
193 url == GURL(chrome::kChromeUIKillURL) ||
194 url == GURL(chrome::kChromeUIHangURL) ||
195 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29196}
197
[email protected]763ec4ca2011-04-29 15:48:12198std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
199 const std::string& alias_name) {
200 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
201}
202
[email protected]b80f68432011-05-02 17:22:30203void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
204 CommandLine* command_line, int child_process_id) {
205#if defined(USE_LINUX_BREAKPAD)
206 if (IsCrashReporterEnabled()) {
207 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
208 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
209 }
210#elif defined(OS_MACOSX)
211 if (IsCrashReporterEnabled()) {
212 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
213 child_process_logging::GetClientId());
214 }
215#endif // OS_MACOSX
216
[email protected]f1933792011-06-14 00:49:34217 if (logging::DialogsAreSuppressed())
218 command_line->AppendSwitch(switches::kNoErrorDialogs);
219
[email protected]b80f68432011-05-02 17:22:30220 std::string process_type =
221 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17222 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30223 if (process_type == switches::kExtensionProcess ||
224 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30225 FilePath user_data_dir =
226 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
227 if (!user_data_dir.empty())
228 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
229#if defined(OS_CHROMEOS)
230 const std::string& login_profile =
231 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
232 if (!login_profile.empty())
233 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
234#endif
235
236 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
237
[email protected]3d7474ff2011-07-27 17:47:37238 Profile* profile = Profile::FromBrowserContext(process->browser_context());
239 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30240 // Currently this pref is only registered if applied via a policy.
241 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
242 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
243 // Turn this policy into a command line switch.
244 command_line->AppendSwitch(switches::kDisable3DAPIs);
245 }
246
247 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46248 // in the Profile preferences or the browser process.
249 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
250 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30251 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46252 }
[email protected]4287a3d2011-06-13 23:56:51253
254 static const char* const kSwitchNames[] = {
255 switches::kAllowHTTPBackgroundPage,
256 switches::kAllowScriptingGallery,
257 switches::kAppsCheckoutURL,
258 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31259 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51260 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51261 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51262 switches::kDomAutomationController,
263 switches::kDumpHistogramsOnExit,
264 switches::kEnableClickToPlay,
265 switches::kEnableCrxlessWebApps,
266 switches::kEnableExperimentalExtensionApis,
267 switches::kEnableInBrowserThumbnailing,
[email protected]d0cf438c2011-08-18 03:08:52268 switches::kEnableInlineWebstoreInstall,
[email protected]4287a3d2011-06-13 23:56:51269 switches::kEnableIPCFuzzing,
270 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24271 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51272 switches::kEnableResourceContentSettings,
273 switches::kEnableSearchProviderApiV2,
274 switches::kEnableWatchdog,
275 switches::kExperimentalSpellcheckerFeatures,
276 switches::kMemoryProfiling,
277 switches::kMessageLoopHistogrammer,
278 switches::kPpapiFlashArgs,
279 switches::kPpapiFlashInProcess,
280 switches::kPpapiFlashPath,
281 switches::kPpapiFlashVersion,
282 switches::kProfilingAtStart,
283 switches::kProfilingFile,
284 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51285 switches::kSilentDumpOnDCHECK,
286 };
287
288 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
289 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17290 } else if (process_type == switches::kUtilityProcess) {
291 if (browser_command_line.HasSwitch(
292 switches::kEnableExperimentalExtensionApis)) {
293 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
294 }
[email protected]4287a3d2011-06-13 23:56:51295 } else if (process_type == switches::kPluginProcess) {
296 static const char* const kSwitchNames[] = {
297 #if defined(OS_CHROMEOS)
298 switches::kLoginProfile,
299 #endif
300 switches::kMemoryProfiling,
301 switches::kSilentDumpOnDCHECK,
302 switches::kUserDataDir,
303 };
304
305 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
306 arraysize(kSwitchNames));
307 } else if (process_type == switches::kZygoteProcess) {
308 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51309 switches::kUserDataDir, // Make logs go to the right file.
310 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
311 switches::kPpapiFlashInProcess,
312 switches::kPpapiFlashPath,
313 switches::kPpapiFlashVersion,
314 };
315
316 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
317 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30318 }
319}
320
321std::string ChromeContentBrowserClient::GetApplicationLocale() {
322 return g_browser_process->GetApplicationLocale();
323}
324
[email protected]b5cca982011-05-26 04:42:08325std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37326 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
327 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08328}
329
[email protected]ac55e292011-06-24 05:16:08330SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
331 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
332 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
333}
334
[email protected]a2176792011-05-08 19:30:49335bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09336 const GURL& manifest_url,
337 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
339 ProfileIOData* io_data =
340 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09341 // FIXME(jochen): get the correct top-level origin.
[email protected]efa55212011-05-13 16:19:38342 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]5b52ad42011-05-26 14:26:09343 GetCookieContentSetting(manifest_url, manifest_url, true);
[email protected]a2176792011-05-08 19:30:49344 DCHECK(setting != CONTENT_SETTING_DEFAULT);
345 return setting != CONTENT_SETTING_BLOCK;
346}
347
[email protected]ed24fad2011-05-10 22:44:01348bool ChromeContentBrowserClient::AllowGetCookie(
349 const GURL& url,
350 const GURL& first_party,
351 const net::CookieList& cookie_list,
352 const content::ResourceContext& context,
353 int render_process_id,
354 int render_view_id) {
355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32356 ProfileIOData* io_data =
357 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09358 ContentSetting setting = io_data->GetHostContentSettingsMap()->
359 GetCookieContentSetting(url, first_party, false);
360 bool allow = setting == CONTENT_SETTING_ALLOW ||
361 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01362
[email protected]8093a542011-05-13 07:29:32363 BrowserThread::PostTask(
364 BrowserThread::UI, FROM_HERE,
365 NewRunnableFunction(
366 &TabSpecificContentSettings::CookiesRead,
367 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01368 return allow;
369}
370
371bool ChromeContentBrowserClient::AllowSetCookie(
372 const GURL& url,
373 const GURL& first_party,
374 const std::string& cookie_line,
375 const content::ResourceContext& context,
376 int render_process_id,
377 int render_view_id,
378 net::CookieOptions* options) {
379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32380 ProfileIOData* io_data =
381 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09382 ContentSetting setting = io_data->GetHostContentSettingsMap()->
383 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01384
[email protected]5b52ad42011-05-26 14:26:09385 if (setting == CONTENT_SETTING_SESSION_ONLY)
386 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01387
[email protected]5b52ad42011-05-26 14:26:09388 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::CookieChanged,
395 render_process_id, render_view_id, url, cookie_line, *options,
396 !allow));
[email protected]ed24fad2011-05-10 22:44:01397 return allow;
398}
399
[email protected]d5a19162011-06-30 18:51:54400bool ChromeContentBrowserClient::AllowSaveLocalState(
401 const content::ResourceContext& context) {
402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
403 ProfileIOData* io_data =
404 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
405 return !io_data->clear_local_state_on_exit()->GetValue();
406}
407
[email protected]6133f922011-07-01 21:34:34408net::URLRequestContext*
409ChromeContentBrowserClient::OverrideRequestContextForURL(
410 const GURL& url, const content::ResourceContext& context) {
411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
412 if (url.SchemeIs(chrome::kExtensionScheme)) {
413 ProfileIOData* io_data =
414 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
415 return io_data->extensions_request_context();
416 }
417
418 return NULL;
419}
420
[email protected]317f96c92011-05-31 06:53:41421QuotaPermissionContext*
422ChromeContentBrowserClient::CreateQuotaPermissionContext() {
423 return new ChromeQuotaPermissionContext();
424}
425
[email protected]0609b17f2011-05-31 20:13:42426void ChromeContentBrowserClient::RevealFolderInOS(const FilePath& path) {
427 // On Mac, this call needs to be done on the UI thread. On other platforms,
428 // do it on the FILE thread so we don't slow down UI.
429#if defined(OS_MACOSX)
430 platform_util::OpenItem(path);
431#else
432 BrowserThread::PostTask(
433 BrowserThread::FILE, FROM_HERE,
434 NewRunnableFunction(&platform_util::OpenItem, path));
435#endif
436}
437
[email protected]848dd042011-06-04 18:24:03438void ChromeContentBrowserClient::AllowCertificateError(
439 SSLCertErrorHandler* handler,
440 bool overridable,
441 Callback2<SSLCertErrorHandler*, bool>::Type* callback) {
[email protected]f9034cf2011-07-21 12:43:41442 // If the tab is being prerendered, cancel the prerender and the request.
443 TabContents* tab = tab_util::GetTabContentsByID(
444 handler->render_process_host_id(),
445 handler->tab_contents_id());
446 if (!tab) {
447 NOTREACHED();
448 return;
449 }
450 prerender::PrerenderManager* prerender_manager =
[email protected]cafe4ad2011-07-28 18:34:56451 Profile::FromBrowserContext(tab->browser_context())->
452 GetPrerenderManager();
[email protected]f9034cf2011-07-21 12:43:41453 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
454 if (prerender_manager->prerender_tracker()->TryCancel(
455 handler->render_process_host_id(),
456 handler->tab_contents_id(),
457 prerender::FINAL_STATUS_SSL_ERROR)) {
458 handler->CancelRequest();
459 return;
460 }
461 }
462
463 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03464 SSLBlockingPage* blocking_page = new SSLBlockingPage(
465 handler, overridable, callback);
466 blocking_page->Show();
467}
468
[email protected]8ec26472011-06-06 16:52:45469void ChromeContentBrowserClient::ShowClientCertificateRequestDialog(
470 int render_process_id,
471 int render_view_id,
472 SSLClientAuthHandler* handler) {
473 TabContents* tab = tab_util::GetTabContentsByID(
474 render_process_id, render_view_id);
475 if (!tab) {
476 NOTREACHED();
477 return;
478 }
479
480 TabContentsWrapper* wrapper =
481 TabContentsWrapper::GetCurrentWrapperForContents(tab);
482 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
483}
484
485void ChromeContentBrowserClient::AddNewCertificate(
486 net::URLRequest* request,
487 net::X509Certificate* cert,
488 int render_process_id,
489 int render_view_id) {
490 // The handler will run the UI and delete itself when it's finished.
491 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
492}
493
[email protected]941623e2011-06-07 23:06:04494void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
495 const GURL& source_origin,
496 int callback_context,
497 int render_process_id,
498 int render_view_id) {
499 RenderViewHost* rvh = RenderViewHost::FromID(
500 render_process_id, render_view_id);
501 if (!rvh) {
502 NOTREACHED();
503 return;
504 }
505
506 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37507 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04508 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37509 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04510 service->RequestPermission(
511 source_origin, render_process_id, render_view_id, callback_context,
512 tab_util::GetTabContentsByID(render_process_id, render_view_id));
513}
514
515WebKit::WebNotificationPresenter::Permission
516 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
517 const GURL& source_url,
518 const content::ResourceContext& context) {
519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
520 ProfileIOData* io_data =
521 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
522
523 const Extension* extension =
524 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
525 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52526 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04527 return WebKit::WebNotificationPresenter::PermissionAllowed;
528 }
529
530 // Fall back to the regular notification preferences, which works on an
531 // origin basis.
532 return io_data->GetNotificationService() ?
533 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
534 WebKit::WebNotificationPresenter::PermissionNotAllowed;
535}
536
537void ChromeContentBrowserClient::ShowDesktopNotification(
538 const DesktopNotificationHostMsg_Show_Params& params,
539 int render_process_id,
540 int render_view_id,
541 bool worker) {
542 RenderViewHost* rvh = RenderViewHost::FromID(
543 render_process_id, render_view_id);
544 if (!rvh) {
545 NOTREACHED();
546 return;
547 }
548
549 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37550 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04551 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37552 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04553 service->ShowDesktopNotification(
554 params, render_process_id, render_view_id,
555 worker ? DesktopNotificationService::WorkerNotification :
556 DesktopNotificationService::PageNotification);
557}
558
559void ChromeContentBrowserClient::CancelDesktopNotification(
560 int render_process_id,
561 int render_view_id,
562 int notification_id) {
563 RenderViewHost* rvh = RenderViewHost::FromID(
564 render_process_id, render_view_id);
565 if (!rvh) {
566 NOTREACHED();
567 return;
568 }
569
570 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37571 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04572 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37573 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04574 service->CancelDesktopNotification(
575 render_process_id, render_view_id, notification_id);
576}
577
[email protected]9f3fba52011-06-08 20:37:19578bool ChromeContentBrowserClient::CanCreateWindow(
579 const GURL& source_url,
580 WindowContainerType container_type,
581 const content::ResourceContext& context) {
582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
583 // If the opener is trying to create a background window but doesn't have
584 // the appropriate permission, fail the attempt.
585 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
586 ProfileIOData* io_data =
587 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
588 const Extension* extension =
589 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
590 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52591 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19592 }
593 return true;
594}
595
596std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
597 const GURL& url, const content::ResourceContext& context) {
598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
599 // Check if it's an extension-created worker, in which case we want to use
600 // the name of the extension.
601 ProfileIOData* io_data =
602 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
603 const Extension* extension =
604 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
605 return extension ? extension->name() : std::string();
606}
607
[email protected]3cb054e62011-06-13 05:21:17608ResourceDispatcherHost*
609 ChromeContentBrowserClient::GetResourceDispatcherHost() {
610 return g_browser_process->resource_dispatcher_host();
611}
612
613ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
614 return g_browser_process->clipboard();
615}
616
[email protected]8f6a3b852011-07-19 16:48:56617MHTMLGenerationManager*
618 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
619 return g_browser_process->mhtml_generation_manager();
620}
621
[email protected]dce502762011-07-20 08:53:49622DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
623 return g_browser_process->devtools_manager();
624}
625
[email protected]ae6e9912011-07-27 01:18:28626net::NetLog* ChromeContentBrowserClient::GetNetLog() {
627 return g_browser_process->net_log();
628}
629
[email protected]dbae6b02011-06-29 23:51:41630bool ChromeContentBrowserClient::IsFastShutdownPossible() {
631 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
632 return !browser_command_line.HasSwitch(switches::kChromeFrame);
633}
634
[email protected]3d7474ff2011-07-27 17:47:37635WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
636 content::BrowserContext* browser_context, bool is_web_ui) {
637 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
638 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36639}
640
641void ChromeContentBrowserClient::UpdateInspectorSetting(
642 RenderViewHost* rvh, const std::string& key, const std::string& value) {
643 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37644 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36645}
646
647void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
648 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37649 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36650}
651
[email protected]b8148ac2011-07-13 22:03:25652void ChromeContentBrowserClient::BrowserURLHandlerCreated(
653 BrowserURLHandler* handler) {
654 // Add the default URL handlers.
655 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
656 BrowserURLHandler::null_handler());
657 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
658 &ExtensionWebUI::HandleChromeURLOverrideReverse);
659
660 // about:
661 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
662 BrowserURLHandler::null_handler());
663 // chrome: & friends.
664 handler->AddHandlerPair(&HandleWebUI,
665 BrowserURLHandler::null_handler());
666}
667
668void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37669 Profile* profile = Profile::FromBrowserContext(
670 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25671 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
672 BrowsingDataRemover::EVERYTHING,
673 base::Time());
674 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
675 // BrowsingDataRemover takes care of deleting itself when done.
676}
677
678void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37679 Profile* profile = Profile::FromBrowserContext(
680 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25681 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
682 BrowsingDataRemover::EVERYTHING,
683 base::Time());
684 int remove_mask = BrowsingDataRemover::REMOVE_COOKIES;
685 remover->Remove(remove_mask);
686 // BrowsingDataRemover takes care of deleting itself when done.
687}
688
[email protected]e1d16eb92011-08-18 23:19:32689FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
690 return download_util::GetDefaultDownloadDirectory();
691}
692
[email protected]b80f68432011-05-02 17:22:30693#if defined(OS_LINUX)
694int ChromeContentBrowserClient::GetCrashSignalFD(
695 const std::string& process_type) {
696 if (process_type == switches::kRendererProcess)
697 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
698
[email protected]9dbfff12011-07-01 19:37:07699 if (process_type == switches::kExtensionProcess) {
700 ExtensionCrashHandlerHostLinux* crash_handler =
701 ExtensionCrashHandlerHostLinux::GetInstance();
702 return crash_handler->GetDeathSignalSocket();
703 }
704
[email protected]b80f68432011-05-02 17:22:30705 if (process_type == switches::kPluginProcess)
706 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
707
708 if (process_type == switches::kPpapiPluginProcess)
709 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
710
711 if (process_type == switches::kGpuProcess)
712 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
713
714 return -1;
715}
[email protected]9dbfff12011-07-01 19:37:07716#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30717
[email protected]37a72af2011-06-13 05:42:01718#if defined(USE_NSS)
719crypto::CryptoModuleBlockingPasswordDelegate*
720 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
721 const GURL& url) {
722 return browser::NewCryptoModuleBlockingDialogDelegate(
723 browser::kCryptoModulePasswordKeygen, url.host());
724}
725#endif
726
[email protected]d977f9c2011-03-14 16:10:26727} // namespace chrome