blob: 3e6639c9ddf814a4d642a297f7d01739f6e59ca4 [file] [log] [blame]
[email protected]d977f9c2011-03-14 16:10:261// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]b80f68432011-05-02 17:22:307#include "base/command_line.h"
8#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:259#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3010#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2311#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1212#include "chrome/browser/character_encoding.h"
[email protected]97e6c4c2011-05-18 16:08:5113#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4114#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]5327dfb2011-05-03 17:50:3615#include "chrome/browser/chrome_worker_message_filter.h"
[email protected]a2176792011-05-08 19:30:4916#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3217#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]e1d16eb92011-08-18 23:19:3218#include "chrome/browser/download/download_util.h"
[email protected]941623e2011-06-07 23:06:0419#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1020#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2621#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2522#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]32538d92011-08-25 00:09:2323#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1224#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2825#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0426#include "chrome/browser/notifications/desktop_notification_service.h"
27#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4228#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1229#include "chrome/browser/prefs/pref_service.h"
[email protected]f9034cf2011-07-21 12:43:4130#include "chrome/browser/prerender/prerender_manager.h"
31#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1432#include "chrome/browser/printing/printing_message_filter.h"
33#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3234#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1435#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3336#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]d4cff272011-05-02 15:46:0137#include "chrome/browser/renderer_host/text_input_client_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1438#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0439#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4640#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4541#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0342#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3643#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4544#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
45#include "chrome/browser/tab_contents/tab_util.h"
46#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5647#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3048#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0149#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3050#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0451#include "chrome/common/extensions/extension.h"
[email protected]f1933792011-06-14 00:49:3452#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1253#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3854#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0955#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2556#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0957#include "content/browser/browsing_instance.h"
[email protected]97e6c4c2011-05-18 16:08:5158#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1459#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2660#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4961#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0962#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4163#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4564#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1265#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3266#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3667#include "content/browser/worker_host/worker_process_host.h"
[email protected]941623e2011-06-07 23:06:0468#include "content/common/desktop_notification_messages.h"
[email protected]29b25d092011-06-29 20:57:3469#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0170#include "net/base/cookie_monster.h"
71#include "net/base/cookie_options.h"
[email protected]ac55e292011-06-24 05:16:0872#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2673
[email protected]b80f68432011-05-02 17:22:3074#if defined(OS_LINUX)
75#include "base/linux_util.h"
[email protected]f967b722011-09-07 00:58:0476#include "chrome/browser/browser_main_gtk.h"
[email protected]b80f68432011-05-02 17:22:3077#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]f967b722011-09-07 00:58:0488#include "chrome/browser/browser_main_mac.h"
89#endif
90
91#if defined(OS_WIN)
92#include "chrome/browser/browser_main_win.h"
93#elif defined(OS_CHROMEOS)
94#include "chrome/browser/chromeos/browser_main_chromeos.h"
[email protected]74313b42011-08-24 16:51:3295#endif
96
[email protected]37a72af2011-06-13 05:42:0197#if defined(USE_NSS)
98#include "chrome/browser/ui/crypto_module_password_dialog.h"
99#endif
100
[email protected]c5dbef02011-05-13 05:06:09101namespace {
102
[email protected]b8148ac2011-07-13 22:03:25103// Handles rewriting Web UI URLs.
[email protected]3d7474ff2011-07-27 17:47:37104static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
105 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25106 return false;
107
108 // Special case the new tab page. In older versions of Chrome, the new tab
109 // page was hosted at chrome-internal:<blah>. This might be in people's saved
110 // sessions or bookmarks, so we say any URL with that scheme triggers the new
111 // tab page.
112 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
113 // Rewrite it with the proper new tab URL.
114 *url = GURL(chrome::kChromeUINewTabURL);
115 }
116
117 return true;
118}
119
[email protected]9dbfff12011-07-01 19:37:07120} // namespace
[email protected]c5dbef02011-05-13 05:06:09121
[email protected]d977f9c2011-03-14 16:10:26122namespace chrome {
123
[email protected]f967b722011-09-07 00:58:04124content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
125 const MainFunctionParams& parameters) {
126#if defined(OS_WIN)
127 return new BrowserMainPartsWin(parameters);
128#elif defined(OS_MACOSX)
129 return new BrowserMainPartsMac(parameters);
130#elif defined(OS_CHROMEOS)
131 return new BrowserMainPartsChromeos(parameters);
132#elif defined(OS_LINUX)
133 return new BrowserMainPartsGtk(parameters);
134#else
135 return NULL;
136#endif
137}
138
[email protected]74313b42011-08-24 16:51:32139TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
140 TabContents* tab_contents) {
[email protected]bb6dcbb2011-08-24 17:05:20141#if defined(TOUCH_UI)
142 return new TabContentsViewTouch(tab_contents);
143#elif defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32144 return new TabContentsViewViews(tab_contents);
145#elif defined(OS_LINUX)
146 return new TabContentsViewGtk(tab_contents);
147#elif defined(OS_MACOSX)
148 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32149#else
150#error Need to create your platform TabContentsView here.
151#endif
152}
153
[email protected]f364d1392011-04-08 21:03:10154void ChromeContentBrowserClient::RenderViewHostCreated(
155 RenderViewHost* render_view_host) {
[email protected]b503914162011-08-19 16:02:50156 new ChromeRenderViewHostObserver(render_view_host);
[email protected]f364d1392011-04-08 21:03:10157 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26158}
159
[email protected]05fcf982011-04-19 00:44:14160void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
161 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02162 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37163 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14164 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02165 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14166 host->channel()->AddFilter(new PrintingMessageFilter());
167 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02168 new SearchProviderInstallStateMessageFilter(id, profile));
169 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]d4cff272011-05-02 15:46:01170#if defined(OS_MACOSX)
171 host->channel()->AddFilter(new TextInputClientMessageFilter(host->id()));
172#endif
[email protected]3e69bc82011-05-26 23:22:38173
[email protected]2ccf45c2011-08-19 23:35:50174 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
175 profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14176}
177
[email protected]97e6c4c2011-05-18 16:08:51178void ChromeContentBrowserClient::PluginProcessHostCreated(
179 PluginProcessHost* host) {
180 host->AddFilter(new ChromePluginMessageFilter(host));
181}
182
[email protected]5327dfb2011-05-03 17:50:36183void ChromeContentBrowserClient::WorkerProcessHostCreated(
184 WorkerProcessHost* host) {
185 host->AddFilter(new ChromeWorkerMessageFilter(host));
186}
187
[email protected]1fd1a502011-03-30 16:55:56188content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
189 return ChromeWebUIFactory::GetInstance();
190}
191
[email protected]3d7474ff2011-07-27 17:47:37192GURL ChromeContentBrowserClient::GetEffectiveURL(
193 content::BrowserContext* browser_context, const GURL& url) {
194 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08195 // Get the effective URL for the given actual URL. If the URL is part of an
196 // installed app, the effective URL is an extension URL with the ID of that
197 // extension as the host. This has the effect of grouping apps together in
198 // a common SiteInstance.
199 if (!profile || !profile->GetExtensionService())
200 return url;
201
202 const Extension* extension =
203 profile->GetExtensionService()->GetExtensionByWebExtent(url);
204 if (!extension)
205 return url;
206
207 // If the URL is part of an extension's web extent, convert it to an
208 // extension URL.
209 return extension->GetResourceURL(url.path());
210}
211
[email protected]056ad2a2011-07-12 02:13:55212bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37213 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55214 // Non-extension URLs should generally use process-per-site-instance.
215 // Because we expect to use the effective URL, hosted apps URLs should have
216 // an extension scheme by now.
217 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
218 return false;
219
[email protected]3d7474ff2011-07-27 17:47:37220 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55221 if (!profile || !profile->GetExtensionService())
222 return false;
223
224 const Extension* extension =
225 profile->GetExtensionService()->GetExtensionByURL(effective_url);
226 if (!extension)
227 return false;
228
229 // If the URL is part of a hosted app that does not have the background
230 // permission, we want to give each instance its own process to improve
231 // responsiveness.
232 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
233 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
234 return false;
235
236 // Hosted apps that have the background permission must use process per site,
237 // since all instances can make synchronous calls to the background window.
238 // Other extensions should use process per site as well.
239 return true;
240}
241
[email protected]0f012df82011-05-19 14:15:29242bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03243 return url == GURL(chrome::kChromeUICrashURL) ||
244 url == GURL(chrome::kChromeUIKillURL) ||
245 url == GURL(chrome::kChromeUIHangURL) ||
246 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29247}
248
[email protected]763ec4ca2011-04-29 15:48:12249std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
250 const std::string& alias_name) {
251 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
252}
253
[email protected]b80f68432011-05-02 17:22:30254void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
255 CommandLine* command_line, int child_process_id) {
256#if defined(USE_LINUX_BREAKPAD)
257 if (IsCrashReporterEnabled()) {
258 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
259 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
260 }
261#elif defined(OS_MACOSX)
262 if (IsCrashReporterEnabled()) {
263 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
264 child_process_logging::GetClientId());
265 }
266#endif // OS_MACOSX
267
[email protected]f1933792011-06-14 00:49:34268 if (logging::DialogsAreSuppressed())
269 command_line->AppendSwitch(switches::kNoErrorDialogs);
270
[email protected]b80f68432011-05-02 17:22:30271 std::string process_type =
272 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17273 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30274 if (process_type == switches::kExtensionProcess ||
275 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30276 FilePath user_data_dir =
277 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
278 if (!user_data_dir.empty())
279 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
280#if defined(OS_CHROMEOS)
281 const std::string& login_profile =
282 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
283 if (!login_profile.empty())
284 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
285#endif
286
287 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
288
[email protected]3d7474ff2011-07-27 17:47:37289 Profile* profile = Profile::FromBrowserContext(process->browser_context());
290 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30291 // Currently this pref is only registered if applied via a policy.
292 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
293 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
294 // Turn this policy into a command line switch.
295 command_line->AppendSwitch(switches::kDisable3DAPIs);
296 }
297
298 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46299 // in the Profile preferences or the browser process.
300 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
301 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30302 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46303 }
[email protected]4287a3d2011-06-13 23:56:51304
305 static const char* const kSwitchNames[] = {
306 switches::kAllowHTTPBackgroundPage,
307 switches::kAllowScriptingGallery,
308 switches::kAppsCheckoutURL,
309 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31310 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51311 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51312 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51313 switches::kDomAutomationController,
314 switches::kDumpHistogramsOnExit,
315 switches::kEnableClickToPlay,
316 switches::kEnableCrxlessWebApps,
317 switches::kEnableExperimentalExtensionApis,
318 switches::kEnableInBrowserThumbnailing,
[email protected]d0cf438c2011-08-18 03:08:52319 switches::kEnableInlineWebstoreInstall,
[email protected]4287a3d2011-06-13 23:56:51320 switches::kEnableIPCFuzzing,
321 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24322 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51323 switches::kEnableResourceContentSettings,
324 switches::kEnableSearchProviderApiV2,
325 switches::kEnableWatchdog,
326 switches::kExperimentalSpellcheckerFeatures,
327 switches::kMemoryProfiling,
328 switches::kMessageLoopHistogrammer,
329 switches::kPpapiFlashArgs,
330 switches::kPpapiFlashInProcess,
331 switches::kPpapiFlashPath,
332 switches::kPpapiFlashVersion,
333 switches::kProfilingAtStart,
334 switches::kProfilingFile,
335 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51336 switches::kSilentDumpOnDCHECK,
337 };
338
339 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
340 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17341 } else if (process_type == switches::kUtilityProcess) {
342 if (browser_command_line.HasSwitch(
343 switches::kEnableExperimentalExtensionApis)) {
344 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
345 }
[email protected]4287a3d2011-06-13 23:56:51346 } else if (process_type == switches::kPluginProcess) {
347 static const char* const kSwitchNames[] = {
348 #if defined(OS_CHROMEOS)
349 switches::kLoginProfile,
350 #endif
351 switches::kMemoryProfiling,
352 switches::kSilentDumpOnDCHECK,
353 switches::kUserDataDir,
354 };
355
356 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
357 arraysize(kSwitchNames));
358 } else if (process_type == switches::kZygoteProcess) {
359 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51360 switches::kUserDataDir, // Make logs go to the right file.
361 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
362 switches::kPpapiFlashInProcess,
363 switches::kPpapiFlashPath,
364 switches::kPpapiFlashVersion,
365 };
366
367 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
368 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30369 }
370}
371
372std::string ChromeContentBrowserClient::GetApplicationLocale() {
373 return g_browser_process->GetApplicationLocale();
374}
375
[email protected]b5cca982011-05-26 04:42:08376std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37377 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
378 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08379}
380
[email protected]ac55e292011-06-24 05:16:08381SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
382 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
383 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
384}
385
[email protected]a2176792011-05-08 19:30:49386bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09387 const GURL& manifest_url,
388 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
390 ProfileIOData* io_data =
391 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09392 // FIXME(jochen): get the correct top-level origin.
[email protected]efa55212011-05-13 16:19:38393 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]5b52ad42011-05-26 14:26:09394 GetCookieContentSetting(manifest_url, manifest_url, true);
[email protected]a2176792011-05-08 19:30:49395 DCHECK(setting != CONTENT_SETTING_DEFAULT);
396 return setting != CONTENT_SETTING_BLOCK;
397}
398
[email protected]ed24fad2011-05-10 22:44:01399bool ChromeContentBrowserClient::AllowGetCookie(
400 const GURL& url,
401 const GURL& first_party,
402 const net::CookieList& cookie_list,
403 const content::ResourceContext& context,
404 int render_process_id,
405 int render_view_id) {
406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32407 ProfileIOData* io_data =
408 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09409 ContentSetting setting = io_data->GetHostContentSettingsMap()->
410 GetCookieContentSetting(url, first_party, false);
411 bool allow = setting == CONTENT_SETTING_ALLOW ||
412 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01413
[email protected]8093a542011-05-13 07:29:32414 BrowserThread::PostTask(
415 BrowserThread::UI, FROM_HERE,
416 NewRunnableFunction(
417 &TabSpecificContentSettings::CookiesRead,
418 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01419 return allow;
420}
421
422bool ChromeContentBrowserClient::AllowSetCookie(
423 const GURL& url,
424 const GURL& first_party,
425 const std::string& cookie_line,
426 const content::ResourceContext& context,
427 int render_process_id,
428 int render_view_id,
429 net::CookieOptions* options) {
430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32431 ProfileIOData* io_data =
432 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09433 ContentSetting setting = io_data->GetHostContentSettingsMap()->
434 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01435
[email protected]5b52ad42011-05-26 14:26:09436 if (setting == CONTENT_SETTING_SESSION_ONLY)
437 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01438
[email protected]5b52ad42011-05-26 14:26:09439 bool allow = setting == CONTENT_SETTING_ALLOW ||
440 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01441
[email protected]8093a542011-05-13 07:29:32442 BrowserThread::PostTask(
443 BrowserThread::UI, FROM_HERE,
444 NewRunnableFunction(
445 &TabSpecificContentSettings::CookieChanged,
446 render_process_id, render_view_id, url, cookie_line, *options,
447 !allow));
[email protected]ed24fad2011-05-10 22:44:01448 return allow;
449}
450
[email protected]d5a19162011-06-30 18:51:54451bool ChromeContentBrowserClient::AllowSaveLocalState(
452 const content::ResourceContext& context) {
453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
454 ProfileIOData* io_data =
455 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
456 return !io_data->clear_local_state_on_exit()->GetValue();
457}
458
[email protected]6133f922011-07-01 21:34:34459net::URLRequestContext*
460ChromeContentBrowserClient::OverrideRequestContextForURL(
461 const GURL& url, const content::ResourceContext& context) {
462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
463 if (url.SchemeIs(chrome::kExtensionScheme)) {
464 ProfileIOData* io_data =
465 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
466 return io_data->extensions_request_context();
467 }
468
469 return NULL;
470}
471
[email protected]317f96c92011-05-31 06:53:41472QuotaPermissionContext*
473ChromeContentBrowserClient::CreateQuotaPermissionContext() {
474 return new ChromeQuotaPermissionContext();
475}
476
[email protected]a0ce3282011-08-19 20:49:52477void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42478 // On Mac, this call needs to be done on the UI thread. On other platforms,
479 // do it on the FILE thread so we don't slow down UI.
480#if defined(OS_MACOSX)
481 platform_util::OpenItem(path);
482#else
483 BrowserThread::PostTask(
484 BrowserThread::FILE, FROM_HERE,
485 NewRunnableFunction(&platform_util::OpenItem, path));
486#endif
487}
488
[email protected]a0ce3282011-08-19 20:49:52489void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
490#if defined(OS_MACOSX)
491 // Mac needs to run this operation on the UI thread.
492 platform_util::ShowItemInFolder(path);
493#else
494 BrowserThread::PostTask(
495 BrowserThread::FILE, FROM_HERE,
496 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
497#endif
498}
499
[email protected]848dd042011-06-04 18:24:03500void ChromeContentBrowserClient::AllowCertificateError(
501 SSLCertErrorHandler* handler,
502 bool overridable,
503 Callback2<SSLCertErrorHandler*, bool>::Type* callback) {
[email protected]f9034cf2011-07-21 12:43:41504 // If the tab is being prerendered, cancel the prerender and the request.
505 TabContents* tab = tab_util::GetTabContentsByID(
506 handler->render_process_host_id(),
507 handler->tab_contents_id());
508 if (!tab) {
509 NOTREACHED();
510 return;
511 }
512 prerender::PrerenderManager* prerender_manager =
[email protected]cafe4ad2011-07-28 18:34:56513 Profile::FromBrowserContext(tab->browser_context())->
514 GetPrerenderManager();
[email protected]f9034cf2011-07-21 12:43:41515 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
516 if (prerender_manager->prerender_tracker()->TryCancel(
517 handler->render_process_host_id(),
518 handler->tab_contents_id(),
519 prerender::FINAL_STATUS_SSL_ERROR)) {
520 handler->CancelRequest();
521 return;
522 }
523 }
524
525 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03526 SSLBlockingPage* blocking_page = new SSLBlockingPage(
527 handler, overridable, callback);
528 blocking_page->Show();
529}
530
[email protected]c99c442e2011-08-24 11:37:30531void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45532 int render_process_id,
533 int render_view_id,
534 SSLClientAuthHandler* handler) {
535 TabContents* tab = tab_util::GetTabContentsByID(
536 render_process_id, render_view_id);
537 if (!tab) {
538 NOTREACHED();
539 return;
540 }
541
542 TabContentsWrapper* wrapper =
543 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30544 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45545}
546
547void ChromeContentBrowserClient::AddNewCertificate(
548 net::URLRequest* request,
549 net::X509Certificate* cert,
550 int render_process_id,
551 int render_view_id) {
552 // The handler will run the UI and delete itself when it's finished.
553 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
554}
555
[email protected]941623e2011-06-07 23:06:04556void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
557 const GURL& source_origin,
558 int callback_context,
559 int render_process_id,
560 int render_view_id) {
561 RenderViewHost* rvh = RenderViewHost::FromID(
562 render_process_id, render_view_id);
563 if (!rvh) {
564 NOTREACHED();
565 return;
566 }
567
568 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37569 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04570 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37571 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04572 service->RequestPermission(
573 source_origin, render_process_id, render_view_id, callback_context,
574 tab_util::GetTabContentsByID(render_process_id, render_view_id));
575}
576
577WebKit::WebNotificationPresenter::Permission
578 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
579 const GURL& source_url,
580 const content::ResourceContext& context) {
581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
582 ProfileIOData* io_data =
583 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
584
585 const Extension* extension =
586 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
587 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52588 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04589 return WebKit::WebNotificationPresenter::PermissionAllowed;
590 }
591
592 // Fall back to the regular notification preferences, which works on an
593 // origin basis.
594 return io_data->GetNotificationService() ?
595 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
596 WebKit::WebNotificationPresenter::PermissionNotAllowed;
597}
598
599void ChromeContentBrowserClient::ShowDesktopNotification(
600 const DesktopNotificationHostMsg_Show_Params& params,
601 int render_process_id,
602 int render_view_id,
603 bool worker) {
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->ShowDesktopNotification(
616 params, render_process_id, render_view_id,
617 worker ? DesktopNotificationService::WorkerNotification :
618 DesktopNotificationService::PageNotification);
619}
620
621void ChromeContentBrowserClient::CancelDesktopNotification(
622 int render_process_id,
623 int render_view_id,
624 int notification_id) {
625 RenderViewHost* rvh = RenderViewHost::FromID(
626 render_process_id, render_view_id);
627 if (!rvh) {
628 NOTREACHED();
629 return;
630 }
631
632 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37633 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04634 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37635 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04636 service->CancelDesktopNotification(
637 render_process_id, render_view_id, notification_id);
638}
639
[email protected]9f3fba52011-06-08 20:37:19640bool ChromeContentBrowserClient::CanCreateWindow(
641 const GURL& source_url,
642 WindowContainerType container_type,
643 const content::ResourceContext& context) {
644 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
645 // If the opener is trying to create a background window but doesn't have
646 // the appropriate permission, fail the attempt.
647 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
648 ProfileIOData* io_data =
649 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
650 const Extension* extension =
651 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
652 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52653 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19654 }
655 return true;
656}
657
658std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
659 const GURL& url, const content::ResourceContext& context) {
660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
661 // Check if it's an extension-created worker, in which case we want to use
662 // the name of the extension.
663 ProfileIOData* io_data =
664 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
665 const Extension* extension =
666 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
667 return extension ? extension->name() : std::string();
668}
669
[email protected]3cb054e62011-06-13 05:21:17670ResourceDispatcherHost*
671 ChromeContentBrowserClient::GetResourceDispatcherHost() {
672 return g_browser_process->resource_dispatcher_host();
673}
674
675ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
676 return g_browser_process->clipboard();
677}
678
[email protected]8f6a3b852011-07-19 16:48:56679MHTMLGenerationManager*
680 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
681 return g_browser_process->mhtml_generation_manager();
682}
683
[email protected]dce502762011-07-20 08:53:49684DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
685 return g_browser_process->devtools_manager();
686}
687
[email protected]ae6e9912011-07-27 01:18:28688net::NetLog* ChromeContentBrowserClient::GetNetLog() {
689 return g_browser_process->net_log();
690}
691
[email protected]3bc0b562011-08-24 23:51:04692speech_input::SpeechInputManager*
693 ChromeContentBrowserClient::GetSpeechInputManager() {
694 return speech_input::ChromeSpeechInputManager::GetInstance();
695}
696
[email protected]32538d92011-08-25 00:09:23697AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
698 return new ChromeAccessTokenStore();
699}
700
[email protected]dbae6b02011-06-29 23:51:41701bool ChromeContentBrowserClient::IsFastShutdownPossible() {
702 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
703 return !browser_command_line.HasSwitch(switches::kChromeFrame);
704}
705
[email protected]3d7474ff2011-07-27 17:47:37706WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
707 content::BrowserContext* browser_context, bool is_web_ui) {
708 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
709 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36710}
711
712void ChromeContentBrowserClient::UpdateInspectorSetting(
713 RenderViewHost* rvh, const std::string& key, const std::string& value) {
714 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37715 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36716}
717
718void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
719 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37720 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36721}
722
[email protected]b8148ac2011-07-13 22:03:25723void ChromeContentBrowserClient::BrowserURLHandlerCreated(
724 BrowserURLHandler* handler) {
725 // Add the default URL handlers.
726 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
727 BrowserURLHandler::null_handler());
728 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
729 &ExtensionWebUI::HandleChromeURLOverrideReverse);
730
731 // about:
732 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
733 BrowserURLHandler::null_handler());
734 // chrome: & friends.
735 handler->AddHandlerPair(&HandleWebUI,
736 BrowserURLHandler::null_handler());
737}
738
739void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37740 Profile* profile = Profile::FromBrowserContext(
741 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25742 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
743 BrowsingDataRemover::EVERYTHING,
744 base::Time());
745 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
746 // BrowsingDataRemover takes care of deleting itself when done.
747}
748
749void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37750 Profile* profile = Profile::FromBrowserContext(
751 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25752 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
753 BrowsingDataRemover::EVERYTHING,
754 base::Time());
[email protected]dceaa912011-09-06 17:17:23755 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:25756 remover->Remove(remove_mask);
757 // BrowsingDataRemover takes care of deleting itself when done.
758}
759
[email protected]e1d16eb92011-08-18 23:19:32760FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
761 return download_util::GetDefaultDownloadDirectory();
762}
763
[email protected]b68bf3892011-08-23 15:03:58764net::URLRequestContextGetter*
765ChromeContentBrowserClient::GetDefaultRequestContextDeprecatedCrBug64339() {
766 return Profile::Deprecated::GetDefaultRequestContext();
767}
768
[email protected]c8571ea2011-08-26 17:22:17769net::URLRequestContextGetter*
770ChromeContentBrowserClient::GetSystemRequestContext() {
771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
772 return g_browser_process->system_request_context();
773}
774
[email protected]b80f68432011-05-02 17:22:30775#if defined(OS_LINUX)
776int ChromeContentBrowserClient::GetCrashSignalFD(
777 const std::string& process_type) {
778 if (process_type == switches::kRendererProcess)
779 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
780
[email protected]9dbfff12011-07-01 19:37:07781 if (process_type == switches::kExtensionProcess) {
782 ExtensionCrashHandlerHostLinux* crash_handler =
783 ExtensionCrashHandlerHostLinux::GetInstance();
784 return crash_handler->GetDeathSignalSocket();
785 }
786
[email protected]b80f68432011-05-02 17:22:30787 if (process_type == switches::kPluginProcess)
788 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
789
790 if (process_type == switches::kPpapiPluginProcess)
791 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
792
793 if (process_type == switches::kGpuProcess)
794 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
795
796 return -1;
797}
[email protected]9dbfff12011-07-01 19:37:07798#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30799
[email protected]4a65826d2011-08-25 16:04:01800#if defined(OS_WIN)
801const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
802 return chrome::kBrowserResourcesDll;
803}
804#endif
805
[email protected]37a72af2011-06-13 05:42:01806#if defined(USE_NSS)
807crypto::CryptoModuleBlockingPasswordDelegate*
808 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
809 const GURL& url) {
810 return browser::NewCryptoModuleBlockingDialogDelegate(
811 browser::kCryptoModulePasswordKeygen, url.host());
812}
813#endif
814
[email protected]d977f9c2011-03-14 16:10:26815} // namespace chrome