blob: c8f84c274e13d88c1d46ed1f53f0a5a1f93d0b2b [file] [log] [blame]
[email protected]d977f9c2011-03-14 16:10:261// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]b80f68432011-05-02 17:22:307#include "base/command_line.h"
8#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:259#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3010#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2311#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1212#include "chrome/browser/character_encoding.h"
[email protected]97e6c4c2011-05-18 16:08:5113#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4114#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]5327dfb2011-05-03 17:50:3615#include "chrome/browser/chrome_worker_message_filter.h"
[email protected]a2176792011-05-08 19:30:4916#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3217#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]e1d16eb92011-08-18 23:19:3218#include "chrome/browser/download/download_util.h"
[email protected]941623e2011-06-07 23:06:0419#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1020#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2621#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2522#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]32538d92011-08-25 00:09:2323#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1224#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2825#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0426#include "chrome/browser/notifications/desktop_notification_service.h"
27#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4228#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1229#include "chrome/browser/prefs/pref_service.h"
[email protected]f9034cf2011-07-21 12:43:4130#include "chrome/browser/prerender/prerender_manager.h"
31#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1432#include "chrome/browser/printing/printing_message_filter.h"
33#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3234#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1435#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3336#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]d4cff272011-05-02 15:46:0137#include "chrome/browser/renderer_host/text_input_client_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1438#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0439#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4640#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4541#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0342#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3643#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4544#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
45#include "chrome/browser/tab_contents/tab_util.h"
46#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5647#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3048#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0149#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3050#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0451#include "chrome/common/extensions/extension.h"
[email protected]f1933792011-06-14 00:49:3452#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1253#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3854#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0955#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2556#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0957#include "content/browser/browsing_instance.h"
[email protected]b46442d7e2011-06-29 02:16:0658#include "content/browser/debugger/devtools_handler.h"
[email protected]97e6c4c2011-05-18 16:08:5159#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1460#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2661#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4962#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0963#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4164#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4565#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1266#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3267#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3668#include "content/browser/worker_host/worker_process_host.h"
[email protected]941623e2011-06-07 23:06:0469#include "content/common/desktop_notification_messages.h"
[email protected]29b25d092011-06-29 20:57:3470#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0171#include "net/base/cookie_monster.h"
72#include "net/base/cookie_options.h"
[email protected]ac55e292011-06-24 05:16:0873#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2674
[email protected]b80f68432011-05-02 17:22:3075#if defined(OS_LINUX)
76#include "base/linux_util.h"
77#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:4378#endif
[email protected]b80f68432011-05-02 17:22:3079
[email protected]bb6dcbb2011-08-24 17:05:2080#if defined(TOUCH_UI)
81#include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h"
82#elif defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:3283#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
84#elif defined(OS_LINUX)
85#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
86#elif defined(OS_MACOSX)
87#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:3288#endif
89
[email protected]37a72af2011-06-13 05:42:0190#if defined(USE_NSS)
91#include "chrome/browser/ui/crypto_module_password_dialog.h"
92#endif
93
[email protected]c5dbef02011-05-13 05:06:0994namespace {
95
[email protected]b8148ac2011-07-13 22:03:2596// Handles rewriting Web UI URLs.
[email protected]3d7474ff2011-07-27 17:47:3797static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
98 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:2599 return false;
100
101 // Special case the new tab page. In older versions of Chrome, the new tab
102 // page was hosted at chrome-internal:<blah>. This might be in people's saved
103 // sessions or bookmarks, so we say any URL with that scheme triggers the new
104 // tab page.
105 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
106 // Rewrite it with the proper new tab URL.
107 *url = GURL(chrome::kChromeUINewTabURL);
108 }
109
110 return true;
111}
112
[email protected]9dbfff12011-07-01 19:37:07113} // namespace
[email protected]c5dbef02011-05-13 05:06:09114
[email protected]d977f9c2011-03-14 16:10:26115namespace chrome {
116
[email protected]74313b42011-08-24 16:51:32117TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
118 TabContents* tab_contents) {
[email protected]bb6dcbb2011-08-24 17:05:20119#if defined(TOUCH_UI)
120 return new TabContentsViewTouch(tab_contents);
121#elif defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32122 return new TabContentsViewViews(tab_contents);
123#elif defined(OS_LINUX)
124 return new TabContentsViewGtk(tab_contents);
125#elif defined(OS_MACOSX)
126 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32127#else
128#error Need to create your platform TabContentsView here.
129#endif
130}
131
[email protected]f364d1392011-04-08 21:03:10132void ChromeContentBrowserClient::RenderViewHostCreated(
133 RenderViewHost* render_view_host) {
[email protected]b503914162011-08-19 16:02:50134 new ChromeRenderViewHostObserver(render_view_host);
[email protected]f364d1392011-04-08 21:03:10135 new DevToolsHandler(render_view_host);
136 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26137}
138
[email protected]05fcf982011-04-19 00:44:14139void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
140 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02141 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37142 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14143 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02144 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14145 host->channel()->AddFilter(new PrintingMessageFilter());
146 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02147 new SearchProviderInstallStateMessageFilter(id, profile));
148 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]d4cff272011-05-02 15:46:01149#if defined(OS_MACOSX)
150 host->channel()->AddFilter(new TextInputClientMessageFilter(host->id()));
151#endif
[email protected]3e69bc82011-05-26 23:22:38152
[email protected]2ccf45c2011-08-19 23:35:50153 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
154 profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14155}
156
[email protected]97e6c4c2011-05-18 16:08:51157void ChromeContentBrowserClient::PluginProcessHostCreated(
158 PluginProcessHost* host) {
159 host->AddFilter(new ChromePluginMessageFilter(host));
160}
161
[email protected]5327dfb2011-05-03 17:50:36162void ChromeContentBrowserClient::WorkerProcessHostCreated(
163 WorkerProcessHost* host) {
164 host->AddFilter(new ChromeWorkerMessageFilter(host));
165}
166
[email protected]1fd1a502011-03-30 16:55:56167content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
168 return ChromeWebUIFactory::GetInstance();
169}
170
[email protected]3d7474ff2011-07-27 17:47:37171GURL ChromeContentBrowserClient::GetEffectiveURL(
172 content::BrowserContext* browser_context, const GURL& url) {
173 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08174 // Get the effective URL for the given actual URL. If the URL is part of an
175 // installed app, the effective URL is an extension URL with the ID of that
176 // extension as the host. This has the effect of grouping apps together in
177 // a common SiteInstance.
178 if (!profile || !profile->GetExtensionService())
179 return url;
180
181 const Extension* extension =
182 profile->GetExtensionService()->GetExtensionByWebExtent(url);
183 if (!extension)
184 return url;
185
186 // If the URL is part of an extension's web extent, convert it to an
187 // extension URL.
188 return extension->GetResourceURL(url.path());
189}
190
[email protected]056ad2a2011-07-12 02:13:55191bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37192 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55193 // Non-extension URLs should generally use process-per-site-instance.
194 // Because we expect to use the effective URL, hosted apps URLs should have
195 // an extension scheme by now.
196 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
197 return false;
198
[email protected]3d7474ff2011-07-27 17:47:37199 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55200 if (!profile || !profile->GetExtensionService())
201 return false;
202
203 const Extension* extension =
204 profile->GetExtensionService()->GetExtensionByURL(effective_url);
205 if (!extension)
206 return false;
207
208 // If the URL is part of a hosted app that does not have the background
209 // permission, we want to give each instance its own process to improve
210 // responsiveness.
211 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
212 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
213 return false;
214
215 // Hosted apps that have the background permission must use process per site,
216 // since all instances can make synchronous calls to the background window.
217 // Other extensions should use process per site as well.
218 return true;
219}
220
[email protected]0f012df82011-05-19 14:15:29221bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03222 return url == GURL(chrome::kChromeUICrashURL) ||
223 url == GURL(chrome::kChromeUIKillURL) ||
224 url == GURL(chrome::kChromeUIHangURL) ||
225 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29226}
227
[email protected]763ec4ca2011-04-29 15:48:12228std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
229 const std::string& alias_name) {
230 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
231}
232
[email protected]b80f68432011-05-02 17:22:30233void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
234 CommandLine* command_line, int child_process_id) {
235#if defined(USE_LINUX_BREAKPAD)
236 if (IsCrashReporterEnabled()) {
237 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
238 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
239 }
240#elif defined(OS_MACOSX)
241 if (IsCrashReporterEnabled()) {
242 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
243 child_process_logging::GetClientId());
244 }
245#endif // OS_MACOSX
246
[email protected]f1933792011-06-14 00:49:34247 if (logging::DialogsAreSuppressed())
248 command_line->AppendSwitch(switches::kNoErrorDialogs);
249
[email protected]b80f68432011-05-02 17:22:30250 std::string process_type =
251 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17252 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30253 if (process_type == switches::kExtensionProcess ||
254 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30255 FilePath user_data_dir =
256 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
257 if (!user_data_dir.empty())
258 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
259#if defined(OS_CHROMEOS)
260 const std::string& login_profile =
261 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
262 if (!login_profile.empty())
263 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
264#endif
265
266 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
267
[email protected]3d7474ff2011-07-27 17:47:37268 Profile* profile = Profile::FromBrowserContext(process->browser_context());
269 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30270 // Currently this pref is only registered if applied via a policy.
271 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
272 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
273 // Turn this policy into a command line switch.
274 command_line->AppendSwitch(switches::kDisable3DAPIs);
275 }
276
277 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46278 // in the Profile preferences or the browser process.
279 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
280 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30281 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46282 }
[email protected]4287a3d2011-06-13 23:56:51283
284 static const char* const kSwitchNames[] = {
285 switches::kAllowHTTPBackgroundPage,
286 switches::kAllowScriptingGallery,
287 switches::kAppsCheckoutURL,
288 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31289 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51290 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51291 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51292 switches::kDomAutomationController,
293 switches::kDumpHistogramsOnExit,
294 switches::kEnableClickToPlay,
295 switches::kEnableCrxlessWebApps,
296 switches::kEnableExperimentalExtensionApis,
297 switches::kEnableInBrowserThumbnailing,
[email protected]d0cf438c2011-08-18 03:08:52298 switches::kEnableInlineWebstoreInstall,
[email protected]4287a3d2011-06-13 23:56:51299 switches::kEnableIPCFuzzing,
300 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24301 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51302 switches::kEnableResourceContentSettings,
303 switches::kEnableSearchProviderApiV2,
304 switches::kEnableWatchdog,
305 switches::kExperimentalSpellcheckerFeatures,
306 switches::kMemoryProfiling,
307 switches::kMessageLoopHistogrammer,
308 switches::kPpapiFlashArgs,
309 switches::kPpapiFlashInProcess,
310 switches::kPpapiFlashPath,
311 switches::kPpapiFlashVersion,
312 switches::kProfilingAtStart,
313 switches::kProfilingFile,
314 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51315 switches::kSilentDumpOnDCHECK,
316 };
317
318 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
319 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17320 } else if (process_type == switches::kUtilityProcess) {
321 if (browser_command_line.HasSwitch(
322 switches::kEnableExperimentalExtensionApis)) {
323 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
324 }
[email protected]4287a3d2011-06-13 23:56:51325 } else if (process_type == switches::kPluginProcess) {
326 static const char* const kSwitchNames[] = {
327 #if defined(OS_CHROMEOS)
328 switches::kLoginProfile,
329 #endif
330 switches::kMemoryProfiling,
331 switches::kSilentDumpOnDCHECK,
332 switches::kUserDataDir,
333 };
334
335 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
336 arraysize(kSwitchNames));
337 } else if (process_type == switches::kZygoteProcess) {
338 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51339 switches::kUserDataDir, // Make logs go to the right file.
340 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
341 switches::kPpapiFlashInProcess,
342 switches::kPpapiFlashPath,
343 switches::kPpapiFlashVersion,
344 };
345
346 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
347 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30348 }
349}
350
351std::string ChromeContentBrowserClient::GetApplicationLocale() {
352 return g_browser_process->GetApplicationLocale();
353}
354
[email protected]b5cca982011-05-26 04:42:08355std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37356 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
357 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08358}
359
[email protected]ac55e292011-06-24 05:16:08360SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
361 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
362 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
363}
364
[email protected]a2176792011-05-08 19:30:49365bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09366 const GURL& manifest_url,
367 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
369 ProfileIOData* io_data =
370 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09371 // FIXME(jochen): get the correct top-level origin.
[email protected]efa55212011-05-13 16:19:38372 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]5b52ad42011-05-26 14:26:09373 GetCookieContentSetting(manifest_url, manifest_url, true);
[email protected]a2176792011-05-08 19:30:49374 DCHECK(setting != CONTENT_SETTING_DEFAULT);
375 return setting != CONTENT_SETTING_BLOCK;
376}
377
[email protected]ed24fad2011-05-10 22:44:01378bool ChromeContentBrowserClient::AllowGetCookie(
379 const GURL& url,
380 const GURL& first_party,
381 const net::CookieList& cookie_list,
382 const content::ResourceContext& context,
383 int render_process_id,
384 int render_view_id) {
385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32386 ProfileIOData* io_data =
387 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09388 ContentSetting setting = io_data->GetHostContentSettingsMap()->
389 GetCookieContentSetting(url, first_party, false);
390 bool allow = setting == CONTENT_SETTING_ALLOW ||
391 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01392
[email protected]8093a542011-05-13 07:29:32393 BrowserThread::PostTask(
394 BrowserThread::UI, FROM_HERE,
395 NewRunnableFunction(
396 &TabSpecificContentSettings::CookiesRead,
397 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01398 return allow;
399}
400
401bool ChromeContentBrowserClient::AllowSetCookie(
402 const GURL& url,
403 const GURL& first_party,
404 const std::string& cookie_line,
405 const content::ResourceContext& context,
406 int render_process_id,
407 int render_view_id,
408 net::CookieOptions* options) {
409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32410 ProfileIOData* io_data =
411 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09412 ContentSetting setting = io_data->GetHostContentSettingsMap()->
413 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01414
[email protected]5b52ad42011-05-26 14:26:09415 if (setting == CONTENT_SETTING_SESSION_ONLY)
416 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01417
[email protected]5b52ad42011-05-26 14:26:09418 bool allow = setting == CONTENT_SETTING_ALLOW ||
419 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01420
[email protected]8093a542011-05-13 07:29:32421 BrowserThread::PostTask(
422 BrowserThread::UI, FROM_HERE,
423 NewRunnableFunction(
424 &TabSpecificContentSettings::CookieChanged,
425 render_process_id, render_view_id, url, cookie_line, *options,
426 !allow));
[email protected]ed24fad2011-05-10 22:44:01427 return allow;
428}
429
[email protected]d5a19162011-06-30 18:51:54430bool ChromeContentBrowserClient::AllowSaveLocalState(
431 const content::ResourceContext& context) {
432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
433 ProfileIOData* io_data =
434 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
435 return !io_data->clear_local_state_on_exit()->GetValue();
436}
437
[email protected]6133f922011-07-01 21:34:34438net::URLRequestContext*
439ChromeContentBrowserClient::OverrideRequestContextForURL(
440 const GURL& url, const content::ResourceContext& context) {
441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
442 if (url.SchemeIs(chrome::kExtensionScheme)) {
443 ProfileIOData* io_data =
444 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
445 return io_data->extensions_request_context();
446 }
447
448 return NULL;
449}
450
[email protected]317f96c92011-05-31 06:53:41451QuotaPermissionContext*
452ChromeContentBrowserClient::CreateQuotaPermissionContext() {
453 return new ChromeQuotaPermissionContext();
454}
455
[email protected]a0ce3282011-08-19 20:49:52456void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42457 // On Mac, this call needs to be done on the UI thread. On other platforms,
458 // do it on the FILE thread so we don't slow down UI.
459#if defined(OS_MACOSX)
460 platform_util::OpenItem(path);
461#else
462 BrowserThread::PostTask(
463 BrowserThread::FILE, FROM_HERE,
464 NewRunnableFunction(&platform_util::OpenItem, path));
465#endif
466}
467
[email protected]a0ce3282011-08-19 20:49:52468void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
469#if defined(OS_MACOSX)
470 // Mac needs to run this operation on the UI thread.
471 platform_util::ShowItemInFolder(path);
472#else
473 BrowserThread::PostTask(
474 BrowserThread::FILE, FROM_HERE,
475 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
476#endif
477}
478
[email protected]848dd042011-06-04 18:24:03479void ChromeContentBrowserClient::AllowCertificateError(
480 SSLCertErrorHandler* handler,
481 bool overridable,
482 Callback2<SSLCertErrorHandler*, bool>::Type* callback) {
[email protected]f9034cf2011-07-21 12:43:41483 // If the tab is being prerendered, cancel the prerender and the request.
484 TabContents* tab = tab_util::GetTabContentsByID(
485 handler->render_process_host_id(),
486 handler->tab_contents_id());
487 if (!tab) {
488 NOTREACHED();
489 return;
490 }
491 prerender::PrerenderManager* prerender_manager =
[email protected]cafe4ad2011-07-28 18:34:56492 Profile::FromBrowserContext(tab->browser_context())->
493 GetPrerenderManager();
[email protected]f9034cf2011-07-21 12:43:41494 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
495 if (prerender_manager->prerender_tracker()->TryCancel(
496 handler->render_process_host_id(),
497 handler->tab_contents_id(),
498 prerender::FINAL_STATUS_SSL_ERROR)) {
499 handler->CancelRequest();
500 return;
501 }
502 }
503
504 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03505 SSLBlockingPage* blocking_page = new SSLBlockingPage(
506 handler, overridable, callback);
507 blocking_page->Show();
508}
509
[email protected]c99c442e2011-08-24 11:37:30510void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45511 int render_process_id,
512 int render_view_id,
513 SSLClientAuthHandler* handler) {
514 TabContents* tab = tab_util::GetTabContentsByID(
515 render_process_id, render_view_id);
516 if (!tab) {
517 NOTREACHED();
518 return;
519 }
520
521 TabContentsWrapper* wrapper =
522 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30523 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45524}
525
526void ChromeContentBrowserClient::AddNewCertificate(
527 net::URLRequest* request,
528 net::X509Certificate* cert,
529 int render_process_id,
530 int render_view_id) {
531 // The handler will run the UI and delete itself when it's finished.
532 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
533}
534
[email protected]941623e2011-06-07 23:06:04535void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
536 const GURL& source_origin,
537 int callback_context,
538 int render_process_id,
539 int render_view_id) {
540 RenderViewHost* rvh = RenderViewHost::FromID(
541 render_process_id, render_view_id);
542 if (!rvh) {
543 NOTREACHED();
544 return;
545 }
546
547 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37548 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04549 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37550 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04551 service->RequestPermission(
552 source_origin, render_process_id, render_view_id, callback_context,
553 tab_util::GetTabContentsByID(render_process_id, render_view_id));
554}
555
556WebKit::WebNotificationPresenter::Permission
557 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
558 const GURL& source_url,
559 const content::ResourceContext& context) {
560 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
561 ProfileIOData* io_data =
562 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
563
564 const Extension* extension =
565 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
566 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52567 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04568 return WebKit::WebNotificationPresenter::PermissionAllowed;
569 }
570
571 // Fall back to the regular notification preferences, which works on an
572 // origin basis.
573 return io_data->GetNotificationService() ?
574 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
575 WebKit::WebNotificationPresenter::PermissionNotAllowed;
576}
577
578void ChromeContentBrowserClient::ShowDesktopNotification(
579 const DesktopNotificationHostMsg_Show_Params& params,
580 int render_process_id,
581 int render_view_id,
582 bool worker) {
583 RenderViewHost* rvh = RenderViewHost::FromID(
584 render_process_id, render_view_id);
585 if (!rvh) {
586 NOTREACHED();
587 return;
588 }
589
590 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37591 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04592 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37593 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04594 service->ShowDesktopNotification(
595 params, render_process_id, render_view_id,
596 worker ? DesktopNotificationService::WorkerNotification :
597 DesktopNotificationService::PageNotification);
598}
599
600void ChromeContentBrowserClient::CancelDesktopNotification(
601 int render_process_id,
602 int render_view_id,
603 int notification_id) {
604 RenderViewHost* rvh = RenderViewHost::FromID(
605 render_process_id, render_view_id);
606 if (!rvh) {
607 NOTREACHED();
608 return;
609 }
610
611 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37612 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04613 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37614 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04615 service->CancelDesktopNotification(
616 render_process_id, render_view_id, notification_id);
617}
618
[email protected]9f3fba52011-06-08 20:37:19619bool ChromeContentBrowserClient::CanCreateWindow(
620 const GURL& source_url,
621 WindowContainerType container_type,
622 const content::ResourceContext& context) {
623 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
624 // If the opener is trying to create a background window but doesn't have
625 // the appropriate permission, fail the attempt.
626 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
627 ProfileIOData* io_data =
628 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
629 const Extension* extension =
630 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
631 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52632 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19633 }
634 return true;
635}
636
637std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
638 const GURL& url, const content::ResourceContext& context) {
639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
640 // Check if it's an extension-created worker, in which case we want to use
641 // the name of the extension.
642 ProfileIOData* io_data =
643 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
644 const Extension* extension =
645 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
646 return extension ? extension->name() : std::string();
647}
648
[email protected]3cb054e62011-06-13 05:21:17649ResourceDispatcherHost*
650 ChromeContentBrowserClient::GetResourceDispatcherHost() {
651 return g_browser_process->resource_dispatcher_host();
652}
653
654ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
655 return g_browser_process->clipboard();
656}
657
[email protected]8f6a3b852011-07-19 16:48:56658MHTMLGenerationManager*
659 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
660 return g_browser_process->mhtml_generation_manager();
661}
662
[email protected]dce502762011-07-20 08:53:49663DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
664 return g_browser_process->devtools_manager();
665}
666
[email protected]ae6e9912011-07-27 01:18:28667net::NetLog* ChromeContentBrowserClient::GetNetLog() {
668 return g_browser_process->net_log();
669}
670
[email protected]3bc0b562011-08-24 23:51:04671speech_input::SpeechInputManager*
672 ChromeContentBrowserClient::GetSpeechInputManager() {
673 return speech_input::ChromeSpeechInputManager::GetInstance();
674}
675
[email protected]32538d92011-08-25 00:09:23676AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
677 return new ChromeAccessTokenStore();
678}
679
[email protected]dbae6b02011-06-29 23:51:41680bool ChromeContentBrowserClient::IsFastShutdownPossible() {
681 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
682 return !browser_command_line.HasSwitch(switches::kChromeFrame);
683}
684
[email protected]3d7474ff2011-07-27 17:47:37685WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
686 content::BrowserContext* browser_context, bool is_web_ui) {
687 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
688 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36689}
690
691void ChromeContentBrowserClient::UpdateInspectorSetting(
692 RenderViewHost* rvh, const std::string& key, const std::string& value) {
693 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37694 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36695}
696
697void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
698 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37699 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36700}
701
[email protected]b8148ac2011-07-13 22:03:25702void ChromeContentBrowserClient::BrowserURLHandlerCreated(
703 BrowserURLHandler* handler) {
704 // Add the default URL handlers.
705 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
706 BrowserURLHandler::null_handler());
707 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
708 &ExtensionWebUI::HandleChromeURLOverrideReverse);
709
710 // about:
711 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
712 BrowserURLHandler::null_handler());
713 // chrome: & friends.
714 handler->AddHandlerPair(&HandleWebUI,
715 BrowserURLHandler::null_handler());
716}
717
718void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37719 Profile* profile = Profile::FromBrowserContext(
720 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25721 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
722 BrowsingDataRemover::EVERYTHING,
723 base::Time());
724 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
725 // BrowsingDataRemover takes care of deleting itself when done.
726}
727
728void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37729 Profile* profile = Profile::FromBrowserContext(
730 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25731 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
732 BrowsingDataRemover::EVERYTHING,
733 base::Time());
734 int remove_mask = BrowsingDataRemover::REMOVE_COOKIES;
735 remover->Remove(remove_mask);
736 // BrowsingDataRemover takes care of deleting itself when done.
737}
738
[email protected]e1d16eb92011-08-18 23:19:32739FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
740 return download_util::GetDefaultDownloadDirectory();
741}
742
[email protected]b68bf3892011-08-23 15:03:58743net::URLRequestContextGetter*
744ChromeContentBrowserClient::GetDefaultRequestContextDeprecatedCrBug64339() {
745 return Profile::Deprecated::GetDefaultRequestContext();
746}
747
[email protected]b80f68432011-05-02 17:22:30748#if defined(OS_LINUX)
749int ChromeContentBrowserClient::GetCrashSignalFD(
750 const std::string& process_type) {
751 if (process_type == switches::kRendererProcess)
752 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
753
[email protected]9dbfff12011-07-01 19:37:07754 if (process_type == switches::kExtensionProcess) {
755 ExtensionCrashHandlerHostLinux* crash_handler =
756 ExtensionCrashHandlerHostLinux::GetInstance();
757 return crash_handler->GetDeathSignalSocket();
758 }
759
[email protected]b80f68432011-05-02 17:22:30760 if (process_type == switches::kPluginProcess)
761 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
762
763 if (process_type == switches::kPpapiPluginProcess)
764 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
765
766 if (process_type == switches::kGpuProcess)
767 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
768
769 return -1;
770}
[email protected]9dbfff12011-07-01 19:37:07771#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30772
[email protected]4a65826d2011-08-25 16:04:01773#if defined(OS_WIN)
774const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
775 return chrome::kBrowserResourcesDll;
776}
777#endif
778
[email protected]37a72af2011-06-13 05:42:01779#if defined(USE_NSS)
780crypto::CryptoModuleBlockingPasswordDelegate*
781 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
782 const GURL& url) {
783 return browser::NewCryptoModuleBlockingDialogDelegate(
784 browser::kCryptoModulePasswordKeygen, url.host());
785}
786#endif
787
[email protected]d977f9c2011-03-14 16:10:26788} // namespace chrome