blob: f1f32dd53f4f2e7c93ef26c64e481c5b9c937c8c [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() ||
270 extension_process_manager->IsExtensionProcessHost(process_host->id());
271 return site_url.SchemeIs(chrome::kExtensionScheme) == is_extension_host;
272}
273
[email protected]763ec4ca2011-04-29 15:48:12274std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
275 const std::string& alias_name) {
276 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
277}
278
[email protected]b80f68432011-05-02 17:22:30279void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
280 CommandLine* command_line, int child_process_id) {
281#if defined(USE_LINUX_BREAKPAD)
282 if (IsCrashReporterEnabled()) {
283 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
284 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
285 }
286#elif defined(OS_MACOSX)
287 if (IsCrashReporterEnabled()) {
288 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
289 child_process_logging::GetClientId());
290 }
291#endif // OS_MACOSX
292
[email protected]f1933792011-06-14 00:49:34293 if (logging::DialogsAreSuppressed())
294 command_line->AppendSwitch(switches::kNoErrorDialogs);
295
[email protected]b80f68432011-05-02 17:22:30296 std::string process_type =
297 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17298 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30299 if (process_type == switches::kExtensionProcess ||
300 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30301 FilePath user_data_dir =
302 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
303 if (!user_data_dir.empty())
304 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
305#if defined(OS_CHROMEOS)
306 const std::string& login_profile =
307 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
308 if (!login_profile.empty())
309 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
310#endif
311
312 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
313
[email protected]3d7474ff2011-07-27 17:47:37314 Profile* profile = Profile::FromBrowserContext(process->browser_context());
315 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30316 // Currently this pref is only registered if applied via a policy.
317 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
318 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
319 // Turn this policy into a command line switch.
320 command_line->AppendSwitch(switches::kDisable3DAPIs);
321 }
322
323 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46324 // in the Profile preferences or the browser process.
325 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
326 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30327 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46328 }
[email protected]4287a3d2011-06-13 23:56:51329
330 static const char* const kSwitchNames[] = {
331 switches::kAllowHTTPBackgroundPage,
332 switches::kAllowScriptingGallery,
333 switches::kAppsCheckoutURL,
334 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31335 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51336 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51337 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51338 switches::kDomAutomationController,
339 switches::kDumpHistogramsOnExit,
340 switches::kEnableClickToPlay,
341 switches::kEnableCrxlessWebApps,
342 switches::kEnableExperimentalExtensionApis,
343 switches::kEnableInBrowserThumbnailing,
344 switches::kEnableIPCFuzzing,
345 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24346 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51347 switches::kEnableResourceContentSettings,
348 switches::kEnableSearchProviderApiV2,
349 switches::kEnableWatchdog,
350 switches::kExperimentalSpellcheckerFeatures,
351 switches::kMemoryProfiling,
352 switches::kMessageLoopHistogrammer,
353 switches::kPpapiFlashArgs,
354 switches::kPpapiFlashInProcess,
355 switches::kPpapiFlashPath,
356 switches::kPpapiFlashVersion,
357 switches::kProfilingAtStart,
358 switches::kProfilingFile,
359 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51360 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03361 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51362 };
363
364 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
365 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17366 } else if (process_type == switches::kUtilityProcess) {
367 if (browser_command_line.HasSwitch(
368 switches::kEnableExperimentalExtensionApis)) {
369 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
370 }
[email protected]4287a3d2011-06-13 23:56:51371 } else if (process_type == switches::kPluginProcess) {
372 static const char* const kSwitchNames[] = {
373 #if defined(OS_CHROMEOS)
374 switches::kLoginProfile,
375 #endif
376 switches::kMemoryProfiling,
377 switches::kSilentDumpOnDCHECK,
378 switches::kUserDataDir,
379 };
380
381 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
382 arraysize(kSwitchNames));
383 } else if (process_type == switches::kZygoteProcess) {
384 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51385 switches::kUserDataDir, // Make logs go to the right file.
386 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
387 switches::kPpapiFlashInProcess,
388 switches::kPpapiFlashPath,
389 switches::kPpapiFlashVersion,
390 };
391
392 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
393 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30394 }
[email protected]6f08af82011-09-15 01:19:03395
396 // The command line switch kEnableBenchmarking needs to be specified along
397 // with the kEnableStatsTable switch to ensure that the stats table global
398 // is initialized correctly.
399 if (command_line->HasSwitch(switches::kEnableBenchmarking))
400 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30401}
402
403std::string ChromeContentBrowserClient::GetApplicationLocale() {
404 return g_browser_process->GetApplicationLocale();
405}
406
[email protected]b5cca982011-05-26 04:42:08407std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37408 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
409 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08410}
411
[email protected]ac55e292011-06-24 05:16:08412SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
413 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
414 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
415}
416
[email protected]a2176792011-05-08 19:30:49417bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09418 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19419 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09420 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
422 ProfileIOData* io_data =
423 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]efa55212011-05-13 16:19:38424 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]0a608842011-09-08 10:55:19425 GetCookieContentSetting(manifest_url, first_party, true);
[email protected]a2176792011-05-08 19:30:49426 DCHECK(setting != CONTENT_SETTING_DEFAULT);
427 return setting != CONTENT_SETTING_BLOCK;
428}
429
[email protected]ed24fad2011-05-10 22:44:01430bool ChromeContentBrowserClient::AllowGetCookie(
431 const GURL& url,
432 const GURL& first_party,
433 const net::CookieList& cookie_list,
434 const content::ResourceContext& context,
435 int render_process_id,
436 int render_view_id) {
437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32438 ProfileIOData* io_data =
439 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09440 ContentSetting setting = io_data->GetHostContentSettingsMap()->
441 GetCookieContentSetting(url, first_party, false);
442 bool allow = setting == CONTENT_SETTING_ALLOW ||
443 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01444
[email protected]8093a542011-05-13 07:29:32445 BrowserThread::PostTask(
446 BrowserThread::UI, FROM_HERE,
447 NewRunnableFunction(
448 &TabSpecificContentSettings::CookiesRead,
449 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01450 return allow;
451}
452
453bool ChromeContentBrowserClient::AllowSetCookie(
454 const GURL& url,
455 const GURL& first_party,
456 const std::string& cookie_line,
457 const content::ResourceContext& context,
458 int render_process_id,
459 int render_view_id,
460 net::CookieOptions* options) {
461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32462 ProfileIOData* io_data =
463 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09464 ContentSetting setting = io_data->GetHostContentSettingsMap()->
465 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01466
[email protected]5b52ad42011-05-26 14:26:09467 if (setting == CONTENT_SETTING_SESSION_ONLY)
468 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01469
[email protected]5b52ad42011-05-26 14:26:09470 bool allow = setting == CONTENT_SETTING_ALLOW ||
471 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01472
[email protected]8093a542011-05-13 07:29:32473 BrowserThread::PostTask(
474 BrowserThread::UI, FROM_HERE,
475 NewRunnableFunction(
476 &TabSpecificContentSettings::CookieChanged,
477 render_process_id, render_view_id, url, cookie_line, *options,
478 !allow));
[email protected]ed24fad2011-05-10 22:44:01479 return allow;
480}
481
[email protected]d5a19162011-06-30 18:51:54482bool ChromeContentBrowserClient::AllowSaveLocalState(
483 const content::ResourceContext& context) {
484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
485 ProfileIOData* io_data =
486 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
487 return !io_data->clear_local_state_on_exit()->GetValue();
488}
489
[email protected]6133f922011-07-01 21:34:34490net::URLRequestContext*
491ChromeContentBrowserClient::OverrideRequestContextForURL(
492 const GURL& url, const content::ResourceContext& context) {
493 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
494 if (url.SchemeIs(chrome::kExtensionScheme)) {
495 ProfileIOData* io_data =
496 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
497 return io_data->extensions_request_context();
498 }
499
500 return NULL;
501}
502
[email protected]317f96c92011-05-31 06:53:41503QuotaPermissionContext*
504ChromeContentBrowserClient::CreateQuotaPermissionContext() {
505 return new ChromeQuotaPermissionContext();
506}
507
[email protected]a0ce3282011-08-19 20:49:52508void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42509 // On Mac, this call needs to be done on the UI thread. On other platforms,
510 // do it on the FILE thread so we don't slow down UI.
511#if defined(OS_MACOSX)
512 platform_util::OpenItem(path);
513#else
514 BrowserThread::PostTask(
515 BrowserThread::FILE, FROM_HERE,
516 NewRunnableFunction(&platform_util::OpenItem, path));
517#endif
518}
519
[email protected]a0ce3282011-08-19 20:49:52520void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
521#if defined(OS_MACOSX)
522 // Mac needs to run this operation on the UI thread.
523 platform_util::ShowItemInFolder(path);
524#else
525 BrowserThread::PostTask(
526 BrowserThread::FILE, FROM_HERE,
527 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
528#endif
529}
530
[email protected]848dd042011-06-04 18:24:03531void ChromeContentBrowserClient::AllowCertificateError(
532 SSLCertErrorHandler* handler,
533 bool overridable,
534 Callback2<SSLCertErrorHandler*, bool>::Type* callback) {
[email protected]f9034cf2011-07-21 12:43:41535 // If the tab is being prerendered, cancel the prerender and the request.
536 TabContents* tab = tab_util::GetTabContentsByID(
537 handler->render_process_host_id(),
538 handler->tab_contents_id());
539 if (!tab) {
540 NOTREACHED();
541 return;
542 }
543 prerender::PrerenderManager* prerender_manager =
[email protected]ada01b92011-09-07 21:01:39544 Profile::FromBrowserContext(tab->browser_context())->
545 GetPrerenderManager();
[email protected]f9034cf2011-07-21 12:43:41546 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
547 if (prerender_manager->prerender_tracker()->TryCancel(
548 handler->render_process_host_id(),
549 handler->tab_contents_id(),
550 prerender::FINAL_STATUS_SSL_ERROR)) {
551 handler->CancelRequest();
552 return;
553 }
554 }
555
556 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03557 SSLBlockingPage* blocking_page = new SSLBlockingPage(
558 handler, overridable, callback);
559 blocking_page->Show();
560}
561
[email protected]c99c442e2011-08-24 11:37:30562void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45563 int render_process_id,
564 int render_view_id,
565 SSLClientAuthHandler* handler) {
566 TabContents* tab = tab_util::GetTabContentsByID(
567 render_process_id, render_view_id);
568 if (!tab) {
569 NOTREACHED();
570 return;
571 }
572
573 TabContentsWrapper* wrapper =
574 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30575 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45576}
577
578void ChromeContentBrowserClient::AddNewCertificate(
579 net::URLRequest* request,
580 net::X509Certificate* cert,
581 int render_process_id,
582 int render_view_id) {
583 // The handler will run the UI and delete itself when it's finished.
584 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
585}
586
[email protected]941623e2011-06-07 23:06:04587void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
588 const GURL& source_origin,
589 int callback_context,
590 int render_process_id,
591 int render_view_id) {
592 RenderViewHost* rvh = RenderViewHost::FromID(
593 render_process_id, render_view_id);
594 if (!rvh) {
595 NOTREACHED();
596 return;
597 }
598
599 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37600 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04601 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37602 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04603 service->RequestPermission(
604 source_origin, render_process_id, render_view_id, callback_context,
605 tab_util::GetTabContentsByID(render_process_id, render_view_id));
606}
607
608WebKit::WebNotificationPresenter::Permission
609 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
610 const GURL& source_url,
611 const content::ResourceContext& context) {
612 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
613 ProfileIOData* io_data =
614 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
615
616 const Extension* extension =
617 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
618 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52619 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04620 return WebKit::WebNotificationPresenter::PermissionAllowed;
621 }
622
623 // Fall back to the regular notification preferences, which works on an
624 // origin basis.
625 return io_data->GetNotificationService() ?
626 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
627 WebKit::WebNotificationPresenter::PermissionNotAllowed;
628}
629
630void ChromeContentBrowserClient::ShowDesktopNotification(
631 const DesktopNotificationHostMsg_Show_Params& params,
632 int render_process_id,
633 int render_view_id,
634 bool worker) {
635 RenderViewHost* rvh = RenderViewHost::FromID(
636 render_process_id, render_view_id);
637 if (!rvh) {
638 NOTREACHED();
639 return;
640 }
641
642 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37643 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04644 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37645 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04646 service->ShowDesktopNotification(
647 params, render_process_id, render_view_id,
648 worker ? DesktopNotificationService::WorkerNotification :
649 DesktopNotificationService::PageNotification);
650}
651
652void ChromeContentBrowserClient::CancelDesktopNotification(
653 int render_process_id,
654 int render_view_id,
655 int notification_id) {
656 RenderViewHost* rvh = RenderViewHost::FromID(
657 render_process_id, render_view_id);
658 if (!rvh) {
659 NOTREACHED();
660 return;
661 }
662
663 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37664 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04665 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37666 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04667 service->CancelDesktopNotification(
668 render_process_id, render_view_id, notification_id);
669}
670
[email protected]9f3fba52011-06-08 20:37:19671bool ChromeContentBrowserClient::CanCreateWindow(
672 const GURL& source_url,
673 WindowContainerType container_type,
674 const content::ResourceContext& context) {
675 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
676 // If the opener is trying to create a background window but doesn't have
677 // the appropriate permission, fail the attempt.
678 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
679 ProfileIOData* io_data =
680 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
681 const Extension* extension =
682 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
683 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52684 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19685 }
686 return true;
687}
688
689std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
690 const GURL& url, const content::ResourceContext& context) {
691 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
692 // Check if it's an extension-created worker, in which case we want to use
693 // the name of the extension.
694 ProfileIOData* io_data =
695 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
696 const Extension* extension =
697 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
698 return extension ? extension->name() : std::string();
699}
700
[email protected]3cb054e62011-06-13 05:21:17701ResourceDispatcherHost*
702 ChromeContentBrowserClient::GetResourceDispatcherHost() {
703 return g_browser_process->resource_dispatcher_host();
704}
705
706ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
707 return g_browser_process->clipboard();
708}
709
[email protected]8f6a3b852011-07-19 16:48:56710MHTMLGenerationManager*
711 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
712 return g_browser_process->mhtml_generation_manager();
713}
714
[email protected]dce502762011-07-20 08:53:49715DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
716 return g_browser_process->devtools_manager();
717}
718
[email protected]ae6e9912011-07-27 01:18:28719net::NetLog* ChromeContentBrowserClient::GetNetLog() {
720 return g_browser_process->net_log();
721}
722
[email protected]3bc0b562011-08-24 23:51:04723speech_input::SpeechInputManager*
724 ChromeContentBrowserClient::GetSpeechInputManager() {
725 return speech_input::ChromeSpeechInputManager::GetInstance();
726}
727
[email protected]32538d92011-08-25 00:09:23728AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
729 return new ChromeAccessTokenStore();
730}
731
[email protected]dbae6b02011-06-29 23:51:41732bool ChromeContentBrowserClient::IsFastShutdownPossible() {
733 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
734 return !browser_command_line.HasSwitch(switches::kChromeFrame);
735}
736
[email protected]3d7474ff2011-07-27 17:47:37737WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
738 content::BrowserContext* browser_context, bool is_web_ui) {
739 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
740 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36741}
742
743void ChromeContentBrowserClient::UpdateInspectorSetting(
744 RenderViewHost* rvh, const std::string& key, const std::string& value) {
745 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37746 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36747}
748
749void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
750 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37751 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36752}
753
[email protected]b8148ac2011-07-13 22:03:25754void ChromeContentBrowserClient::BrowserURLHandlerCreated(
755 BrowserURLHandler* handler) {
756 // Add the default URL handlers.
757 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
758 BrowserURLHandler::null_handler());
759 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
760 &ExtensionWebUI::HandleChromeURLOverrideReverse);
761
762 // about:
763 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
764 BrowserURLHandler::null_handler());
765 // chrome: & friends.
766 handler->AddHandlerPair(&HandleWebUI,
767 BrowserURLHandler::null_handler());
768}
769
770void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37771 Profile* profile = Profile::FromBrowserContext(
772 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25773 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
774 BrowsingDataRemover::EVERYTHING,
775 base::Time());
776 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
777 // BrowsingDataRemover takes care of deleting itself when done.
778}
779
780void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37781 Profile* profile = Profile::FromBrowserContext(
782 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25783 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
784 BrowsingDataRemover::EVERYTHING,
785 base::Time());
[email protected]dceaa912011-09-06 17:17:23786 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:25787 remover->Remove(remove_mask);
788 // BrowsingDataRemover takes care of deleting itself when done.
789}
790
[email protected]e1d16eb92011-08-18 23:19:32791FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
792 return download_util::GetDefaultDownloadDirectory();
793}
794
[email protected]b68bf3892011-08-23 15:03:58795net::URLRequestContextGetter*
796ChromeContentBrowserClient::GetDefaultRequestContextDeprecatedCrBug64339() {
797 return Profile::Deprecated::GetDefaultRequestContext();
798}
799
[email protected]c8571ea2011-08-26 17:22:17800net::URLRequestContextGetter*
801ChromeContentBrowserClient::GetSystemRequestContext() {
802 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
803 return g_browser_process->system_request_context();
804}
805
[email protected]b80f68432011-05-02 17:22:30806#if defined(OS_LINUX)
807int ChromeContentBrowserClient::GetCrashSignalFD(
808 const std::string& process_type) {
809 if (process_type == switches::kRendererProcess)
810 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
811
[email protected]9dbfff12011-07-01 19:37:07812 if (process_type == switches::kExtensionProcess) {
813 ExtensionCrashHandlerHostLinux* crash_handler =
814 ExtensionCrashHandlerHostLinux::GetInstance();
815 return crash_handler->GetDeathSignalSocket();
816 }
817
[email protected]b80f68432011-05-02 17:22:30818 if (process_type == switches::kPluginProcess)
819 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
820
821 if (process_type == switches::kPpapiPluginProcess)
822 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
823
824 if (process_type == switches::kGpuProcess)
825 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
826
827 return -1;
828}
[email protected]9dbfff12011-07-01 19:37:07829#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30830
[email protected]4a65826d2011-08-25 16:04:01831#if defined(OS_WIN)
832const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
833 return chrome::kBrowserResourcesDll;
834}
835#endif
836
[email protected]37a72af2011-06-13 05:42:01837#if defined(USE_NSS)
838crypto::CryptoModuleBlockingPasswordDelegate*
839 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
840 const GURL& url) {
841 return browser::NewCryptoModuleBlockingDialogDelegate(
842 browser::kCryptoModulePasswordKeygen, url.host());
843}
844#endif
845
[email protected]d977f9c2011-03-14 16:10:26846} // namespace chrome