blob: 4709e327f89d2f5602a9fcc1afc94f195fef5454 [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]6f08af82011-09-15 01:19:0313#include "chrome/browser/chrome_benchmarking_message_filter.h"
[email protected]97e6c4c2011-05-18 16:08:5114#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4115#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]5327dfb2011-05-03 17:50:3616#include "chrome/browser/chrome_worker_message_filter.h"
[email protected]a2176792011-05-08 19:30:4917#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3218#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]e1d16eb92011-08-18 23:19:3219#include "chrome/browser/download/download_util.h"
[email protected]941623e2011-06-07 23:06:0420#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1021#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2622#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2523#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]32538d92011-08-25 00:09:2324#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1225#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2826#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0427#include "chrome/browser/notifications/desktop_notification_service.h"
28#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4229#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1230#include "chrome/browser/prefs/pref_service.h"
[email protected]f9034cf2011-07-21 12:43:4131#include "chrome/browser/prerender/prerender_manager.h"
32#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1433#include "chrome/browser/printing/printing_message_filter.h"
34#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3235#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1436#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3337#include "chrome/browser/renderer_host/chrome_render_view_host_observer.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]199fc7a2011-09-28 22:45:3874#if defined(USE_AURA)
75#include "chrome/browser/chrome_browser_main_aura.h"
76#elif defined(OS_WIN)
77#include "chrome/browser/chrome_browser_main_win.h"
78#elif defined(OS_MACOSX)
79#include "chrome/browser/chrome_browser_main_mac.h"
80#elif defined(OS_CHROMEOS)
81#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
82#elif defined(OS_LINUX)
83#include "chrome/browser/chrome_browser_main_gtk.h"
84#endif
85
[email protected]b80f68432011-05-02 17:22:3086#if defined(OS_LINUX)
87#include "base/linux_util.h"
88#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:4389#endif
[email protected]b80f68432011-05-02 17:22:3090
[email protected]080f34f2011-09-20 05:39:2691#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:3292#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
93#elif defined(OS_LINUX)
94#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
95#elif defined(OS_MACOSX)
96#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:3297#endif
98
[email protected]37a72af2011-06-13 05:42:0199#if defined(USE_NSS)
100#include "chrome/browser/ui/crypto_module_password_dialog.h"
101#endif
102
[email protected]c5dbef02011-05-13 05:06:09103namespace {
104
[email protected]b8148ac2011-07-13 22:03:25105// Handles rewriting Web UI URLs.
[email protected]3d7474ff2011-07-27 17:47:37106static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
107 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25108 return false;
109
110 // Special case the new tab page. In older versions of Chrome, the new tab
111 // page was hosted at chrome-internal:<blah>. This might be in people's saved
112 // sessions or bookmarks, so we say any URL with that scheme triggers the new
113 // tab page.
114 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
115 // Rewrite it with the proper new tab URL.
116 *url = GURL(chrome::kChromeUINewTabURL);
117 }
118
119 return true;
120}
121
[email protected]9dbfff12011-07-01 19:37:07122} // namespace
[email protected]c5dbef02011-05-13 05:06:09123
[email protected]d977f9c2011-03-14 16:10:26124namespace chrome {
125
[email protected]f967b722011-09-07 00:58:04126content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
127 const MainFunctionParams& parameters) {
[email protected]199fc7a2011-09-28 22:45:38128#if defined(USE_AURA)
129 return new ChromeBrowserMainPartsAura(parameters);
130#elif defined(OS_WIN)
[email protected]e6b5bc22011-09-08 22:01:56131 return new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04132#elif defined(OS_MACOSX)
[email protected]46c83b62011-09-08 22:09:04133 return new ChromeBrowserMainPartsMac(parameters);
[email protected]f967b722011-09-07 00:58:04134#elif defined(OS_CHROMEOS)
[email protected]46c83b62011-09-08 22:09:04135 return new ChromeBrowserMainPartsChromeos(parameters);
[email protected]f967b722011-09-07 00:58:04136#elif defined(OS_LINUX)
[email protected]e6b5bc22011-09-08 22:01:56137 return new ChromeBrowserMainPartsGtk(parameters);
[email protected]f967b722011-09-07 00:58:04138#else
139 return NULL;
140#endif
141}
142
[email protected]74313b42011-08-24 16:51:32143TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
144 TabContents* tab_contents) {
[email protected]080f34f2011-09-20 05:39:26145#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32146 return new TabContentsViewViews(tab_contents);
147#elif defined(OS_LINUX)
148 return new TabContentsViewGtk(tab_contents);
149#elif defined(OS_MACOSX)
150 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32151#else
152#error Need to create your platform TabContentsView here.
153#endif
154}
155
[email protected]f364d1392011-04-08 21:03:10156void ChromeContentBrowserClient::RenderViewHostCreated(
157 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46158
159 SiteInstance* site_instance = render_view_host->site_instance();
160 Profile* profile = Profile::FromBrowserContext(
161 site_instance->browsing_instance()->browser_context());
162
163 new ChromeRenderViewHostObserver(render_view_host,
164 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10165 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26166}
167
[email protected]05fcf982011-04-19 00:44:14168void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
169 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02170 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37171 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14172 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02173 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14174 host->channel()->AddFilter(new PrintingMessageFilter());
175 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02176 new SearchProviderInstallStateMessageFilter(id, profile));
177 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]6f08af82011-09-15 01:19:03178 host->channel()->AddFilter(new ChromeBenchmarkingMessageFilter(
179 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38180
[email protected]2ccf45c2011-08-19 23:35:50181 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
182 profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14183}
184
[email protected]97e6c4c2011-05-18 16:08:51185void ChromeContentBrowserClient::PluginProcessHostCreated(
186 PluginProcessHost* host) {
187 host->AddFilter(new ChromePluginMessageFilter(host));
188}
189
[email protected]5327dfb2011-05-03 17:50:36190void ChromeContentBrowserClient::WorkerProcessHostCreated(
191 WorkerProcessHost* host) {
192 host->AddFilter(new ChromeWorkerMessageFilter(host));
193}
194
[email protected]1fd1a502011-03-30 16:55:56195content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
196 return ChromeWebUIFactory::GetInstance();
197}
198
[email protected]3d7474ff2011-07-27 17:47:37199GURL ChromeContentBrowserClient::GetEffectiveURL(
200 content::BrowserContext* browser_context, const GURL& url) {
201 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08202 // Get the effective URL for the given actual URL. If the URL is part of an
203 // installed app, the effective URL is an extension URL with the ID of that
204 // extension as the host. This has the effect of grouping apps together in
205 // a common SiteInstance.
206 if (!profile || !profile->GetExtensionService())
207 return url;
208
209 const Extension* extension =
210 profile->GetExtensionService()->GetExtensionByWebExtent(url);
211 if (!extension)
212 return url;
213
214 // If the URL is part of an extension's web extent, convert it to an
215 // extension URL.
216 return extension->GetResourceURL(url.path());
217}
218
[email protected]056ad2a2011-07-12 02:13:55219bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37220 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55221 // Non-extension URLs should generally use process-per-site-instance.
222 // Because we expect to use the effective URL, hosted apps URLs should have
223 // an extension scheme by now.
224 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
225 return false;
226
[email protected]3d7474ff2011-07-27 17:47:37227 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55228 if (!profile || !profile->GetExtensionService())
229 return false;
230
231 const Extension* extension =
232 profile->GetExtensionService()->GetExtensionByURL(effective_url);
233 if (!extension)
234 return false;
235
236 // If the URL is part of a hosted app that does not have the background
237 // permission, we want to give each instance its own process to improve
238 // responsiveness.
239 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
240 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
241 return false;
242
243 // Hosted apps that have the background permission must use process per site,
244 // since all instances can make synchronous calls to the background window.
245 // Other extensions should use process per site as well.
246 return true;
247}
248
[email protected]0f012df82011-05-19 14:15:29249bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03250 return url == GURL(chrome::kChromeUICrashURL) ||
251 url == GURL(chrome::kChromeUIKillURL) ||
252 url == GURL(chrome::kChromeUIHangURL) ||
253 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29254}
255
[email protected]2a5221b2011-09-27 23:07:31256bool ChromeContentBrowserClient::IsSuitableHost(
257 RenderProcessHost* process_host,
258 const GURL& site_url) {
259 Profile* profile =
260 Profile::FromBrowserContext(process_host->browser_context());
261 ExtensionProcessManager* extension_process_manager =
262 profile->GetExtensionProcessManager();
263
264 // Maybe NULL during tests.
265 if (!extension_process_manager)
266 return true;
267
268 bool is_extension_host =
269 process_host->is_extension_process() ||
[email protected]8add5412011-10-01 21:02:14270 extension_process_manager->AreBindingsEnabledForProcess(
271 process_host->id());
[email protected]2a5221b2011-09-27 23:07:31272 return site_url.SchemeIs(chrome::kExtensionScheme) == is_extension_host;
273}
274
[email protected]763ec4ca2011-04-29 15:48:12275std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
276 const std::string& alias_name) {
277 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
278}
279
[email protected]b80f68432011-05-02 17:22:30280void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
281 CommandLine* command_line, int child_process_id) {
282#if defined(USE_LINUX_BREAKPAD)
283 if (IsCrashReporterEnabled()) {
284 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
285 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
286 }
287#elif defined(OS_MACOSX)
288 if (IsCrashReporterEnabled()) {
289 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
290 child_process_logging::GetClientId());
291 }
292#endif // OS_MACOSX
293
[email protected]f1933792011-06-14 00:49:34294 if (logging::DialogsAreSuppressed())
295 command_line->AppendSwitch(switches::kNoErrorDialogs);
296
[email protected]b80f68432011-05-02 17:22:30297 std::string process_type =
298 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17299 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30300 if (process_type == switches::kExtensionProcess ||
301 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30302 FilePath user_data_dir =
303 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
304 if (!user_data_dir.empty())
305 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
306#if defined(OS_CHROMEOS)
307 const std::string& login_profile =
308 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
309 if (!login_profile.empty())
310 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
311#endif
312
313 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
314
[email protected]3d7474ff2011-07-27 17:47:37315 Profile* profile = Profile::FromBrowserContext(process->browser_context());
316 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30317 // Currently this pref is only registered if applied via a policy.
318 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
319 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
320 // Turn this policy into a command line switch.
321 command_line->AppendSwitch(switches::kDisable3DAPIs);
322 }
323
324 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46325 // in the Profile preferences or the browser process.
326 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
327 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30328 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46329 }
[email protected]4287a3d2011-06-13 23:56:51330
331 static const char* const kSwitchNames[] = {
332 switches::kAllowHTTPBackgroundPage,
333 switches::kAllowScriptingGallery,
334 switches::kAppsCheckoutURL,
335 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31336 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51337 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51338 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51339 switches::kDomAutomationController,
340 switches::kDumpHistogramsOnExit,
341 switches::kEnableClickToPlay,
342 switches::kEnableCrxlessWebApps,
343 switches::kEnableExperimentalExtensionApis,
344 switches::kEnableInBrowserThumbnailing,
345 switches::kEnableIPCFuzzing,
346 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24347 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51348 switches::kEnableResourceContentSettings,
349 switches::kEnableSearchProviderApiV2,
350 switches::kEnableWatchdog,
351 switches::kExperimentalSpellcheckerFeatures,
352 switches::kMemoryProfiling,
353 switches::kMessageLoopHistogrammer,
354 switches::kPpapiFlashArgs,
355 switches::kPpapiFlashInProcess,
356 switches::kPpapiFlashPath,
357 switches::kPpapiFlashVersion,
358 switches::kProfilingAtStart,
359 switches::kProfilingFile,
360 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51361 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03362 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51363 };
364
365 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
366 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17367 } else if (process_type == switches::kUtilityProcess) {
368 if (browser_command_line.HasSwitch(
369 switches::kEnableExperimentalExtensionApis)) {
370 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
371 }
[email protected]4287a3d2011-06-13 23:56:51372 } else if (process_type == switches::kPluginProcess) {
373 static const char* const kSwitchNames[] = {
374 #if defined(OS_CHROMEOS)
375 switches::kLoginProfile,
376 #endif
377 switches::kMemoryProfiling,
378 switches::kSilentDumpOnDCHECK,
379 switches::kUserDataDir,
380 };
381
382 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
383 arraysize(kSwitchNames));
384 } else if (process_type == switches::kZygoteProcess) {
385 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51386 switches::kUserDataDir, // Make logs go to the right file.
387 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
388 switches::kPpapiFlashInProcess,
389 switches::kPpapiFlashPath,
390 switches::kPpapiFlashVersion,
391 };
392
393 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
394 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30395 }
[email protected]6f08af82011-09-15 01:19:03396
397 // The command line switch kEnableBenchmarking needs to be specified along
398 // with the kEnableStatsTable switch to ensure that the stats table global
399 // is initialized correctly.
400 if (command_line->HasSwitch(switches::kEnableBenchmarking))
401 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30402}
403
404std::string ChromeContentBrowserClient::GetApplicationLocale() {
405 return g_browser_process->GetApplicationLocale();
406}
407
[email protected]b5cca982011-05-26 04:42:08408std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37409 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
410 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08411}
412
[email protected]ac55e292011-06-24 05:16:08413SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
414 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
415 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
416}
417
[email protected]a2176792011-05-08 19:30:49418bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09419 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19420 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09421 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
423 ProfileIOData* io_data =
424 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]efa55212011-05-13 16:19:38425 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]0a608842011-09-08 10:55:19426 GetCookieContentSetting(manifest_url, first_party, true);
[email protected]a2176792011-05-08 19:30:49427 DCHECK(setting != CONTENT_SETTING_DEFAULT);
428 return setting != CONTENT_SETTING_BLOCK;
429}
430
[email protected]ed24fad2011-05-10 22:44:01431bool ChromeContentBrowserClient::AllowGetCookie(
432 const GURL& url,
433 const GURL& first_party,
434 const net::CookieList& cookie_list,
435 const content::ResourceContext& context,
436 int render_process_id,
437 int render_view_id) {
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32439 ProfileIOData* io_data =
440 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09441 ContentSetting setting = io_data->GetHostContentSettingsMap()->
442 GetCookieContentSetting(url, first_party, false);
443 bool allow = setting == CONTENT_SETTING_ALLOW ||
444 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01445
[email protected]8093a542011-05-13 07:29:32446 BrowserThread::PostTask(
447 BrowserThread::UI, FROM_HERE,
448 NewRunnableFunction(
449 &TabSpecificContentSettings::CookiesRead,
450 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01451 return allow;
452}
453
454bool ChromeContentBrowserClient::AllowSetCookie(
455 const GURL& url,
456 const GURL& first_party,
457 const std::string& cookie_line,
458 const content::ResourceContext& context,
459 int render_process_id,
460 int render_view_id,
461 net::CookieOptions* options) {
462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32463 ProfileIOData* io_data =
464 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09465 ContentSetting setting = io_data->GetHostContentSettingsMap()->
466 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01467
[email protected]5b52ad42011-05-26 14:26:09468 if (setting == CONTENT_SETTING_SESSION_ONLY)
469 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01470
[email protected]5b52ad42011-05-26 14:26:09471 bool allow = setting == CONTENT_SETTING_ALLOW ||
472 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01473
[email protected]8093a542011-05-13 07:29:32474 BrowserThread::PostTask(
475 BrowserThread::UI, FROM_HERE,
476 NewRunnableFunction(
477 &TabSpecificContentSettings::CookieChanged,
478 render_process_id, render_view_id, url, cookie_line, *options,
479 !allow));
[email protected]ed24fad2011-05-10 22:44:01480 return allow;
481}
482
[email protected]d5a19162011-06-30 18:51:54483bool ChromeContentBrowserClient::AllowSaveLocalState(
484 const content::ResourceContext& context) {
485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
486 ProfileIOData* io_data =
487 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
488 return !io_data->clear_local_state_on_exit()->GetValue();
489}
490
[email protected]6133f922011-07-01 21:34:34491net::URLRequestContext*
492ChromeContentBrowserClient::OverrideRequestContextForURL(
493 const GURL& url, const content::ResourceContext& context) {
494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
495 if (url.SchemeIs(chrome::kExtensionScheme)) {
496 ProfileIOData* io_data =
497 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
498 return io_data->extensions_request_context();
499 }
500
501 return NULL;
502}
503
[email protected]317f96c92011-05-31 06:53:41504QuotaPermissionContext*
505ChromeContentBrowserClient::CreateQuotaPermissionContext() {
506 return new ChromeQuotaPermissionContext();
507}
508
[email protected]a0ce3282011-08-19 20:49:52509void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42510 // On Mac, this call needs to be done on the UI thread. On other platforms,
511 // do it on the FILE thread so we don't slow down UI.
512#if defined(OS_MACOSX)
513 platform_util::OpenItem(path);
514#else
515 BrowserThread::PostTask(
516 BrowserThread::FILE, FROM_HERE,
517 NewRunnableFunction(&platform_util::OpenItem, path));
518#endif
519}
520
[email protected]a0ce3282011-08-19 20:49:52521void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
522#if defined(OS_MACOSX)
523 // Mac needs to run this operation on the UI thread.
524 platform_util::ShowItemInFolder(path);
525#else
526 BrowserThread::PostTask(
527 BrowserThread::FILE, FROM_HERE,
528 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
529#endif
530}
531
[email protected]848dd042011-06-04 18:24:03532void ChromeContentBrowserClient::AllowCertificateError(
533 SSLCertErrorHandler* handler,
534 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58535 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41536 // If the tab is being prerendered, cancel the prerender and the request.
537 TabContents* tab = tab_util::GetTabContentsByID(
538 handler->render_process_host_id(),
539 handler->tab_contents_id());
540 if (!tab) {
541 NOTREACHED();
542 return;
543 }
544 prerender::PrerenderManager* prerender_manager =
[email protected]ada01b92011-09-07 21:01:39545 Profile::FromBrowserContext(tab->browser_context())->
546 GetPrerenderManager();
[email protected]f9034cf2011-07-21 12:43:41547 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
548 if (prerender_manager->prerender_tracker()->TryCancel(
549 handler->render_process_host_id(),
550 handler->tab_contents_id(),
551 prerender::FINAL_STATUS_SSL_ERROR)) {
552 handler->CancelRequest();
553 return;
554 }
555 }
556
557 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03558 SSLBlockingPage* blocking_page = new SSLBlockingPage(
559 handler, overridable, callback);
560 blocking_page->Show();
561}
562
[email protected]c99c442e2011-08-24 11:37:30563void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45564 int render_process_id,
565 int render_view_id,
566 SSLClientAuthHandler* handler) {
567 TabContents* tab = tab_util::GetTabContentsByID(
568 render_process_id, render_view_id);
569 if (!tab) {
570 NOTREACHED();
571 return;
572 }
573
574 TabContentsWrapper* wrapper =
575 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30576 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45577}
578
579void ChromeContentBrowserClient::AddNewCertificate(
580 net::URLRequest* request,
581 net::X509Certificate* cert,
582 int render_process_id,
583 int render_view_id) {
584 // The handler will run the UI and delete itself when it's finished.
585 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
586}
587
[email protected]941623e2011-06-07 23:06:04588void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
589 const GURL& source_origin,
590 int callback_context,
591 int render_process_id,
592 int render_view_id) {
593 RenderViewHost* rvh = RenderViewHost::FromID(
594 render_process_id, render_view_id);
595 if (!rvh) {
596 NOTREACHED();
597 return;
598 }
599
600 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37601 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04602 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37603 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04604 service->RequestPermission(
605 source_origin, render_process_id, render_view_id, callback_context,
606 tab_util::GetTabContentsByID(render_process_id, render_view_id));
607}
608
609WebKit::WebNotificationPresenter::Permission
610 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
611 const GURL& source_url,
612 const content::ResourceContext& context) {
613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
614 ProfileIOData* io_data =
615 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
616
617 const Extension* extension =
618 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
619 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52620 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04621 return WebKit::WebNotificationPresenter::PermissionAllowed;
622 }
623
624 // Fall back to the regular notification preferences, which works on an
625 // origin basis.
626 return io_data->GetNotificationService() ?
627 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
628 WebKit::WebNotificationPresenter::PermissionNotAllowed;
629}
630
631void ChromeContentBrowserClient::ShowDesktopNotification(
632 const DesktopNotificationHostMsg_Show_Params& params,
633 int render_process_id,
634 int render_view_id,
635 bool worker) {
636 RenderViewHost* rvh = RenderViewHost::FromID(
637 render_process_id, render_view_id);
638 if (!rvh) {
639 NOTREACHED();
640 return;
641 }
642
643 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37644 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04645 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37646 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04647 service->ShowDesktopNotification(
648 params, render_process_id, render_view_id,
649 worker ? DesktopNotificationService::WorkerNotification :
650 DesktopNotificationService::PageNotification);
651}
652
653void ChromeContentBrowserClient::CancelDesktopNotification(
654 int render_process_id,
655 int render_view_id,
656 int notification_id) {
657 RenderViewHost* rvh = RenderViewHost::FromID(
658 render_process_id, render_view_id);
659 if (!rvh) {
660 NOTREACHED();
661 return;
662 }
663
664 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37665 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04666 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37667 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04668 service->CancelDesktopNotification(
669 render_process_id, render_view_id, notification_id);
670}
671
[email protected]9f3fba52011-06-08 20:37:19672bool ChromeContentBrowserClient::CanCreateWindow(
673 const GURL& source_url,
674 WindowContainerType container_type,
675 const content::ResourceContext& context) {
676 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
677 // If the opener is trying to create a background window but doesn't have
678 // the appropriate permission, fail the attempt.
679 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
680 ProfileIOData* io_data =
681 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
682 const Extension* extension =
683 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
684 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52685 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19686 }
687 return true;
688}
689
690std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
691 const GURL& url, const content::ResourceContext& context) {
692 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
693 // Check if it's an extension-created worker, in which case we want to use
694 // the name of the extension.
695 ProfileIOData* io_data =
696 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
697 const Extension* extension =
698 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
699 return extension ? extension->name() : std::string();
700}
701
[email protected]3cb054e62011-06-13 05:21:17702ResourceDispatcherHost*
703 ChromeContentBrowserClient::GetResourceDispatcherHost() {
704 return g_browser_process->resource_dispatcher_host();
705}
706
707ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
708 return g_browser_process->clipboard();
709}
710
[email protected]8f6a3b852011-07-19 16:48:56711MHTMLGenerationManager*
712 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
713 return g_browser_process->mhtml_generation_manager();
714}
715
[email protected]dce502762011-07-20 08:53:49716DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
717 return g_browser_process->devtools_manager();
718}
719
[email protected]ae6e9912011-07-27 01:18:28720net::NetLog* ChromeContentBrowserClient::GetNetLog() {
721 return g_browser_process->net_log();
722}
723
[email protected]3bc0b562011-08-24 23:51:04724speech_input::SpeechInputManager*
725 ChromeContentBrowserClient::GetSpeechInputManager() {
726 return speech_input::ChromeSpeechInputManager::GetInstance();
727}
728
[email protected]32538d92011-08-25 00:09:23729AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
730 return new ChromeAccessTokenStore();
731}
732
[email protected]dbae6b02011-06-29 23:51:41733bool ChromeContentBrowserClient::IsFastShutdownPossible() {
734 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
735 return !browser_command_line.HasSwitch(switches::kChromeFrame);
736}
737
[email protected]3d7474ff2011-07-27 17:47:37738WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
739 content::BrowserContext* browser_context, bool is_web_ui) {
740 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
741 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36742}
743
744void ChromeContentBrowserClient::UpdateInspectorSetting(
745 RenderViewHost* rvh, const std::string& key, const std::string& value) {
746 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37747 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36748}
749
750void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
751 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37752 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36753}
754
[email protected]b8148ac2011-07-13 22:03:25755void ChromeContentBrowserClient::BrowserURLHandlerCreated(
756 BrowserURLHandler* handler) {
757 // Add the default URL handlers.
758 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
759 BrowserURLHandler::null_handler());
760 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
761 &ExtensionWebUI::HandleChromeURLOverrideReverse);
762
763 // about:
764 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
765 BrowserURLHandler::null_handler());
766 // chrome: & friends.
767 handler->AddHandlerPair(&HandleWebUI,
768 BrowserURLHandler::null_handler());
769}
770
771void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37772 Profile* profile = Profile::FromBrowserContext(
773 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25774 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
775 BrowsingDataRemover::EVERYTHING,
776 base::Time());
777 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
778 // BrowsingDataRemover takes care of deleting itself when done.
779}
780
781void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37782 Profile* profile = Profile::FromBrowserContext(
783 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25784 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
785 BrowsingDataRemover::EVERYTHING,
786 base::Time());
[email protected]dceaa912011-09-06 17:17:23787 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:25788 remover->Remove(remove_mask);
789 // BrowsingDataRemover takes care of deleting itself when done.
790}
791
[email protected]e1d16eb92011-08-18 23:19:32792FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
793 return download_util::GetDefaultDownloadDirectory();
794}
795
[email protected]b80f68432011-05-02 17:22:30796#if defined(OS_LINUX)
797int ChromeContentBrowserClient::GetCrashSignalFD(
798 const std::string& process_type) {
799 if (process_type == switches::kRendererProcess)
800 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
801
[email protected]9dbfff12011-07-01 19:37:07802 if (process_type == switches::kExtensionProcess) {
803 ExtensionCrashHandlerHostLinux* crash_handler =
804 ExtensionCrashHandlerHostLinux::GetInstance();
805 return crash_handler->GetDeathSignalSocket();
806 }
807
[email protected]b80f68432011-05-02 17:22:30808 if (process_type == switches::kPluginProcess)
809 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
810
811 if (process_type == switches::kPpapiPluginProcess)
812 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
813
814 if (process_type == switches::kGpuProcess)
815 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
816
817 return -1;
818}
[email protected]9dbfff12011-07-01 19:37:07819#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30820
[email protected]4a65826d2011-08-25 16:04:01821#if defined(OS_WIN)
822const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
823 return chrome::kBrowserResourcesDll;
824}
825#endif
826
[email protected]37a72af2011-06-13 05:42:01827#if defined(USE_NSS)
828crypto::CryptoModuleBlockingPasswordDelegate*
829 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
830 const GURL& url) {
831 return browser::NewCryptoModuleBlockingDialogDelegate(
832 browser::kCryptoModulePasswordKeygen, url.host());
833}
834#endif
835
[email protected]d977f9c2011-03-14 16:10:26836} // namespace chrome