blob: 794dfa2099fa6aff9c11d38ab594f0c24ed7bb84 [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 =
[email protected]718eab62011-10-05 21:16:52270 extension_process_manager->IsExtensionProcess(process_host->id());
[email protected]2a5221b2011-09-27 23:07:31271 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]718eab62011-10-05 21:16:52299 if (process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30300 FilePath user_data_dir =
301 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
302 if (!user_data_dir.empty())
303 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
304#if defined(OS_CHROMEOS)
305 const std::string& login_profile =
306 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
307 if (!login_profile.empty())
308 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
309#endif
310
311 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
312
[email protected]3d7474ff2011-07-27 17:47:37313 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]718eab62011-10-05 21:16:52314
315 ExtensionProcessManager* extension_process_manager =
316 profile->GetExtensionProcessManager();
317 if (extension_process_manager->IsExtensionProcess(
318 process->id())) {
319 command_line->AppendSwitch(switches::kExtensionProcess);
320 }
321
[email protected]3d7474ff2011-07-27 17:47:37322 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30323 // Currently this pref is only registered if applied via a policy.
324 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
325 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
326 // Turn this policy into a command line switch.
327 command_line->AppendSwitch(switches::kDisable3DAPIs);
328 }
329
330 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46331 // in the Profile preferences or the browser process.
332 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
333 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30334 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46335 }
[email protected]4287a3d2011-06-13 23:56:51336
337 static const char* const kSwitchNames[] = {
338 switches::kAllowHTTPBackgroundPage,
339 switches::kAllowScriptingGallery,
340 switches::kAppsCheckoutURL,
341 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31342 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51343 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51344 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51345 switches::kDomAutomationController,
346 switches::kDumpHistogramsOnExit,
347 switches::kEnableClickToPlay,
348 switches::kEnableCrxlessWebApps,
349 switches::kEnableExperimentalExtensionApis,
350 switches::kEnableInBrowserThumbnailing,
351 switches::kEnableIPCFuzzing,
352 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24353 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51354 switches::kEnableResourceContentSettings,
355 switches::kEnableSearchProviderApiV2,
356 switches::kEnableWatchdog,
357 switches::kExperimentalSpellcheckerFeatures,
358 switches::kMemoryProfiling,
359 switches::kMessageLoopHistogrammer,
[email protected]2a6bb0b12011-10-05 19:18:04360 switches::kNoRunningInsecureContent,
[email protected]4287a3d2011-06-13 23:56:51361 switches::kPpapiFlashArgs,
362 switches::kPpapiFlashInProcess,
363 switches::kPpapiFlashPath,
364 switches::kPpapiFlashVersion,
365 switches::kProfilingAtStart,
366 switches::kProfilingFile,
367 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51368 switches::kSilentDumpOnDCHECK,
[email protected]6f08af82011-09-15 01:19:03369 switches::kEnableBenchmarking,
[email protected]4287a3d2011-06-13 23:56:51370 };
371
372 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
373 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17374 } else if (process_type == switches::kUtilityProcess) {
375 if (browser_command_line.HasSwitch(
376 switches::kEnableExperimentalExtensionApis)) {
377 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
378 }
[email protected]4287a3d2011-06-13 23:56:51379 } else if (process_type == switches::kPluginProcess) {
380 static const char* const kSwitchNames[] = {
381 #if defined(OS_CHROMEOS)
382 switches::kLoginProfile,
383 #endif
384 switches::kMemoryProfiling,
385 switches::kSilentDumpOnDCHECK,
386 switches::kUserDataDir,
387 };
388
389 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
390 arraysize(kSwitchNames));
391 } else if (process_type == switches::kZygoteProcess) {
392 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51393 switches::kUserDataDir, // Make logs go to the right file.
394 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
395 switches::kPpapiFlashInProcess,
396 switches::kPpapiFlashPath,
397 switches::kPpapiFlashVersion,
398 };
399
400 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
401 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30402 }
[email protected]6f08af82011-09-15 01:19:03403
404 // The command line switch kEnableBenchmarking needs to be specified along
405 // with the kEnableStatsTable switch to ensure that the stats table global
406 // is initialized correctly.
407 if (command_line->HasSwitch(switches::kEnableBenchmarking))
408 DCHECK(command_line->HasSwitch(switches::kEnableStatsTable));
[email protected]b80f68432011-05-02 17:22:30409}
410
411std::string ChromeContentBrowserClient::GetApplicationLocale() {
412 return g_browser_process->GetApplicationLocale();
413}
414
[email protected]b5cca982011-05-26 04:42:08415std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37416 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
417 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08418}
419
[email protected]ac55e292011-06-24 05:16:08420SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
421 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
422 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
423}
424
[email protected]a2176792011-05-08 19:30:49425bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09426 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19427 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09428 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
430 ProfileIOData* io_data =
431 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]efa55212011-05-13 16:19:38432 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]0a608842011-09-08 10:55:19433 GetCookieContentSetting(manifest_url, first_party, true);
[email protected]a2176792011-05-08 19:30:49434 DCHECK(setting != CONTENT_SETTING_DEFAULT);
435 return setting != CONTENT_SETTING_BLOCK;
436}
437
[email protected]ed24fad2011-05-10 22:44:01438bool ChromeContentBrowserClient::AllowGetCookie(
439 const GURL& url,
440 const GURL& first_party,
441 const net::CookieList& cookie_list,
442 const content::ResourceContext& context,
443 int render_process_id,
444 int render_view_id) {
445 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32446 ProfileIOData* io_data =
447 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09448 ContentSetting setting = io_data->GetHostContentSettingsMap()->
449 GetCookieContentSetting(url, first_party, false);
450 bool allow = setting == CONTENT_SETTING_ALLOW ||
451 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01452
[email protected]8093a542011-05-13 07:29:32453 BrowserThread::PostTask(
454 BrowserThread::UI, FROM_HERE,
455 NewRunnableFunction(
456 &TabSpecificContentSettings::CookiesRead,
457 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01458 return allow;
459}
460
461bool ChromeContentBrowserClient::AllowSetCookie(
462 const GURL& url,
463 const GURL& first_party,
464 const std::string& cookie_line,
465 const content::ResourceContext& context,
466 int render_process_id,
467 int render_view_id,
468 net::CookieOptions* options) {
469 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32470 ProfileIOData* io_data =
471 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09472 ContentSetting setting = io_data->GetHostContentSettingsMap()->
473 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01474
[email protected]5b52ad42011-05-26 14:26:09475 if (setting == CONTENT_SETTING_SESSION_ONLY)
476 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01477
[email protected]5b52ad42011-05-26 14:26:09478 bool allow = setting == CONTENT_SETTING_ALLOW ||
479 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01480
[email protected]8093a542011-05-13 07:29:32481 BrowserThread::PostTask(
482 BrowserThread::UI, FROM_HERE,
483 NewRunnableFunction(
484 &TabSpecificContentSettings::CookieChanged,
485 render_process_id, render_view_id, url, cookie_line, *options,
486 !allow));
[email protected]ed24fad2011-05-10 22:44:01487 return allow;
488}
489
[email protected]d5a19162011-06-30 18:51:54490bool ChromeContentBrowserClient::AllowSaveLocalState(
491 const content::ResourceContext& context) {
492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
493 ProfileIOData* io_data =
494 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
495 return !io_data->clear_local_state_on_exit()->GetValue();
496}
497
[email protected]6133f922011-07-01 21:34:34498net::URLRequestContext*
499ChromeContentBrowserClient::OverrideRequestContextForURL(
500 const GURL& url, const content::ResourceContext& context) {
501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
502 if (url.SchemeIs(chrome::kExtensionScheme)) {
503 ProfileIOData* io_data =
504 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
505 return io_data->extensions_request_context();
506 }
507
508 return NULL;
509}
510
[email protected]317f96c92011-05-31 06:53:41511QuotaPermissionContext*
512ChromeContentBrowserClient::CreateQuotaPermissionContext() {
513 return new ChromeQuotaPermissionContext();
514}
515
[email protected]a0ce3282011-08-19 20:49:52516void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42517 // On Mac, this call needs to be done on the UI thread. On other platforms,
518 // do it on the FILE thread so we don't slow down UI.
519#if defined(OS_MACOSX)
520 platform_util::OpenItem(path);
521#else
522 BrowserThread::PostTask(
523 BrowserThread::FILE, FROM_HERE,
524 NewRunnableFunction(&platform_util::OpenItem, path));
525#endif
526}
527
[email protected]a0ce3282011-08-19 20:49:52528void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
529#if defined(OS_MACOSX)
530 // Mac needs to run this operation on the UI thread.
531 platform_util::ShowItemInFolder(path);
532#else
533 BrowserThread::PostTask(
534 BrowserThread::FILE, FROM_HERE,
535 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
536#endif
537}
538
[email protected]848dd042011-06-04 18:24:03539void ChromeContentBrowserClient::AllowCertificateError(
540 SSLCertErrorHandler* handler,
541 bool overridable,
[email protected]8a27abf2011-09-30 21:59:58542 const base::Callback<void(SSLCertErrorHandler*, bool)>& callback) {
[email protected]f9034cf2011-07-21 12:43:41543 // If the tab is being prerendered, cancel the prerender and the request.
544 TabContents* tab = tab_util::GetTabContentsByID(
545 handler->render_process_host_id(),
546 handler->tab_contents_id());
547 if (!tab) {
548 NOTREACHED();
549 return;
550 }
551 prerender::PrerenderManager* prerender_manager =
[email protected]3085c502011-10-05 17:50:50552 prerender::PrerenderManagerFactory::GetForProfile(
553 Profile::FromBrowserContext(tab->browser_context()));
[email protected]f9034cf2011-07-21 12:43:41554 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
555 if (prerender_manager->prerender_tracker()->TryCancel(
556 handler->render_process_host_id(),
557 handler->tab_contents_id(),
558 prerender::FINAL_STATUS_SSL_ERROR)) {
559 handler->CancelRequest();
560 return;
561 }
562 }
563
564 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03565 SSLBlockingPage* blocking_page = new SSLBlockingPage(
566 handler, overridable, callback);
567 blocking_page->Show();
568}
569
[email protected]c99c442e2011-08-24 11:37:30570void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45571 int render_process_id,
572 int render_view_id,
573 SSLClientAuthHandler* handler) {
574 TabContents* tab = tab_util::GetTabContentsByID(
575 render_process_id, render_view_id);
576 if (!tab) {
577 NOTREACHED();
578 return;
579 }
580
581 TabContentsWrapper* wrapper =
582 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30583 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45584}
585
586void ChromeContentBrowserClient::AddNewCertificate(
587 net::URLRequest* request,
588 net::X509Certificate* cert,
589 int render_process_id,
590 int render_view_id) {
591 // The handler will run the UI and delete itself when it's finished.
592 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
593}
594
[email protected]941623e2011-06-07 23:06:04595void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
596 const GURL& source_origin,
597 int callback_context,
598 int render_process_id,
599 int render_view_id) {
600 RenderViewHost* rvh = RenderViewHost::FromID(
601 render_process_id, render_view_id);
602 if (!rvh) {
603 NOTREACHED();
604 return;
605 }
606
607 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37608 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04609 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37610 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04611 service->RequestPermission(
612 source_origin, render_process_id, render_view_id, callback_context,
613 tab_util::GetTabContentsByID(render_process_id, render_view_id));
614}
615
616WebKit::WebNotificationPresenter::Permission
617 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
618 const GURL& source_url,
619 const content::ResourceContext& context) {
620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
621 ProfileIOData* io_data =
622 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
623
624 const Extension* extension =
625 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
626 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52627 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04628 return WebKit::WebNotificationPresenter::PermissionAllowed;
629 }
630
631 // Fall back to the regular notification preferences, which works on an
632 // origin basis.
633 return io_data->GetNotificationService() ?
634 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
635 WebKit::WebNotificationPresenter::PermissionNotAllowed;
636}
637
638void ChromeContentBrowserClient::ShowDesktopNotification(
639 const DesktopNotificationHostMsg_Show_Params& params,
640 int render_process_id,
641 int render_view_id,
642 bool worker) {
643 RenderViewHost* rvh = RenderViewHost::FromID(
644 render_process_id, render_view_id);
645 if (!rvh) {
646 NOTREACHED();
647 return;
648 }
649
650 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37651 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04652 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37653 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04654 service->ShowDesktopNotification(
655 params, render_process_id, render_view_id,
656 worker ? DesktopNotificationService::WorkerNotification :
657 DesktopNotificationService::PageNotification);
658}
659
660void ChromeContentBrowserClient::CancelDesktopNotification(
661 int render_process_id,
662 int render_view_id,
663 int notification_id) {
664 RenderViewHost* rvh = RenderViewHost::FromID(
665 render_process_id, render_view_id);
666 if (!rvh) {
667 NOTREACHED();
668 return;
669 }
670
671 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37672 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04673 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37674 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04675 service->CancelDesktopNotification(
676 render_process_id, render_view_id, notification_id);
677}
678
[email protected]9f3fba52011-06-08 20:37:19679bool ChromeContentBrowserClient::CanCreateWindow(
680 const GURL& source_url,
681 WindowContainerType container_type,
682 const content::ResourceContext& context) {
683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
684 // If the opener is trying to create a background window but doesn't have
685 // the appropriate permission, fail the attempt.
686 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
687 ProfileIOData* io_data =
688 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
689 const Extension* extension =
690 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
691 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52692 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19693 }
694 return true;
695}
696
697std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
698 const GURL& url, const content::ResourceContext& context) {
699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
700 // Check if it's an extension-created worker, in which case we want to use
701 // the name of the extension.
702 ProfileIOData* io_data =
703 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
704 const Extension* extension =
705 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
706 return extension ? extension->name() : std::string();
707}
708
[email protected]3cb054e62011-06-13 05:21:17709ResourceDispatcherHost*
710 ChromeContentBrowserClient::GetResourceDispatcherHost() {
711 return g_browser_process->resource_dispatcher_host();
712}
713
714ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
715 return g_browser_process->clipboard();
716}
717
[email protected]8f6a3b852011-07-19 16:48:56718MHTMLGenerationManager*
719 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
720 return g_browser_process->mhtml_generation_manager();
721}
722
[email protected]dce502762011-07-20 08:53:49723DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
724 return g_browser_process->devtools_manager();
725}
726
[email protected]ae6e9912011-07-27 01:18:28727net::NetLog* ChromeContentBrowserClient::GetNetLog() {
728 return g_browser_process->net_log();
729}
730
[email protected]3bc0b562011-08-24 23:51:04731speech_input::SpeechInputManager*
732 ChromeContentBrowserClient::GetSpeechInputManager() {
733 return speech_input::ChromeSpeechInputManager::GetInstance();
734}
735
[email protected]32538d92011-08-25 00:09:23736AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
737 return new ChromeAccessTokenStore();
738}
739
[email protected]dbae6b02011-06-29 23:51:41740bool ChromeContentBrowserClient::IsFastShutdownPossible() {
741 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
742 return !browser_command_line.HasSwitch(switches::kChromeFrame);
743}
744
[email protected]3d7474ff2011-07-27 17:47:37745WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
746 content::BrowserContext* browser_context, bool is_web_ui) {
747 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
748 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36749}
750
751void ChromeContentBrowserClient::UpdateInspectorSetting(
752 RenderViewHost* rvh, const std::string& key, const std::string& value) {
753 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37754 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36755}
756
757void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
758 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37759 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36760}
761
[email protected]b8148ac2011-07-13 22:03:25762void ChromeContentBrowserClient::BrowserURLHandlerCreated(
763 BrowserURLHandler* handler) {
764 // Add the default URL handlers.
765 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
766 BrowserURLHandler::null_handler());
767 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
768 &ExtensionWebUI::HandleChromeURLOverrideReverse);
769
770 // about:
771 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
772 BrowserURLHandler::null_handler());
773 // chrome: & friends.
774 handler->AddHandlerPair(&HandleWebUI,
775 BrowserURLHandler::null_handler());
776}
777
778void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37779 Profile* profile = Profile::FromBrowserContext(
780 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25781 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
782 BrowsingDataRemover::EVERYTHING,
783 base::Time());
784 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
785 // BrowsingDataRemover takes care of deleting itself when done.
786}
787
788void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37789 Profile* profile = Profile::FromBrowserContext(
790 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25791 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
792 BrowsingDataRemover::EVERYTHING,
793 base::Time());
[email protected]dceaa912011-09-06 17:17:23794 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:25795 remover->Remove(remove_mask);
796 // BrowsingDataRemover takes care of deleting itself when done.
797}
798
[email protected]e1d16eb92011-08-18 23:19:32799FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
800 return download_util::GetDefaultDownloadDirectory();
801}
802
[email protected]b80f68432011-05-02 17:22:30803#if defined(OS_LINUX)
804int ChromeContentBrowserClient::GetCrashSignalFD(
[email protected]718eab62011-10-05 21:16:52805 const CommandLine& command_line) {
806 if (command_line.HasSwitch(switches::kExtensionProcess)) {
[email protected]9dbfff12011-07-01 19:37:07807 ExtensionCrashHandlerHostLinux* crash_handler =
808 ExtensionCrashHandlerHostLinux::GetInstance();
809 return crash_handler->GetDeathSignalSocket();
810 }
811
[email protected]718eab62011-10-05 21:16:52812 std::string process_type =
813 command_line.GetSwitchValueASCII(switches::kProcessType);
814
815 if (process_type == switches::kRendererProcess)
816 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
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