blob: ce7a52cb902183ba511b328fdd061da160d8c336 [file] [log] [blame]
[email protected]d977f9c2011-03-14 16:10:261// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chrome_content_browser_client.h"
6
[email protected]b80f68432011-05-02 17:22:307#include "base/command_line.h"
8#include "chrome/app/breakpad_mac.h"
[email protected]b8148ac2011-07-13 22:03:259#include "chrome/browser/browser_about_handler.h"
[email protected]b80f68432011-05-02 17:22:3010#include "chrome/browser/browser_process.h"
[email protected]3b8f7e32011-07-13 11:52:2311#include "chrome/browser/browsing_data_remover.h"
[email protected]763ec4ca2011-04-29 15:48:1212#include "chrome/browser/character_encoding.h"
[email protected]97e6c4c2011-05-18 16:08:5113#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4114#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]5327dfb2011-05-03 17:50:3615#include "chrome/browser/chrome_worker_message_filter.h"
[email protected]a2176792011-05-08 19:30:4916#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3217#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]e1d16eb92011-08-18 23:19:3218#include "chrome/browser/download/download_util.h"
[email protected]941623e2011-06-07 23:06:0419#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1020#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2621#include "chrome/browser/extensions/extension_service.h"
[email protected]b8148ac2011-07-13 22:03:2522#include "chrome/browser/extensions/extension_web_ui.h"
[email protected]32538d92011-08-25 00:09:2323#include "chrome/browser/geolocation/chrome_access_token_store.h"
[email protected]763ec4ca2011-04-29 15:48:1224#include "chrome/browser/google/google_util.h"
[email protected]ae6e9912011-07-27 01:18:2825#include "chrome/browser/net/chrome_net_log.h"
[email protected]941623e2011-06-07 23:06:0426#include "chrome/browser/notifications/desktop_notification_service.h"
27#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4228#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1229#include "chrome/browser/prefs/pref_service.h"
[email protected]f9034cf2011-07-21 12:43:4130#include "chrome/browser/prerender/prerender_manager.h"
31#include "chrome/browser/prerender/prerender_tracker.h"
[email protected]05fcf982011-04-19 00:44:1432#include "chrome/browser/printing/printing_message_filter.h"
33#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3234#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1435#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3336#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]d4cff272011-05-02 15:46:0137#include "chrome/browser/renderer_host/text_input_client_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1438#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
[email protected]3bc0b562011-08-24 23:51:0439#include "chrome/browser/speech/chrome_speech_input_manager.h"
[email protected]8ec71262011-07-28 08:12:4640#include "chrome/browser/spellchecker/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4541#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0342#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]181a95ee2011-07-12 19:26:3643#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
[email protected]8ec26472011-06-06 16:52:4544#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
45#include "chrome/browser/tab_contents/tab_util.h"
46#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5647#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3048#include "chrome/common/child_process_logging.h"
[email protected]4a65826d2011-08-25 16:04:0149#include "chrome/common/chrome_constants.h"
[email protected]b80f68432011-05-02 17:22:3050#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0451#include "chrome/common/extensions/extension.h"
[email protected]f1933792011-06-14 00:49:3452#include "chrome/common/logging_chrome.h"
[email protected]763ec4ca2011-04-29 15:48:1253#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3854#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0955#include "chrome/common/url_constants.h"
[email protected]b8148ac2011-07-13 22:03:2556#include "content/browser/browser_url_handler.h"
[email protected]c5dbef02011-05-13 05:06:0957#include "content/browser/browsing_instance.h"
[email protected]97e6c4c2011-05-18 16:08:5158#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1459#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2660#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4961#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0962#include "content/browser/site_instance.h"
[email protected]f9034cf2011-07-21 12:43:4163#include "content/browser/ssl/ssl_cert_error_handler.h"
[email protected]8ec26472011-06-06 16:52:4564#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1265#include "content/browser/tab_contents/tab_contents.h"
[email protected]74313b42011-08-24 16:51:3266#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]5327dfb2011-05-03 17:50:3667#include "content/browser/worker_host/worker_process_host.h"
[email protected]941623e2011-06-07 23:06:0468#include "content/common/desktop_notification_messages.h"
[email protected]29b25d092011-06-29 20:57:3469#include "grit/ui_resources.h"
[email protected]ed24fad2011-05-10 22:44:0170#include "net/base/cookie_monster.h"
71#include "net/base/cookie_options.h"
[email protected]ac55e292011-06-24 05:16:0872#include "ui/base/resource/resource_bundle.h"
[email protected]d977f9c2011-03-14 16:10:2673
[email protected]b80f68432011-05-02 17:22:3074#if defined(OS_LINUX)
75#include "base/linux_util.h"
[email protected]e6b5bc22011-09-08 22:01:5676#include "chrome/browser/chrome_browser_main_gtk.h"
[email protected]b80f68432011-05-02 17:22:3077#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:4378#endif
[email protected]b80f68432011-05-02 17:22:3079
[email protected]bb6dcbb2011-08-24 17:05:2080#if defined(TOUCH_UI)
81#include "chrome/browser/ui/views/tab_contents/tab_contents_view_touch.h"
82#elif defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:3283#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
84#elif defined(OS_LINUX)
85#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
86#elif defined(OS_MACOSX)
87#include "chrome/browser/tab_contents/tab_contents_view_mac.h"
[email protected]e6b5bc22011-09-08 22:01:5688#include "chrome/browser/chrome_browser_main_mac.h"
[email protected]f967b722011-09-07 00:58:0489#endif
90
91#if defined(OS_WIN)
[email protected]e6b5bc22011-09-08 22:01:5692#include "chrome/browser/chrome_browser_main_win.h"
[email protected]f967b722011-09-07 00:58:0493#elif defined(OS_CHROMEOS)
[email protected]e6b5bc22011-09-08 22:01:5694#include "chrome/browser/chromeos/chrome_browser_main_chromeos.h"
[email protected]74313b42011-08-24 16:51:3295#endif
96
[email protected]37a72af2011-06-13 05:42:0197#if defined(USE_NSS)
98#include "chrome/browser/ui/crypto_module_password_dialog.h"
99#endif
100
[email protected]c5dbef02011-05-13 05:06:09101namespace {
102
[email protected]b8148ac2011-07-13 22:03:25103// Handles rewriting Web UI URLs.
[email protected]3d7474ff2011-07-27 17:47:37104static bool HandleWebUI(GURL* url, content::BrowserContext* browser_context) {
105 if (!ChromeWebUIFactory::GetInstance()->UseWebUIForURL(browser_context, *url))
[email protected]b8148ac2011-07-13 22:03:25106 return false;
107
108 // Special case the new tab page. In older versions of Chrome, the new tab
109 // page was hosted at chrome-internal:<blah>. This might be in people's saved
110 // sessions or bookmarks, so we say any URL with that scheme triggers the new
111 // tab page.
112 if (url->SchemeIs(chrome::kChromeInternalScheme)) {
113 // Rewrite it with the proper new tab URL.
114 *url = GURL(chrome::kChromeUINewTabURL);
115 }
116
117 return true;
118}
119
[email protected]9dbfff12011-07-01 19:37:07120} // namespace
[email protected]c5dbef02011-05-13 05:06:09121
[email protected]d977f9c2011-03-14 16:10:26122namespace chrome {
123
[email protected]f967b722011-09-07 00:58:04124content::BrowserMainParts* ChromeContentBrowserClient::CreateBrowserMainParts(
125 const MainFunctionParams& parameters) {
126#if defined(OS_WIN)
[email protected]e6b5bc22011-09-08 22:01:56127 return new ChromeBrowserMainPartsWin(parameters);
[email protected]f967b722011-09-07 00:58:04128#elif defined(OS_MACOSX)
[email protected]46c83b62011-09-08 22:09:04129 return new ChromeBrowserMainPartsMac(parameters);
[email protected]f967b722011-09-07 00:58:04130#elif defined(OS_CHROMEOS)
[email protected]46c83b62011-09-08 22:09:04131 return new ChromeBrowserMainPartsChromeos(parameters);
[email protected]f967b722011-09-07 00:58:04132#elif defined(OS_LINUX)
[email protected]e6b5bc22011-09-08 22:01:56133 return new ChromeBrowserMainPartsGtk(parameters);
[email protected]f967b722011-09-07 00:58:04134#else
135 return NULL;
136#endif
137}
138
[email protected]74313b42011-08-24 16:51:32139TabContentsView* ChromeContentBrowserClient::CreateTabContentsView(
140 TabContents* tab_contents) {
[email protected]bb6dcbb2011-08-24 17:05:20141#if defined(TOUCH_UI)
142 return new TabContentsViewTouch(tab_contents);
143#elif defined(TOOLKIT_VIEWS)
[email protected]74313b42011-08-24 16:51:32144 return new TabContentsViewViews(tab_contents);
145#elif defined(OS_LINUX)
146 return new TabContentsViewGtk(tab_contents);
147#elif defined(OS_MACOSX)
148 return tab_contents_view_mac::CreateTabContentsView(tab_contents);
[email protected]74313b42011-08-24 16:51:32149#else
150#error Need to create your platform TabContentsView here.
151#endif
152}
153
[email protected]f364d1392011-04-08 21:03:10154void ChromeContentBrowserClient::RenderViewHostCreated(
155 RenderViewHost* render_view_host) {
[email protected]67372ecf2011-09-10 01:30:46156
157 SiteInstance* site_instance = render_view_host->site_instance();
158 Profile* profile = Profile::FromBrowserContext(
159 site_instance->browsing_instance()->browser_context());
160
161 new ChromeRenderViewHostObserver(render_view_host,
162 profile->GetNetworkPredictor());
[email protected]f364d1392011-04-08 21:03:10163 new ExtensionMessageHandler(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26164}
165
[email protected]05fcf982011-04-19 00:44:14166void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
167 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02168 int id = host->id();
[email protected]3d7474ff2011-07-27 17:47:37169 Profile* profile = Profile::FromBrowserContext(host->browser_context());
[email protected]05fcf982011-04-19 00:44:14170 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02171 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14172 host->channel()->AddFilter(new PrintingMessageFilter());
173 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02174 new SearchProviderInstallStateMessageFilter(id, profile));
175 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]d4cff272011-05-02 15:46:01176#if defined(OS_MACOSX)
177 host->channel()->AddFilter(new TextInputClientMessageFilter(host->id()));
178#endif
[email protected]3e69bc82011-05-26 23:22:38179
[email protected]2ccf45c2011-08-19 23:35:50180 host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
181 profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14182}
183
[email protected]97e6c4c2011-05-18 16:08:51184void ChromeContentBrowserClient::PluginProcessHostCreated(
185 PluginProcessHost* host) {
186 host->AddFilter(new ChromePluginMessageFilter(host));
187}
188
[email protected]5327dfb2011-05-03 17:50:36189void ChromeContentBrowserClient::WorkerProcessHostCreated(
190 WorkerProcessHost* host) {
191 host->AddFilter(new ChromeWorkerMessageFilter(host));
192}
193
[email protected]1fd1a502011-03-30 16:55:56194content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
195 return ChromeWebUIFactory::GetInstance();
196}
197
[email protected]3d7474ff2011-07-27 17:47:37198GURL ChromeContentBrowserClient::GetEffectiveURL(
199 content::BrowserContext* browser_context, const GURL& url) {
200 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]36fb2c7c2011-04-04 15:49:08201 // Get the effective URL for the given actual URL. If the URL is part of an
202 // installed app, the effective URL is an extension URL with the ID of that
203 // extension as the host. This has the effect of grouping apps together in
204 // a common SiteInstance.
205 if (!profile || !profile->GetExtensionService())
206 return url;
207
208 const Extension* extension =
209 profile->GetExtensionService()->GetExtensionByWebExtent(url);
210 if (!extension)
211 return url;
212
213 // If the URL is part of an extension's web extent, convert it to an
214 // extension URL.
215 return extension->GetResourceURL(url.path());
216}
217
[email protected]056ad2a2011-07-12 02:13:55218bool ChromeContentBrowserClient::ShouldUseProcessPerSite(
[email protected]3d7474ff2011-07-27 17:47:37219 content::BrowserContext* browser_context, const GURL& effective_url) {
[email protected]056ad2a2011-07-12 02:13:55220 // Non-extension URLs should generally use process-per-site-instance.
221 // Because we expect to use the effective URL, hosted apps URLs should have
222 // an extension scheme by now.
223 if (!effective_url.SchemeIs(chrome::kExtensionScheme))
224 return false;
225
[email protected]3d7474ff2011-07-27 17:47:37226 Profile* profile = Profile::FromBrowserContext(browser_context);
[email protected]056ad2a2011-07-12 02:13:55227 if (!profile || !profile->GetExtensionService())
228 return false;
229
230 const Extension* extension =
231 profile->GetExtensionService()->GetExtensionByURL(effective_url);
232 if (!extension)
233 return false;
234
235 // If the URL is part of a hosted app that does not have the background
236 // permission, we want to give each instance its own process to improve
237 // responsiveness.
238 if (extension->GetType() == Extension::TYPE_HOSTED_APP &&
239 !extension->HasAPIPermission(ExtensionAPIPermission::kBackground))
240 return false;
241
242 // Hosted apps that have the background permission must use process per site,
243 // since all instances can make synchronous calls to the background window.
244 // Other extensions should use process per site as well.
245 return true;
246}
247
[email protected]0f012df82011-05-19 14:15:29248bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03249 return url == GURL(chrome::kChromeUICrashURL) ||
250 url == GURL(chrome::kChromeUIKillURL) ||
251 url == GURL(chrome::kChromeUIHangURL) ||
252 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29253}
254
[email protected]763ec4ca2011-04-29 15:48:12255std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
256 const std::string& alias_name) {
257 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
258}
259
[email protected]b80f68432011-05-02 17:22:30260void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
261 CommandLine* command_line, int child_process_id) {
262#if defined(USE_LINUX_BREAKPAD)
263 if (IsCrashReporterEnabled()) {
264 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
265 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
266 }
267#elif defined(OS_MACOSX)
268 if (IsCrashReporterEnabled()) {
269 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
270 child_process_logging::GetClientId());
271 }
272#endif // OS_MACOSX
273
[email protected]f1933792011-06-14 00:49:34274 if (logging::DialogsAreSuppressed())
275 command_line->AppendSwitch(switches::kNoErrorDialogs);
276
[email protected]b80f68432011-05-02 17:22:30277 std::string process_type =
278 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17279 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30280 if (process_type == switches::kExtensionProcess ||
281 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30282 FilePath user_data_dir =
283 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
284 if (!user_data_dir.empty())
285 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
286#if defined(OS_CHROMEOS)
287 const std::string& login_profile =
288 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
289 if (!login_profile.empty())
290 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
291#endif
292
293 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
294
[email protected]3d7474ff2011-07-27 17:47:37295 Profile* profile = Profile::FromBrowserContext(process->browser_context());
296 PrefService* prefs = profile->GetPrefs();
[email protected]b80f68432011-05-02 17:22:30297 // Currently this pref is only registered if applied via a policy.
298 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
299 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
300 // Turn this policy into a command line switch.
301 command_line->AppendSwitch(switches::kDisable3DAPIs);
302 }
303
304 // Disable client-side phishing detection in the renderer if it is disabled
[email protected]8c40da62011-07-13 22:58:46305 // in the Profile preferences or the browser process.
306 if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) ||
307 !g_browser_process->safe_browsing_detection_service()) {
[email protected]b80f68432011-05-02 17:22:30308 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]8c40da62011-07-13 22:58:46309 }
[email protected]4287a3d2011-06-13 23:56:51310
311 static const char* const kSwitchNames[] = {
312 switches::kAllowHTTPBackgroundPage,
313 switches::kAllowScriptingGallery,
314 switches::kAppsCheckoutURL,
315 switches::kAppsGalleryURL,
[email protected]be9d9c82011-07-13 04:17:31316 switches::kCloudPrintServiceURL,
[email protected]4287a3d2011-06-13 23:56:51317 switches::kDebugPrint,
[email protected]4287a3d2011-06-13 23:56:51318 switches::kDisablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51319 switches::kDomAutomationController,
320 switches::kDumpHistogramsOnExit,
321 switches::kEnableClickToPlay,
322 switches::kEnableCrxlessWebApps,
323 switches::kEnableExperimentalExtensionApis,
324 switches::kEnableInBrowserThumbnailing,
[email protected]d0cf438c2011-08-18 03:08:52325 switches::kEnableInlineWebstoreInstall,
[email protected]4287a3d2011-06-13 23:56:51326 switches::kEnableIPCFuzzing,
327 switches::kEnableNaCl,
[email protected]5714ee32011-08-18 01:51:24328 switches::kEnablePrintPreview,
[email protected]4287a3d2011-06-13 23:56:51329 switches::kEnableResourceContentSettings,
330 switches::kEnableSearchProviderApiV2,
331 switches::kEnableWatchdog,
332 switches::kExperimentalSpellcheckerFeatures,
333 switches::kMemoryProfiling,
334 switches::kMessageLoopHistogrammer,
335 switches::kPpapiFlashArgs,
336 switches::kPpapiFlashInProcess,
337 switches::kPpapiFlashPath,
338 switches::kPpapiFlashVersion,
339 switches::kProfilingAtStart,
340 switches::kProfilingFile,
341 switches::kProfilingFlush,
[email protected]4287a3d2011-06-13 23:56:51342 switches::kSilentDumpOnDCHECK,
343 };
344
345 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
346 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17347 } else if (process_type == switches::kUtilityProcess) {
348 if (browser_command_line.HasSwitch(
349 switches::kEnableExperimentalExtensionApis)) {
350 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
351 }
[email protected]4287a3d2011-06-13 23:56:51352 } else if (process_type == switches::kPluginProcess) {
353 static const char* const kSwitchNames[] = {
354 #if defined(OS_CHROMEOS)
355 switches::kLoginProfile,
356 #endif
357 switches::kMemoryProfiling,
358 switches::kSilentDumpOnDCHECK,
359 switches::kUserDataDir,
360 };
361
362 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
363 arraysize(kSwitchNames));
364 } else if (process_type == switches::kZygoteProcess) {
365 static const char* const kSwitchNames[] = {
[email protected]4287a3d2011-06-13 23:56:51366 switches::kUserDataDir, // Make logs go to the right file.
367 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
368 switches::kPpapiFlashInProcess,
369 switches::kPpapiFlashPath,
370 switches::kPpapiFlashVersion,
371 };
372
373 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
374 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30375 }
376}
377
378std::string ChromeContentBrowserClient::GetApplicationLocale() {
379 return g_browser_process->GetApplicationLocale();
380}
381
[email protected]b5cca982011-05-26 04:42:08382std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
[email protected]3d7474ff2011-07-27 17:47:37383 Profile* profile = Profile::FromBrowserContext(tab->browser_context());
384 return profile->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]b5cca982011-05-26 04:42:08385}
386
[email protected]ac55e292011-06-24 05:16:08387SkBitmap* ChromeContentBrowserClient::GetDefaultFavicon() {
388 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
389 return rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
390}
391
[email protected]a2176792011-05-08 19:30:49392bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09393 const GURL& manifest_url,
[email protected]0a608842011-09-08 10:55:19394 const GURL& first_party,
[email protected]5b52ad42011-05-26 14:26:09395 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
397 ProfileIOData* io_data =
398 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]efa55212011-05-13 16:19:38399 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]0a608842011-09-08 10:55:19400 GetCookieContentSetting(manifest_url, first_party, true);
[email protected]a2176792011-05-08 19:30:49401 DCHECK(setting != CONTENT_SETTING_DEFAULT);
402 return setting != CONTENT_SETTING_BLOCK;
403}
404
[email protected]ed24fad2011-05-10 22:44:01405bool ChromeContentBrowserClient::AllowGetCookie(
406 const GURL& url,
407 const GURL& first_party,
408 const net::CookieList& cookie_list,
409 const content::ResourceContext& context,
410 int render_process_id,
411 int render_view_id) {
412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32413 ProfileIOData* io_data =
414 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09415 ContentSetting setting = io_data->GetHostContentSettingsMap()->
416 GetCookieContentSetting(url, first_party, false);
417 bool allow = setting == CONTENT_SETTING_ALLOW ||
418 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01419
[email protected]8093a542011-05-13 07:29:32420 BrowserThread::PostTask(
421 BrowserThread::UI, FROM_HERE,
422 NewRunnableFunction(
423 &TabSpecificContentSettings::CookiesRead,
424 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01425 return allow;
426}
427
428bool ChromeContentBrowserClient::AllowSetCookie(
429 const GURL& url,
430 const GURL& first_party,
431 const std::string& cookie_line,
432 const content::ResourceContext& context,
433 int render_process_id,
434 int render_view_id,
435 net::CookieOptions* options) {
436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32437 ProfileIOData* io_data =
438 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09439 ContentSetting setting = io_data->GetHostContentSettingsMap()->
440 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01441
[email protected]5b52ad42011-05-26 14:26:09442 if (setting == CONTENT_SETTING_SESSION_ONLY)
443 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01444
[email protected]5b52ad42011-05-26 14:26:09445 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::CookieChanged,
452 render_process_id, render_view_id, url, cookie_line, *options,
453 !allow));
[email protected]ed24fad2011-05-10 22:44:01454 return allow;
455}
456
[email protected]d5a19162011-06-30 18:51:54457bool ChromeContentBrowserClient::AllowSaveLocalState(
458 const content::ResourceContext& context) {
459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
460 ProfileIOData* io_data =
461 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
462 return !io_data->clear_local_state_on_exit()->GetValue();
463}
464
[email protected]6133f922011-07-01 21:34:34465net::URLRequestContext*
466ChromeContentBrowserClient::OverrideRequestContextForURL(
467 const GURL& url, const content::ResourceContext& context) {
468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
469 if (url.SchemeIs(chrome::kExtensionScheme)) {
470 ProfileIOData* io_data =
471 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
472 return io_data->extensions_request_context();
473 }
474
475 return NULL;
476}
477
[email protected]317f96c92011-05-31 06:53:41478QuotaPermissionContext*
479ChromeContentBrowserClient::CreateQuotaPermissionContext() {
480 return new ChromeQuotaPermissionContext();
481}
482
[email protected]a0ce3282011-08-19 20:49:52483void ChromeContentBrowserClient::OpenItem(const FilePath& path) {
[email protected]0609b17f2011-05-31 20:13:42484 // On Mac, this call needs to be done on the UI thread. On other platforms,
485 // do it on the FILE thread so we don't slow down UI.
486#if defined(OS_MACOSX)
487 platform_util::OpenItem(path);
488#else
489 BrowserThread::PostTask(
490 BrowserThread::FILE, FROM_HERE,
491 NewRunnableFunction(&platform_util::OpenItem, path));
492#endif
493}
494
[email protected]a0ce3282011-08-19 20:49:52495void ChromeContentBrowserClient::ShowItemInFolder(const FilePath& path) {
496#if defined(OS_MACOSX)
497 // Mac needs to run this operation on the UI thread.
498 platform_util::ShowItemInFolder(path);
499#else
500 BrowserThread::PostTask(
501 BrowserThread::FILE, FROM_HERE,
502 NewRunnableFunction(&platform_util::ShowItemInFolder, path));
503#endif
504}
505
[email protected]848dd042011-06-04 18:24:03506void ChromeContentBrowserClient::AllowCertificateError(
507 SSLCertErrorHandler* handler,
508 bool overridable,
509 Callback2<SSLCertErrorHandler*, bool>::Type* callback) {
[email protected]f9034cf2011-07-21 12:43:41510 // If the tab is being prerendered, cancel the prerender and the request.
511 TabContents* tab = tab_util::GetTabContentsByID(
512 handler->render_process_host_id(),
513 handler->tab_contents_id());
514 if (!tab) {
515 NOTREACHED();
516 return;
517 }
518 prerender::PrerenderManager* prerender_manager =
[email protected]ada01b92011-09-07 21:01:39519 Profile::FromBrowserContext(tab->browser_context())->
520 GetPrerenderManager();
[email protected]f9034cf2011-07-21 12:43:41521 if (prerender_manager && prerender_manager->IsTabContentsPrerendering(tab)) {
522 if (prerender_manager->prerender_tracker()->TryCancel(
523 handler->render_process_host_id(),
524 handler->tab_contents_id(),
525 prerender::FINAL_STATUS_SSL_ERROR)) {
526 handler->CancelRequest();
527 return;
528 }
529 }
530
531 // Otherwise, display an SSL blocking page.
[email protected]848dd042011-06-04 18:24:03532 SSLBlockingPage* blocking_page = new SSLBlockingPage(
533 handler, overridable, callback);
534 blocking_page->Show();
535}
536
[email protected]c99c442e2011-08-24 11:37:30537void ChromeContentBrowserClient::SelectClientCertificate(
[email protected]8ec26472011-06-06 16:52:45538 int render_process_id,
539 int render_view_id,
540 SSLClientAuthHandler* handler) {
541 TabContents* tab = tab_util::GetTabContentsByID(
542 render_process_id, render_view_id);
543 if (!tab) {
544 NOTREACHED();
545 return;
546 }
547
548 TabContentsWrapper* wrapper =
549 TabContentsWrapper::GetCurrentWrapperForContents(tab);
[email protected]c99c442e2011-08-24 11:37:30550 wrapper->ssl_helper()->SelectClientCertificate(handler);
[email protected]8ec26472011-06-06 16:52:45551}
552
553void ChromeContentBrowserClient::AddNewCertificate(
554 net::URLRequest* request,
555 net::X509Certificate* cert,
556 int render_process_id,
557 int render_view_id) {
558 // The handler will run the UI and delete itself when it's finished.
559 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
560}
561
[email protected]941623e2011-06-07 23:06:04562void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
563 const GURL& source_origin,
564 int callback_context,
565 int render_process_id,
566 int render_view_id) {
567 RenderViewHost* rvh = RenderViewHost::FromID(
568 render_process_id, render_view_id);
569 if (!rvh) {
570 NOTREACHED();
571 return;
572 }
573
574 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37575 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04576 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37577 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04578 service->RequestPermission(
579 source_origin, render_process_id, render_view_id, callback_context,
580 tab_util::GetTabContentsByID(render_process_id, render_view_id));
581}
582
583WebKit::WebNotificationPresenter::Permission
584 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
585 const GURL& source_url,
586 const content::ResourceContext& context) {
587 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
588 ProfileIOData* io_data =
589 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
590
591 const Extension* extension =
592 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
593 if (extension &&
[email protected]0d3e4a22011-06-23 19:02:52594 extension->HasAPIPermission(ExtensionAPIPermission::kNotification)) {
[email protected]941623e2011-06-07 23:06:04595 return WebKit::WebNotificationPresenter::PermissionAllowed;
596 }
597
598 // Fall back to the regular notification preferences, which works on an
599 // origin basis.
600 return io_data->GetNotificationService() ?
601 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
602 WebKit::WebNotificationPresenter::PermissionNotAllowed;
603}
604
605void ChromeContentBrowserClient::ShowDesktopNotification(
606 const DesktopNotificationHostMsg_Show_Params& params,
607 int render_process_id,
608 int render_view_id,
609 bool worker) {
610 RenderViewHost* rvh = RenderViewHost::FromID(
611 render_process_id, render_view_id);
612 if (!rvh) {
613 NOTREACHED();
614 return;
615 }
616
617 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37618 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04619 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37620 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04621 service->ShowDesktopNotification(
622 params, render_process_id, render_view_id,
623 worker ? DesktopNotificationService::WorkerNotification :
624 DesktopNotificationService::PageNotification);
625}
626
627void ChromeContentBrowserClient::CancelDesktopNotification(
628 int render_process_id,
629 int render_view_id,
630 int notification_id) {
631 RenderViewHost* rvh = RenderViewHost::FromID(
632 render_process_id, render_view_id);
633 if (!rvh) {
634 NOTREACHED();
635 return;
636 }
637
638 RenderProcessHost* process = rvh->process();
[email protected]3d7474ff2011-07-27 17:47:37639 Profile* profile = Profile::FromBrowserContext(process->browser_context());
[email protected]941623e2011-06-07 23:06:04640 DesktopNotificationService* service =
[email protected]3d7474ff2011-07-27 17:47:37641 DesktopNotificationServiceFactory::GetForProfile(profile);
[email protected]941623e2011-06-07 23:06:04642 service->CancelDesktopNotification(
643 render_process_id, render_view_id, notification_id);
644}
645
[email protected]9f3fba52011-06-08 20:37:19646bool ChromeContentBrowserClient::CanCreateWindow(
647 const GURL& source_url,
648 WindowContainerType container_type,
649 const content::ResourceContext& context) {
650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
651 // If the opener is trying to create a background window but doesn't have
652 // the appropriate permission, fail the attempt.
653 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
654 ProfileIOData* io_data =
655 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
656 const Extension* extension =
657 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
658 return (extension &&
[email protected]0d3e4a22011-06-23 19:02:52659 extension->HasAPIPermission(ExtensionAPIPermission::kBackground));
[email protected]9f3fba52011-06-08 20:37:19660 }
661 return true;
662}
663
664std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
665 const GURL& url, const content::ResourceContext& context) {
666 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
667 // Check if it's an extension-created worker, in which case we want to use
668 // the name of the extension.
669 ProfileIOData* io_data =
670 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
671 const Extension* extension =
672 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
673 return extension ? extension->name() : std::string();
674}
675
[email protected]3cb054e62011-06-13 05:21:17676ResourceDispatcherHost*
677 ChromeContentBrowserClient::GetResourceDispatcherHost() {
678 return g_browser_process->resource_dispatcher_host();
679}
680
681ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
682 return g_browser_process->clipboard();
683}
684
[email protected]8f6a3b852011-07-19 16:48:56685MHTMLGenerationManager*
686 ChromeContentBrowserClient::GetMHTMLGenerationManager() {
687 return g_browser_process->mhtml_generation_manager();
688}
689
[email protected]dce502762011-07-20 08:53:49690DevToolsManager* ChromeContentBrowserClient::GetDevToolsManager() {
691 return g_browser_process->devtools_manager();
692}
693
[email protected]ae6e9912011-07-27 01:18:28694net::NetLog* ChromeContentBrowserClient::GetNetLog() {
695 return g_browser_process->net_log();
696}
697
[email protected]3bc0b562011-08-24 23:51:04698speech_input::SpeechInputManager*
699 ChromeContentBrowserClient::GetSpeechInputManager() {
700 return speech_input::ChromeSpeechInputManager::GetInstance();
701}
702
[email protected]32538d92011-08-25 00:09:23703AccessTokenStore* ChromeContentBrowserClient::CreateAccessTokenStore() {
704 return new ChromeAccessTokenStore();
705}
706
[email protected]dbae6b02011-06-29 23:51:41707bool ChromeContentBrowserClient::IsFastShutdownPossible() {
708 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
709 return !browser_command_line.HasSwitch(switches::kChromeFrame);
710}
711
[email protected]3d7474ff2011-07-27 17:47:37712WebPreferences ChromeContentBrowserClient::GetWebkitPrefs(
713 content::BrowserContext* browser_context, bool is_web_ui) {
714 return RenderViewHostDelegateHelper::GetWebkitPrefs(browser_context,
715 is_web_ui);
[email protected]181a95ee2011-07-12 19:26:36716}
717
718void ChromeContentBrowserClient::UpdateInspectorSetting(
719 RenderViewHost* rvh, const std::string& key, const std::string& value) {
720 RenderViewHostDelegateHelper::UpdateInspectorSetting(
[email protected]3d7474ff2011-07-27 17:47:37721 rvh->process()->browser_context(), key, value);
[email protected]181a95ee2011-07-12 19:26:36722}
723
724void ChromeContentBrowserClient::ClearInspectorSettings(RenderViewHost* rvh) {
725 RenderViewHostDelegateHelper::ClearInspectorSettings(
[email protected]3d7474ff2011-07-27 17:47:37726 rvh->process()->browser_context());
[email protected]181a95ee2011-07-12 19:26:36727}
728
[email protected]b8148ac2011-07-13 22:03:25729void ChromeContentBrowserClient::BrowserURLHandlerCreated(
730 BrowserURLHandler* handler) {
731 // Add the default URL handlers.
732 handler->AddHandlerPair(&ExtensionWebUI::HandleChromeURLOverride,
733 BrowserURLHandler::null_handler());
734 handler->AddHandlerPair(BrowserURLHandler::null_handler(),
735 &ExtensionWebUI::HandleChromeURLOverrideReverse);
736
737 // about:
738 handler->AddHandlerPair(&WillHandleBrowserAboutURL,
739 BrowserURLHandler::null_handler());
740 // chrome: & friends.
741 handler->AddHandlerPair(&HandleWebUI,
742 BrowserURLHandler::null_handler());
743}
744
745void ChromeContentBrowserClient::ClearCache(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37746 Profile* profile = Profile::FromBrowserContext(
747 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25748 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
749 BrowsingDataRemover::EVERYTHING,
750 base::Time());
751 remover->Remove(BrowsingDataRemover::REMOVE_CACHE);
752 // BrowsingDataRemover takes care of deleting itself when done.
753}
754
755void ChromeContentBrowserClient::ClearCookies(RenderViewHost* rvh) {
[email protected]3d7474ff2011-07-27 17:47:37756 Profile* profile = Profile::FromBrowserContext(
757 rvh->site_instance()->GetProcess()->browser_context());
[email protected]b8148ac2011-07-13 22:03:25758 BrowsingDataRemover* remover = new BrowsingDataRemover(profile,
759 BrowsingDataRemover::EVERYTHING,
760 base::Time());
[email protected]dceaa912011-09-06 17:17:23761 int remove_mask = BrowsingDataRemover::REMOVE_SITE_DATA;
[email protected]b8148ac2011-07-13 22:03:25762 remover->Remove(remove_mask);
763 // BrowsingDataRemover takes care of deleting itself when done.
764}
765
[email protected]e1d16eb92011-08-18 23:19:32766FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
767 return download_util::GetDefaultDownloadDirectory();
768}
769
[email protected]b68bf3892011-08-23 15:03:58770net::URLRequestContextGetter*
771ChromeContentBrowserClient::GetDefaultRequestContextDeprecatedCrBug64339() {
772 return Profile::Deprecated::GetDefaultRequestContext();
773}
774
[email protected]c8571ea2011-08-26 17:22:17775net::URLRequestContextGetter*
776ChromeContentBrowserClient::GetSystemRequestContext() {
777 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
778 return g_browser_process->system_request_context();
779}
780
[email protected]b80f68432011-05-02 17:22:30781#if defined(OS_LINUX)
782int ChromeContentBrowserClient::GetCrashSignalFD(
783 const std::string& process_type) {
784 if (process_type == switches::kRendererProcess)
785 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
786
[email protected]9dbfff12011-07-01 19:37:07787 if (process_type == switches::kExtensionProcess) {
788 ExtensionCrashHandlerHostLinux* crash_handler =
789 ExtensionCrashHandlerHostLinux::GetInstance();
790 return crash_handler->GetDeathSignalSocket();
791 }
792
[email protected]b80f68432011-05-02 17:22:30793 if (process_type == switches::kPluginProcess)
794 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
795
796 if (process_type == switches::kPpapiPluginProcess)
797 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
798
799 if (process_type == switches::kGpuProcess)
800 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
801
802 return -1;
803}
[email protected]9dbfff12011-07-01 19:37:07804#endif // defined(OS_LINUX)
[email protected]b80f68432011-05-02 17:22:30805
[email protected]4a65826d2011-08-25 16:04:01806#if defined(OS_WIN)
807const wchar_t* ChromeContentBrowserClient::GetResourceDllName() {
808 return chrome::kBrowserResourcesDll;
809}
810#endif
811
[email protected]37a72af2011-06-13 05:42:01812#if defined(USE_NSS)
813crypto::CryptoModuleBlockingPasswordDelegate*
814 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
815 const GURL& url) {
816 return browser::NewCryptoModuleBlockingDialogDelegate(
817 browser::kCryptoModulePasswordKeygen, url.host());
818}
819#endif
820
[email protected]d977f9c2011-03-14 16:10:26821} // namespace chrome