blob: efec5727f56d11caa51fef060db85fef32f66fa4 [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"
[email protected]3085c502011-10-05 17:50:5032#include "chrome/browser/prerender/prerender_manager_factory.h"
[email protected]f9034cf2011-07-21 12:43:4133#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1434#include "chrome/browser/printing/printing_message_filter.h"
35#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3236#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1437#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3338#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]05fcf982011-04-19 00:44:1439#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0440#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4641#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4542#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0343#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3644#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4545#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
46#include "chrome/browser/tab_contents/tab_util.h"
47#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5648#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3049#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0150#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3051#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0452#include "chrome/common/extensions/extension.h"
[email protected]f1933792011-06-14 00:49:3453#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1254#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3855#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0956#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2557#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0958#include "content/browser/browsing_instance.h"
[email protected]97e6c4c2011-05-18 16:08:5159#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1460#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2661#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4962#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0963#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4164#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4565#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1266#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3267#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3668#include "content/browser/worker_host/worker_process_host.h"
[email protected]941623e2011-06-07 23:06:0469#include "content/common/desktop_notification_messages.h"
[email protected]29b25d092011-06-29 20:57:3470#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0171#include "net/base/cookie_monster.h"
72#include "net/base/cookie_options.h"
[email protected]ac55e292011-06-24 05:16:0873#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2674
[email protected]199fc7a2011-09-28 22:45:3875#if defined(USE_AURA)
76#include "chrome/browser/chrome_browser_main_aura.h"
77#elif defined(OS_WIN)
78#include "chrome/browser/chrome_browser_main_win.h"
79#elif defined(OS_MACOSX)
80#include "chrome/browser/chrome_browser_main_mac.h"
81#elif defined(OS_CHROMEOS)
82#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
83#elif defined(OS_LINUX)
84#include "chrome/browser/chrome_browser_main_gtk.h"
85#endif
86
[email protected]b80f68432011-05-02 17:22:3087#if defined(OS_LINUX)
88#include "base/linux_util.h"
89#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:4390#endif
[email protected]b80f68432011-05-02 17:22:3091
[email protected]080f34f2011-09-20 05:39:2692#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:3293#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
94#elif defined(OS_LINUX)
95#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
96#elif defined(OS_MACOSX)
97#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]74313b42011-08-24 16:51:3298#endif
99
[email protected]37a72af2011-06-13 05:42:01100#if defined(USE_NSS)
101#include "chrome/browser/ui/crypto_module_password_dialog.h"
102#endif
103
[email protected]c5dbef02011-05-13 05:06:09104namespace {
105
[email protected]b8148ac2011-07-13 22:03:25106// Handles rewriting Web UI URLs.
[email protected]3d7474ff2011-07-27 17:47:37107static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
108 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25109 return false;
110
111 // Special case the new tab page. In older versions of Chrome, the new tab
112 // page was hosted at chrome-internal:<blah>. This might be in people's saved
113 // sessions or bookmarks, so we say any URL with that scheme triggers the new
114 // tab page.
115 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
116 // Rewrite it with the proper new tab URL.
117 *url = GURL(chrome::kChromeUINewTabURL);
118 }
119
120 return true;
121}
122
[email protected]9dbfff12011-07-01 19:37:07123} // namespace
[email protected]c5dbef02011-05-13 05:06:09124
[email protected]d977f9c2011-03-14 16:10:26125namespace chrome {
126
[email protected]f967b722011-09-07 00:58:04127content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
128 const MainFunctionParams& parameters) {
[email protected]199fc7a2011-09-28 22:45:38129#if defined(USE_AURA)
130 return new ChromeBrowserMainPartsAura(parameters);
131#elif defined(OS_WIN)
[email protected]e6b5bc22011-09-08 22:01:56132 return new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04133#elif defined(OS_MACOSX)
[email protected]46c83b62011-09-08 22:09:04134 return new ChromeBrowserMainPartsMac(parameters);
[email protected]f967b722011-09-07 00:58:04135#elif defined(OS_CHROMEOS)
[email protected]46c83b62011-09-08 22:09:04136 return new ChromeBrowserMainPartsChromeos(parameters);
[email protected]f967b722011-09-07 00:58:04137#elif defined(OS_LINUX)
[email protected]e6b5bc22011-09-08 22:01:56138 return new ChromeBrowserMainPartsGtk(parameters);
[email protected]f967b722011-09-07 00:58:04139#else
140 return NULL;
141#endif
142}
143
[email protected]74313b42011-08-24 16:51:32144TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
145 TabContents* tab_contents) {
[email protected]080f34f2011-09-20 05:39:26146#if defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32147 return new TabContentsViewViews(tab_contents);
148#elif defined(OS_LINUX)
149 return new TabContentsViewGtk(tab_contents);
150#elif defined(OS_MACOSX)
151 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32152#else
153#error Need to create your platform TabContentsView here.
154#endif
155}
156
[email protected]f364d1392011-04-08 21:03:10157void ChromeContentBrowserClient::RenderViewHostCreated(
158 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46159
160 SiteInstance* site_instance = render_view_host->site_instance();
161 Profile* profile = Profile::FromBrowserContext(
162 site_instance->browsing_instance()->browser_context());
163
164 new ChromeRenderViewHostObserver(render_view_host,
165 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10166 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26167}
168
[email protected]05fcf982011-04-19 00:44:14169void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
170 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02171 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37172 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14173 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02174 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14175 host->channel()->AddFilter(new PrintingMessageFilter());
176 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02177 new SearchProviderInstallStateMessageFilter(id, profile));
178 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]6f08af82011-09-15 01:19:03179 host->channel()->AddFilter(new ChromeBenchmarkingMessageFilter(
180 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]3e69bc82011-05-26 23:22:38181
[email protected]2ccf45c2011-08-19 23:35:50182 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
183 profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14184}
185
[email protected]97e6c4c2011-05-18 16:08:51186void ChromeContentBrowserClient::PluginProcessHostCreated(
187 PluginProcessHost* host) {
188 host->AddFilter(new ChromePluginMessageFilter(host));
189}
190
[email protected]5327dfb2011-05-03 17:50:36191void ChromeContentBrowserClient::WorkerProcessHostCreated(
192 WorkerProcessHost* host) {
193 host->AddFilter(new ChromeWorkerMessageFilter(host));
194}
195
[email protected]1fd1a502011-03-30 16:55:56196content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
197 return ChromeWebUIFactory::GetInstance();
198}
199
[email protected]3d7474ff2011-07-27 17:47:37200GURL ChromeContentBrowserClient::GetEffectiveURL(
201 content::BrowserContext* browser_context, const GURL& url) {
202 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08203 // Get the effective URL for the given actual URL. If the URL is part of an
204 // installed app, the effective URL is an extension URL with the ID of that
205 // extension as the host. This has the effect of grouping apps together in
206 // a common SiteInstance.
207 if (!profile || !profile->GetExtensionService())
208 return url;
209
210 const Extension* extension =
211 profile->GetExtensionService()->GetExtensionByWebExtent(url);
212 if (!extension)
213 return url;
214
215 // If the URL is part of an extension's web extent, convert it to an
216 // extension URL.
217 return extension->GetResourceURL(url.path());
218}
219
[email protected]056ad2a2011-07-12 02:13:55220bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37221 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55222 // Non-extension URLs should generally use process-per-site-instance.
223 // Because we expect to use the effective URL, hosted apps URLs should have
224 // an extension scheme by now.
225 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
226 return false;
227
[email protected]3d7474ff2011-07-27 17:47:37228 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55229 if (!profile || !profile->GetExtensionService())
230 return false;
231
232 const Extension* extension =
233 profile->GetExtensionService()->GetExtensionByURL(effective_url);
234 if (!extension)
235 return false;
236
237 // If the URL is part of a hosted app that does not have the background
238 // permission, we want to give each instance its own process to improve
239 // responsiveness.
240 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
241 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
242 return false;
243
244 // Hosted apps that have the background permission must use process per site,
245 // since all instances can make synchronous calls to the background window.
246 // Other extensions should use process per site as well.
247 return true;
248}
249
[email protected]0f012df82011-05-19 14:15:29250bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03251 return url == GURL(chrome::kChromeUICrashURL) ||
252 url == GURL(chrome::kChromeUIKillURL) ||
253 url == GURL(chrome::kChromeUIHangURL) ||
254 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29255}
256
[email protected]2a5221b2011-09-27 23:07:31257bool ChromeContentBrowserClient::IsSuitableHost(
258 RenderProcessHost* process_host,
259 const GURL& site_url) {
260 Profile* profile =
261 Profile::FromBrowserContext(process_host->browser_context());
262 ExtensionProcessManager* extension_process_manager =
263 profile->GetExtensionProcessManager();
264
265 // Maybe NULL during tests.
266 if (!extension_process_manager)
267 return true;
268
269 bool is_extension_host =
270 process_host->is_extension_process() ||
[email protected]8add5412011-10-01 21:02:14271 extension_process_manager->AreBindingsEnabledForProcess(
272 process_host->id());
[email protected]2a5221b2011-09-27 23:07:31273 return site_url.SchemeIs(chrome::kExtensionScheme) == is_extension_host;
274}
275
[email protected]763ec4ca2011-04-29 15:48:12276std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
277 const std::string& alias_name) {
278 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
279}
280
[email protected]b80f68432011-05-02 17:22:30281void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
282 CommandLine* command_line, int child_process_id) {
283#if defined(USE_LINUX_BREAKPAD)
284 if (IsCrashReporterEnabled()) {
285 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
286 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
287 }
288#elif defined(OS_MACOSX)
289 if (IsCrashReporterEnabled()) {
290 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
291 child_process_logging::GetClientId());
292 }
293#endif // OS_MACOSX
294
[email protected]f1933792011-06-14 00:49:34295 if (logging::DialogsAreSuppressed())
296 command_line->AppendSwitch(switches::kNoErrorDialogs);
297
[email protected]b80f68432011-05-02 17:22:30298 std::string process_type =
299 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17300 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30301 if (process_type == switches::kExtensionProcess ||
302 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30303 FilePath user_data_dir =
304 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
305 if (!user_data_dir.empty())
306 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
307#if defined(OS_CHROMEOS)
308 const std::string& login_profile =
309 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
310 if (!login_profile.empty())
311 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
312#endif
313
314 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
315
[email protected]3d7474ff2011-07-27 17:47:37316 Profile* profile = Profile::FromBrowserContext(process->browser_context());
317 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30318 // Currently this pref is only registered if applied via a policy.
319 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
320 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
321 // Turn this policy into a command line switch.
322 command_line->AppendSwitch(switches::kDisable3DAPIs);
323 }
324
325 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46326 // in the Profile preferences or the browser process.
327 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
328 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30329 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46330 }
[email protected]4287a3d2011-06-13 23:56:51331
332 static const char* const kSwitchNames[] = {
333 switches::kAllowHTTPBackgroundPage,
334 switches::kAllowScriptingGallery,
335 switches::kAppsCheckoutURL,
336 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31337 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51338 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51339 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51340 switches::kDomAutomationController,
341 switches::kDumpHistogramsOnExit,
342 switches::kEnableClickToPlay,
343 switches::kEnableCrxlessWebApps,
344 switches::kEnableExperimentalExtensionApis,
345 switches::kEnableInBrowserThumbnailing,
346 switches::kEnableIPCFuzzing,
347 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24348 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51349 switches::kEnableResourceContentSettings,
350 switches::kEnableSearchProviderApiV2,
351 switches::kEnableWatchdog,
352 switches::kExperimentalSpellcheckerFeatures,
353 switches::kMemoryProfiling,
354 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04355 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51356 switches::kPpapiFlashArgs,
357 switches::kPpapiFlashInProcess,
358 switches::kPpapiFlashPath,
359 switches::kPpapiFlashVersion,
360 switches::kProfilingAtStart,
361 switches::kProfilingFile,
362 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51363 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03364 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51365 };
366
367 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
368 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17369 } else if (process_type == switches::kUtilityProcess) {
370 if (browser_command_line.HasSwitch(
371 switches::kEnableExperimentalExtensionApis)) {
372 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
373 }
[email protected]4287a3d2011-06-13 23:56:51374 } else if (process_type == switches::kPluginProcess) {
375 static const char* const kSwitchNames[] = {
376 #if defined(OS_CHROMEOS)
377 switches::kLoginProfile,
378 #endif
379 switches::kMemoryProfiling,
380 switches::kSilentDumpOnDCHECK,
381 switches::kUserDataDir,
382 };
383
384 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
385 arraysize(kSwitchNames));
386 } else if (process_type == switches::kZygoteProcess) {
387 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51388 switches::kUserDataDir, // Make logs go to the right file.
389 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
390 switches::kPpapiFlashInProcess,
391 switches::kPpapiFlashPath,
392 switches::kPpapiFlashVersion,
393 };
394
395 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
396 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30397 }
[email protected]6f08af82011-09-15 01:19:03398
399 // The command line switch kEnableBenchmarking needs to be specified along
400 // with the kEnableStatsTable switch to ensure that the stats table global
401 // is initialized correctly.
402 if (command_line->HasSwitch(switches::kEnableBenchmarking))
403 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30404}
405
406std::string ChromeContentBrowserClient::GetApplicationLocale() {
407 return g_browser_process->GetApplicationLocale();
408}
409
[email protected]b5cca982011-05-26 04:42:08410std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37411 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
412 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08413}
414
[email protected]ac55e292011-06-24 05:16:08415SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
416 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
417 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
418}
419
[email protected]a2176792011-05-08 19:30:49420bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09421 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19422 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09423 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
425 ProfileIOData* io_data =
426 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]efa55212011-05-13 16:19:38427 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]0a608842011-09-08 10:55:19428 GetCookieContentSetting(manifest_url, first_party, true);
[email protected]a2176792011-05-08 19:30:49429 DCHECK(setting != CONTENT_SETTING_DEFAULT);
430 return setting != CONTENT_SETTING_BLOCK;
431}
432
[email protected]ed24fad2011-05-10 22:44:01433bool ChromeContentBrowserClient::AllowGetCookie(
434 const GURL& url,
435 const GURL& first_party,
436 const net::CookieList& cookie_list,
437 const content::ResourceContext& context,
438 int render_process_id,
439 int render_view_id) {
440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32441 ProfileIOData* io_data =
442 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09443 ContentSetting setting = io_data->GetHostContentSettingsMap()->
444 GetCookieContentSetting(url, first_party, false);
445 bool allow = setting == CONTENT_SETTING_ALLOW ||
446 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01447
[email protected]8093a542011-05-13 07:29:32448 BrowserThread::PostTask(
449 BrowserThread::UI, FROM_HERE,
450 NewRunnableFunction(
451 &TabSpecificContentSettings::CookiesRead,
452 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01453 return allow;
454}
455
456bool ChromeContentBrowserClient::AllowSetCookie(
457 const GURL& url,
458 const GURL& first_party,
459 const std::string& cookie_line,
460 const content::ResourceContext& context,
461 int render_process_id,
462 int render_view_id,
463 net::CookieOptions* options) {
464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32465 ProfileIOData* io_data =
466 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09467 ContentSetting setting = io_data->GetHostContentSettingsMap()->
468 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01469
[email protected]5b52ad42011-05-26 14:26:09470 if (setting == CONTENT_SETTING_SESSION_ONLY)
471 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01472
[email protected]5b52ad42011-05-26 14:26:09473 bool allow = setting == CONTENT_SETTING_ALLOW ||
474 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01475
[email protected]8093a542011-05-13 07:29:32476 BrowserThread::PostTask(
477 BrowserThread::UI, FROM_HERE,
478 NewRunnableFunction(
479 &TabSpecificContentSettings::CookieChanged,
480 render_process_id, render_view_id, url, cookie_line, *options,
481 !allow));
[email protected]ed24fad2011-05-10 22:44:01482 return allow;
483}
484
[email protected]d5a19162011-06-30 18:51:54485bool ChromeContentBrowserClient::AllowSaveLocalState(
486 const content::ResourceContext& context) {
487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
488 ProfileIOData* io_data =
489 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
490 return !io_data->clear_local_state_on_exit()->GetValue();
491}
492
[email protected]6133f922011-07-01 21:34:34493net::URLRequestContext*
494ChromeContentBrowserClient::OverrideRequestContextForURL(
495 const GURL& url, const content::ResourceContext& context) {
496 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
497 if (url.SchemeIs(chrome::kExtensionScheme)) {
498 ProfileIOData* io_data =
499 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
500 return io_data->extensions_request_context();
501 }
502
503 return NULL;
504}
505
[email protected]317f96c92011-05-31 06:53:41506QuotaPermissionContext*
507ChromeContentBrowserClient::CreateQuotaPermissionContext() {
508 return new ChromeQuotaPermissionContext();
509}
510
[email protected]a0ce3282011-08-19 20:49:52511void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42512 // On Mac, this call needs to be done on the UI thread. On other platforms,
513 // do it on the FILE thread so we don't slow down UI.
514#if defined(OS_MACOSX)
515 platform_util::OpenItem(path);
516#else
517 BrowserThread::PostTask(
518 BrowserThread::FILE, FROM_HERE,
519 NewRunnableFunction(&platform_util::OpenItem, path));
520#endif
521}
522
[email protected]a0ce3282011-08-19 20:49:52523void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
524#if defined(OS_MACOSX)
525 // Mac needs to run this operation on the UI thread.
526 platform_util::ShowItemInFolder(path);
527#else
528 BrowserThread::PostTask(
529 BrowserThread::FILE, FROM_HERE,
530 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
531#endif
532}
533
[email protected]848dd042011-06-04 18:24:03534void ChromeContentBrowserClient::AllowCertificateError(
535 SSLCertErrorHandler* handler,
536 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58537 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41538 // If the tab is being prerendered, cancel the prerender and the request.
539 TabContents* tab = tab_util::GetTabContentsByID(
540 handler->render_process_host_id(),
541 handler->tab_contents_id());
542 if (!tab) {
543 NOTREACHED();
544 return;
545 }
546 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50547 prerender::PrerenderManagerFactory::GetForProfile(
548 Profile::FromBrowserContext(tab->browser_context()));
[email protected]f9034cf2011-07-21 12:43:41549 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
550 if (prerender_manager->prerender_tracker()->TryCancel(
551 handler->render_process_host_id(),
552 handler->tab_contents_id(),
553 prerender::FINAL_STATUS_SSL_ERROR)) {
554 handler->CancelRequest();
555 return;
556 }
557 }
558
559 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03560 SSLBlockingPage* blocking_page = new SSLBlockingPage(
561 handler, overridable, callback);
562 blocking_page->Show();
563}
564
[email protected]c99c442e2011-08-24 11:37:30565void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45566 int render_process_id,
567 int render_view_id,
568 SSLClientAuthHandler* handler) {
569 TabContents* tab = tab_util::GetTabContentsByID(
570 render_process_id, render_view_id);
571 if (!tab) {
572 NOTREACHED();
573 return;
574 }
575
576 TabContentsWrapper* wrapper =
577 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30578 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45579}
580
581void ChromeContentBrowserClient::AddNewCertificate(
582 net::URLRequest* request,
583 net::X509Certificate* cert,
584 int render_process_id,
585 int render_view_id) {
586 // The handler will run the UI and delete itself when it's finished.
587 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
588}
589
[email protected]941623e2011-06-07 23:06:04590void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
591 const GURL& source_origin,
592 int callback_context,
593 int render_process_id,
594 int render_view_id) {
595 RenderViewHost* rvh = RenderViewHost::FromID(
596 render_process_id, render_view_id);
597 if (!rvh) {
598 NOTREACHED();
599 return;
600 }
601
602 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37603 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04604 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37605 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04606 service->RequestPermission(
607 source_origin, render_process_id, render_view_id, callback_context,
608 tab_util::GetTabContentsByID(render_process_id, render_view_id));
609}
610
611WebKit::WebNotificationPresenter::Permission
612 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
613 const GURL& source_url,
614 const content::ResourceContext& context) {
615 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
616 ProfileIOData* io_data =
617 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
618
619 const Extension* extension =
620 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
621 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52622 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04623 return WebKit::WebNotificationPresenter::PermissionAllowed;
624 }
625
626 // Fall back to the regular notification preferences, which works on an
627 // origin basis.
628 return io_data->GetNotificationService() ?
629 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
630 WebKit::WebNotificationPresenter::PermissionNotAllowed;
631}
632
633void ChromeContentBrowserClient::ShowDesktopNotification(
634 const DesktopNotificationHostMsg_Show_Params& params,
635 int render_process_id,
636 int render_view_id,
637 bool worker) {
638 RenderViewHost* rvh = RenderViewHost::FromID(
639 render_process_id, render_view_id);
640 if (!rvh) {
641 NOTREACHED();
642 return;
643 }
644
645 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37646 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04647 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37648 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04649 service->ShowDesktopNotification(
650 params, render_process_id, render_view_id,
651 worker ? DesktopNotificationService::WorkerNotification :
652 DesktopNotificationService::PageNotification);
653}
654
655void ChromeContentBrowserClient::CancelDesktopNotification(
656 int render_process_id,
657 int render_view_id,
658 int notification_id) {
659 RenderViewHost* rvh = RenderViewHost::FromID(
660 render_process_id, render_view_id);
661 if (!rvh) {
662 NOTREACHED();
663 return;
664 }
665
666 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37667 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04668 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37669 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04670 service->CancelDesktopNotification(
671 render_process_id, render_view_id, notification_id);
672}
673
[email protected]9f3fba52011-06-08 20:37:19674bool ChromeContentBrowserClient::CanCreateWindow(
675 const GURL& source_url,
676 WindowContainerType container_type,
677 const content::ResourceContext& context) {
678 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
679 // If the opener is trying to create a background window but doesn't have
680 // the appropriate permission, fail the attempt.
681 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
682 ProfileIOData* io_data =
683 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
684 const Extension* extension =
685 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
686 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52687 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19688 }
689 return true;
690}
691
692std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
693 const GURL& url, const content::ResourceContext& context) {
694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
695 // Check if it's an extension-created worker, in which case we want to use
696 // the name of the extension.
697 ProfileIOData* io_data =
698 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
699 const Extension* extension =
700 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
701 return extension ? extension->name() : std::string();
702}
703
[email protected]3cb054e62011-06-13 05:21:17704ResourceDispatcherHost*
705 ChromeContentBrowserClient::GetResourceDispatcherHost() {
706 return g_browser_process->resource_dispatcher_host();
707}
708
709ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
710 return g_browser_process->clipboard();
711}
712
[email protected]8f6a3b852011-07-19 16:48:56713MHTMLGenerationManager*
714 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
715 return g_browser_process->mhtml_generation_manager();
716}
717
[email protected]dce502762011-07-20 08:53:49718DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
719 return g_browser_process->devtools_manager();
720}
721
[email protected]ae6e9912011-07-27 01:18:28722net::NetLog* ChromeContentBrowserClient::GetNetLog() {
723 return g_browser_process->net_log();
724}
725
[email protected]3bc0b562011-08-24 23:51:04726speech_input::SpeechInputManager*
727 ChromeContentBrowserClient::GetSpeechInputManager() {
728 return speech_input::ChromeSpeechInputManager::GetInstance();
729}
730
[email protected]32538d92011-08-25 00:09:23731AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
732 return new ChromeAccessTokenStore();
733}
734
[email protected]dbae6b02011-06-29 23:51:41735bool ChromeContentBrowserClient::IsFastShutdownPossible() {
736 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
737 return !browser_command_line.HasSwitch(switches::kChromeFrame);
738}
739
[email protected]3d7474ff2011-07-27 17:47:37740WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
741 content::BrowserContext* browser_context, bool is_web_ui) {
742 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
743 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36744}
745
746void ChromeContentBrowserClient::UpdateInspectorSetting(
747 RenderViewHost* rvh, const std::string& key, const std::string& value) {
748 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37749 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36750}
751
752void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
753 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37754 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36755}
756
[email protected]b8148ac2011-07-13 22:03:25757void ChromeContentBrowserClient::BrowserURLHandlerCreated(
758 BrowserURLHandler* handler) {
759 // Add the default URL handlers.
760 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
761 BrowserURLHandler::null_handler());
762 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
763 &ExtensionWebUI::HandleChromeURLOverrideReverse);
764
765 // about:
766 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
767 BrowserURLHandler::null_handler());
768 // chrome: & friends.
769 handler->AddHandlerPair(&HandleWebUI,
770 BrowserURLHandler::null_handler());
771}
772
773void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37774 Profile* profile = Profile::FromBrowserContext(
775 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25776 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
777 BrowsingDataRemover::EVERYTHING,
778 base::Time());
779 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
780 // BrowsingDataRemover takes care of deleting itself when done.
781}
782
783void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37784 Profile* profile = Profile::FromBrowserContext(
785 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25786 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
787 BrowsingDataRemover::EVERYTHING,
788 base::Time());
[email protected]dceaa912011-09-06 17:17:23789 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:25790 remover->Remove(remove_mask);
791 // BrowsingDataRemover takes care of deleting itself when done.
792}
793
[email protected]e1d16eb92011-08-18 23:19:32794FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
795 return download_util::GetDefaultDownloadDirectory();
796}
797
[email protected]b80f68432011-05-02 17:22:30798#if defined(OS_LINUX)
799int ChromeContentBrowserClient::GetCrashSignalFD(
800 const std::string& process_type) {
801 if (process_type == switches::kRendererProcess)
802 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
803
[email protected]9dbfff12011-07-01 19:37:07804 if (process_type == switches::kExtensionProcess) {
805 ExtensionCrashHandlerHostLinux* crash_handler =
806 ExtensionCrashHandlerHostLinux::GetInstance();
807 return crash_handler->GetDeathSignalSocket();
808 }
809
[email protected]b80f68432011-05-02 17:22:30810 if (process_type == switches::kPluginProcess)
811 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
812
813 if (process_type == switches::kPpapiPluginProcess)
814 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
815
816 if (process_type == switches::kGpuProcess)
817 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
818
819 return -1;
820}
[email protected]9dbfff12011-07-01 19:37:07821#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30822
[email protected]4a65826d2011-08-25 16:04:01823#if defined(OS_WIN)
824const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
825 return chrome::kBrowserResourcesDll;
826}
827#endif
828
[email protected]37a72af2011-06-13 05:42:01829#if defined(USE_NSS)
830crypto::CryptoModuleBlockingPasswordDelegate*
831 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
832 const GURL& url) {
833 return browser::NewCryptoModuleBlockingDialogDelegate(
834 browser::kCryptoModulePasswordKeygen, url.host());
835}
836#endif
837
[email protected]d977f9c2011-03-14 16:10:26838} // namespace chrome