blob: 03e17557be1400713e7f42d5b1cee2eaa87f2d91 [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]4287a3d2011-06-13 23:56:519#include "chrome/browser/accessibility/browser_accessibility_state.h"
[email protected]b80f68432011-05-02 17:22:3010#include "chrome/browser/browser_process.h"
[email protected]763ec4ca2011-04-29 15:48:1211#include "chrome/browser/character_encoding.h"
[email protected]97e6c4c2011-05-18 16:08:5112#include "chrome/browser/chrome_plugin_message_filter.h"
[email protected]317f96c92011-05-31 06:53:4113#include "chrome/browser/chrome_quota_permission_context.h"
[email protected]5327dfb2011-05-03 17:50:3614#include "chrome/browser/chrome_worker_message_filter.h"
[email protected]a2176792011-05-08 19:30:4915#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]8093a542011-05-13 07:29:3216#include "chrome/browser/content_settings/tab_specific_content_settings.h"
[email protected]f364d1392011-04-08 21:03:1017#include "chrome/browser/debugger/devtools_handler.h"
[email protected]941623e2011-06-07 23:06:0418#include "chrome/browser/extensions/extension_info_map.h"
[email protected]f364d1392011-04-08 21:03:1019#include "chrome/browser/extensions/extension_message_handler.h"
[email protected]d977f9c2011-03-14 16:10:2620#include "chrome/browser/extensions/extension_service.h"
[email protected]763ec4ca2011-04-29 15:48:1221#include "chrome/browser/google/google_util.h"
[email protected]941623e2011-06-07 23:06:0422#include "chrome/browser/notifications/desktop_notification_service.h"
23#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]0609b17f2011-05-31 20:13:4224#include "chrome/browser/platform_util.h"
[email protected]763ec4ca2011-04-29 15:48:1225#include "chrome/browser/prefs/pref_service.h"
[email protected]05fcf982011-04-19 00:44:1426#include "chrome/browser/printing/printing_message_filter.h"
27#include "chrome/browser/profiles/profile.h"
[email protected]8093a542011-05-13 07:29:3228#include "chrome/browser/profiles/profile_io_data.h"
[email protected]05fcf982011-04-19 00:44:1429#include "chrome/browser/renderer_host/chrome_render_message_filter.h"
[email protected]53a0afa2011-04-28 02:09:3330#include "chrome/browser/renderer_host/chrome_render_view_host_observer.h"
[email protected]d4cff272011-05-02 15:46:0131#include "chrome/browser/renderer_host/text_input_client_message_filter.h"
[email protected]05fcf982011-04-19 00:44:1432#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
33#include "chrome/browser/spellcheck_message_filter.h"
[email protected]8ec26472011-06-06 16:52:4534#include "chrome/browser/ssl/ssl_add_cert_handler.h"
[email protected]848dd042011-06-04 18:24:0335#include "chrome/browser/ssl/ssl_blocking_page.h"
[email protected]8ec26472011-06-06 16:52:4536#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
37#include "chrome/browser/tab_contents/tab_util.h"
38#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
[email protected]1fd1a502011-03-30 16:55:5639#include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
[email protected]b80f68432011-05-02 17:22:3040#include "chrome/common/child_process_logging.h"
41#include "chrome/common/chrome_switches.h"
[email protected]941623e2011-06-07 23:06:0442#include "chrome/common/extensions/extension.h"
[email protected]c5dbef02011-05-13 05:06:0943#include "chrome/common/extensions/extension_messages.h"
[email protected]763ec4ca2011-04-29 15:48:1244#include "chrome/common/pref_names.h"
[email protected]3e69bc82011-05-26 23:22:3845#include "chrome/common/render_messages.h"
[email protected]c5dbef02011-05-13 05:06:0946#include "chrome/common/url_constants.h"
47#include "content/browser/browsing_instance.h"
48#include "content/browser/child_process_security_policy.h"
[email protected]97e6c4c2011-05-18 16:08:5149#include "content/browser/plugin_process_host.h"
[email protected]05fcf982011-04-19 00:44:1450#include "content/browser/renderer_host/browser_render_process_host.h"
[email protected]d977f9c2011-03-14 16:10:2651#include "content/browser/renderer_host/render_view_host.h"
[email protected]a2176792011-05-08 19:30:4952#include "content/browser/resource_context.h"
[email protected]c5dbef02011-05-13 05:06:0953#include "content/browser/site_instance.h"
[email protected]8ec26472011-06-06 16:52:4554#include "content/browser/ssl/ssl_client_auth_handler.h"
[email protected]763ec4ca2011-04-29 15:48:1255#include "content/browser/tab_contents/tab_contents.h"
[email protected]5327dfb2011-05-03 17:50:3656#include "content/browser/worker_host/worker_process_host.h"
[email protected]c5dbef02011-05-13 05:06:0957#include "content/common/bindings_policy.h"
[email protected]941623e2011-06-07 23:06:0458#include "content/common/desktop_notification_messages.h"
[email protected]ed24fad2011-05-10 22:44:0159#include "net/base/cookie_monster.h"
60#include "net/base/cookie_options.h"
[email protected]d977f9c2011-03-14 16:10:2661
[email protected]b80f68432011-05-02 17:22:3062#if defined(OS_LINUX)
63#include "base/linux_util.h"
64#include "chrome/browser/crash_handler_host_linux.h"
[email protected]1fd5302c2011-05-28 04:06:4365#endif
[email protected]b80f68432011-05-02 17:22:3066
[email protected]37a72af2011-06-13 05:42:0167#if defined(USE_NSS)
68#include "chrome/browser/ui/crypto_module_password_dialog.h"
69#endif
70
[email protected]c5dbef02011-05-13 05:06:0971namespace {
72
73void InitRenderViewHostForExtensions(RenderViewHost* render_view_host) {
74 // Note that due to GetEffectiveURL(), even hosted apps will have a
75 // chrome-extension:// URL for their site, so we can ignore that wrinkle here.
76 SiteInstance* site_instance = render_view_host->site_instance();
77 const GURL& site = site_instance->site();
78 RenderProcessHost* process = render_view_host->process();
79
80 if (!site.SchemeIs(chrome::kExtensionScheme))
81 return;
82
83 Profile* profile = site_instance->browsing_instance()->profile();
84 ExtensionService* service = profile->GetExtensionService();
85 if (!service)
86 return;
87
88 ExtensionProcessManager* process_manager =
89 profile->GetExtensionProcessManager();
90 CHECK(process_manager);
91
92 // This can happen if somebody typos a chrome-extension:// URL.
93 const Extension* extension = service->GetExtensionByURL(site);
94 if (!extension)
95 return;
96
97 site_instance->GetProcess()->mark_is_extension_process();
98
99 // Register the association between extension and process with
100 // ExtensionProcessManager.
101 process_manager->RegisterExtensionProcess(extension->id(), process->id());
102
103 // Record which, if any, installed app is associated with this process.
104 // TODO(aa): Totally lame to store this state in a global map in extension
105 // service. Can we get it from EPM instead?
106 if (extension->is_app())
107 service->SetInstalledAppForRenderer(process->id(), extension);
108
109 // Some extensions use chrome:// URLs.
110 Extension::Type type = extension->GetType();
111 if (type == Extension::TYPE_EXTENSION ||
112 type == Extension::TYPE_PACKAGED_APP) {
113 ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
114 process->id(), chrome::kChromeUIScheme);
115 }
116
117 // Enable extension bindings for the renderer. Currently only extensions,
118 // packaged apps, and hosted component apps use extension bindings.
119 if (type == Extension::TYPE_EXTENSION ||
[email protected]2333bf22011-05-19 02:16:51120 type == Extension::TYPE_USER_SCRIPT ||
[email protected]c5dbef02011-05-13 05:06:09121 type == Extension::TYPE_PACKAGED_APP ||
122 (type == Extension::TYPE_HOSTED_APP &&
123 extension->location() == Extension::COMPONENT)) {
124 render_view_host->Send(new ExtensionMsg_ActivateExtension(extension->id()));
125 render_view_host->AllowBindings(BindingsPolicy::EXTENSION);
126 }
127}
128
129}
130
[email protected]d977f9c2011-03-14 16:10:26131namespace chrome {
132
[email protected]f364d1392011-04-08 21:03:10133void ChromeContentBrowserClient::RenderViewHostCreated(
134 RenderViewHost* render_view_host) {
[email protected]53a0afa2011-04-28 02:09:33135 new ChromeRenderViewHostObserver(render_view_host);
[email protected]f364d1392011-04-08 21:03:10136 new DevToolsHandler(render_view_host);
137 new ExtensionMessageHandler(render_view_host);
[email protected]f364d1392011-04-08 21:03:10138
[email protected]4287a3d2011-06-13 23:56:51139 if (BrowserAccessibilityState::GetInstance()->IsAccessibleBrowser())
140 render_view_host->EnableRendererAccessibility();
141
[email protected]c5dbef02011-05-13 05:06:09142 InitRenderViewHostForExtensions(render_view_host);
[email protected]d977f9c2011-03-14 16:10:26143}
144
[email protected]05fcf982011-04-19 00:44:14145void ChromeContentBrowserClient::BrowserRenderProcessHostCreated(
146 BrowserRenderProcessHost* host) {
[email protected]c47cfd62011-04-29 21:27:02147 int id = host->id();
148 Profile* profile = host->profile();
[email protected]05fcf982011-04-19 00:44:14149 host->channel()->AddFilter(new ChromeRenderMessageFilter(
[email protected]c47cfd62011-04-29 21:27:02150 id, profile, profile->GetRequestContextForRenderProcess(id)));
[email protected]05fcf982011-04-19 00:44:14151 host->channel()->AddFilter(new PrintingMessageFilter());
152 host->channel()->AddFilter(
[email protected]c47cfd62011-04-29 21:27:02153 new SearchProviderInstallStateMessageFilter(id, profile));
154 host->channel()->AddFilter(new SpellCheckMessageFilter(id));
[email protected]d4cff272011-05-02 15:46:01155#if defined(OS_MACOSX)
156 host->channel()->AddFilter(new TextInputClientMessageFilter(host->id()));
157#endif
[email protected]3e69bc82011-05-26 23:22:38158
159 host->Send(new ViewMsg_SetIsIncognitoProcess(profile->IsOffTheRecord()));
[email protected]05fcf982011-04-19 00:44:14160}
161
[email protected]97e6c4c2011-05-18 16:08:51162void ChromeContentBrowserClient::PluginProcessHostCreated(
163 PluginProcessHost* host) {
164 host->AddFilter(new ChromePluginMessageFilter(host));
165}
166
[email protected]5327dfb2011-05-03 17:50:36167void ChromeContentBrowserClient::WorkerProcessHostCreated(
168 WorkerProcessHost* host) {
169 host->AddFilter(new ChromeWorkerMessageFilter(host));
170}
171
[email protected]1fd1a502011-03-30 16:55:56172content::WebUIFactory* ChromeContentBrowserClient::GetWebUIFactory() {
173 return ChromeWebUIFactory::GetInstance();
174}
175
[email protected]36fb2c7c2011-04-04 15:49:08176GURL ChromeContentBrowserClient::GetEffectiveURL(Profile* profile,
177 const GURL& url) {
178 // Get the effective URL for the given actual URL. If the URL is part of an
179 // installed app, the effective URL is an extension URL with the ID of that
180 // extension as the host. This has the effect of grouping apps together in
181 // a common SiteInstance.
182 if (!profile || !profile->GetExtensionService())
183 return url;
184
185 const Extension* extension =
186 profile->GetExtensionService()->GetExtensionByWebExtent(url);
187 if (!extension)
188 return url;
189
190 // If the URL is part of an extension's web extent, convert it to an
191 // extension URL.
192 return extension->GetResourceURL(url.path());
193}
194
[email protected]0f012df82011-05-19 14:15:29195bool ChromeContentBrowserClient::IsURLSameAsAnySiteInstance(const GURL& url) {
[email protected]89f550b2011-06-08 18:34:03196 return url == GURL(chrome::kChromeUICrashURL) ||
197 url == GURL(chrome::kChromeUIKillURL) ||
198 url == GURL(chrome::kChromeUIHangURL) ||
199 url == GURL(chrome::kChromeUIShorthangURL);
[email protected]0f012df82011-05-19 14:15:29200}
201
[email protected]763ec4ca2011-04-29 15:48:12202std::string ChromeContentBrowserClient::GetCanonicalEncodingNameByAliasName(
203 const std::string& alias_name) {
204 return CharacterEncoding::GetCanonicalEncodingNameByAliasName(alias_name);
205}
206
[email protected]b80f68432011-05-02 17:22:30207void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
208 CommandLine* command_line, int child_process_id) {
209#if defined(USE_LINUX_BREAKPAD)
210 if (IsCrashReporterEnabled()) {
211 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
212 child_process_logging::GetClientId() + "," + base::GetLinuxDistro());
213 }
214#elif defined(OS_MACOSX)
215 if (IsCrashReporterEnabled()) {
216 command_line->AppendSwitchASCII(switches::kEnableCrashReporter,
217 child_process_logging::GetClientId());
218 }
219#endif // OS_MACOSX
220
221 std::string process_type =
222 command_line->GetSwitchValueASCII(switches::kProcessType);
[email protected]3cb054e62011-06-13 05:21:17223 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
[email protected]b80f68432011-05-02 17:22:30224 if (process_type == switches::kExtensionProcess ||
225 process_type == switches::kRendererProcess) {
[email protected]b80f68432011-05-02 17:22:30226 FilePath user_data_dir =
227 browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
228 if (!user_data_dir.empty())
229 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir);
230#if defined(OS_CHROMEOS)
231 const std::string& login_profile =
232 browser_command_line.GetSwitchValueASCII(switches::kLoginProfile);
233 if (!login_profile.empty())
234 command_line->AppendSwitchASCII(switches::kLoginProfile, login_profile);
235#endif
236
237 RenderProcessHost* process = RenderProcessHost::FromID(child_process_id);
238
239 PrefService* prefs = process->profile()->GetPrefs();
240 // Currently this pref is only registered if applied via a policy.
241 if (prefs->HasPrefPath(prefs::kDisable3DAPIs) &&
242 prefs->GetBoolean(prefs::kDisable3DAPIs)) {
243 // Turn this policy into a command line switch.
244 command_line->AppendSwitch(switches::kDisable3DAPIs);
245 }
246
247 // Disable client-side phishing detection in the renderer if it is disabled
248 // in the browser process.
249 if (!g_browser_process->safe_browsing_detection_service())
250 command_line->AppendSwitch(switches::kDisableClientSidePhishingDetection);
[email protected]4287a3d2011-06-13 23:56:51251
252 static const char* const kSwitchNames[] = {
253 switches::kAllowHTTPBackgroundPage,
254 switches::kAllowScriptingGallery,
255 switches::kAppsCheckoutURL,
256 switches::kAppsGalleryURL,
257 switches::kDebugPrint,
258#if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
259 // Enabled by default in Google Chrome builds, except on CrOS.
260 switches::kDisablePrintPreview,
261#else
262 // Disabled by default in Chromium builds and on CrOS.
263 switches::kEnablePrintPreview,
264#endif
265 switches::kDomAutomationController,
266 switches::kDumpHistogramsOnExit,
267 switches::kEnableClickToPlay,
268 switches::kEnableCrxlessWebApps,
269 switches::kEnableExperimentalExtensionApis,
270 switches::kEnableInBrowserThumbnailing,
271 switches::kEnableIPCFuzzing,
272 switches::kEnableNaCl,
273 switches::kEnableRemoting,
274 switches::kEnableResourceContentSettings,
275 switches::kEnableSearchProviderApiV2,
276 switches::kEnableWatchdog,
277 switches::kExperimentalSpellcheckerFeatures,
278 switches::kMemoryProfiling,
279 switches::kMessageLoopHistogrammer,
280 switches::kPpapiFlashArgs,
281 switches::kPpapiFlashInProcess,
282 switches::kPpapiFlashPath,
283 switches::kPpapiFlashVersion,
284 switches::kProfilingAtStart,
285 switches::kProfilingFile,
286 switches::kProfilingFlush,
287 switches::kRemoteShellPort,
288 switches::kSilentDumpOnDCHECK,
289 };
290
291 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
292 arraysize(kSwitchNames));
[email protected]3cb054e62011-06-13 05:21:17293 } else if (process_type == switches::kUtilityProcess) {
294 if (browser_command_line.HasSwitch(
295 switches::kEnableExperimentalExtensionApis)) {
296 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
297 }
[email protected]4287a3d2011-06-13 23:56:51298 } else if (process_type == switches::kPluginProcess) {
299 static const char* const kSwitchNames[] = {
300 #if defined(OS_CHROMEOS)
301 switches::kLoginProfile,
302 #endif
303 switches::kMemoryProfiling,
304 switches::kSilentDumpOnDCHECK,
305 switches::kUserDataDir,
306 };
307
308 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
309 arraysize(kSwitchNames));
310 } else if (process_type == switches::kZygoteProcess) {
311 static const char* const kSwitchNames[] = {
312 switches::kEnableRemoting,
313 switches::kUserDataDir, // Make logs go to the right file.
314 // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox.
315 switches::kPpapiFlashInProcess,
316 switches::kPpapiFlashPath,
317 switches::kPpapiFlashVersion,
318 };
319
320 command_line->CopySwitchesFrom(browser_command_line, kSwitchNames,
321 arraysize(kSwitchNames));
[email protected]b80f68432011-05-02 17:22:30322 }
323}
324
325std::string ChromeContentBrowserClient::GetApplicationLocale() {
326 return g_browser_process->GetApplicationLocale();
327}
328
[email protected]b5cca982011-05-26 04:42:08329std::string ChromeContentBrowserClient::GetAcceptLangs(const TabContents* tab) {
330 return tab->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
331}
332
[email protected]a2176792011-05-08 19:30:49333bool ChromeContentBrowserClient::AllowAppCache(
[email protected]5b52ad42011-05-26 14:26:09334 const GURL& manifest_url,
335 const content::ResourceContext& context) {
[email protected]8093a542011-05-13 07:29:32336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
337 ProfileIOData* io_data =
338 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09339 // FIXME(jochen): get the correct top-level origin.
[email protected]efa55212011-05-13 16:19:38340 ContentSetting setting = io_data->GetHostContentSettingsMap()->
[email protected]5b52ad42011-05-26 14:26:09341 GetCookieContentSetting(manifest_url, manifest_url, true);
[email protected]a2176792011-05-08 19:30:49342 DCHECK(setting != CONTENT_SETTING_DEFAULT);
343 return setting != CONTENT_SETTING_BLOCK;
344}
345
[email protected]ed24fad2011-05-10 22:44:01346bool ChromeContentBrowserClient::AllowGetCookie(
347 const GURL& url,
348 const GURL& first_party,
349 const net::CookieList& cookie_list,
350 const content::ResourceContext& context,
351 int render_process_id,
352 int render_view_id) {
353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32354 ProfileIOData* io_data =
355 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09356 ContentSetting setting = io_data->GetHostContentSettingsMap()->
357 GetCookieContentSetting(url, first_party, false);
358 bool allow = setting == CONTENT_SETTING_ALLOW ||
359 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01360
[email protected]8093a542011-05-13 07:29:32361 BrowserThread::PostTask(
362 BrowserThread::UI, FROM_HERE,
363 NewRunnableFunction(
364 &TabSpecificContentSettings::CookiesRead,
365 render_process_id, render_view_id, url, cookie_list, !allow));
[email protected]ed24fad2011-05-10 22:44:01366 return allow;
367}
368
369bool ChromeContentBrowserClient::AllowSetCookie(
370 const GURL& url,
371 const GURL& first_party,
372 const std::string& cookie_line,
373 const content::ResourceContext& context,
374 int render_process_id,
375 int render_view_id,
376 net::CookieOptions* options) {
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
[email protected]8093a542011-05-13 07:29:32378 ProfileIOData* io_data =
379 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
[email protected]5b52ad42011-05-26 14:26:09380 ContentSetting setting = io_data->GetHostContentSettingsMap()->
381 GetCookieContentSetting(url, first_party, true);
[email protected]ed24fad2011-05-10 22:44:01382
[email protected]5b52ad42011-05-26 14:26:09383 if (setting == CONTENT_SETTING_SESSION_ONLY)
384 options->set_force_session();
[email protected]ed24fad2011-05-10 22:44:01385
[email protected]5b52ad42011-05-26 14:26:09386 bool allow = setting == CONTENT_SETTING_ALLOW ||
387 setting == CONTENT_SETTING_SESSION_ONLY;
[email protected]ed24fad2011-05-10 22:44:01388
[email protected]8093a542011-05-13 07:29:32389 BrowserThread::PostTask(
390 BrowserThread::UI, FROM_HERE,
391 NewRunnableFunction(
392 &TabSpecificContentSettings::CookieChanged,
393 render_process_id, render_view_id, url, cookie_line, *options,
394 !allow));
[email protected]ed24fad2011-05-10 22:44:01395 return allow;
396}
397
[email protected]317f96c92011-05-31 06:53:41398QuotaPermissionContext*
399ChromeContentBrowserClient::CreateQuotaPermissionContext() {
400 return new ChromeQuotaPermissionContext();
401}
402
[email protected]0609b17f2011-05-31 20:13:42403void ChromeContentBrowserClient::RevealFolderInOS(const FilePath& path) {
404 // On Mac, this call needs to be done on the UI thread. On other platforms,
405 // do it on the FILE thread so we don't slow down UI.
406#if defined(OS_MACOSX)
407 platform_util::OpenItem(path);
408#else
409 BrowserThread::PostTask(
410 BrowserThread::FILE, FROM_HERE,
411 NewRunnableFunction(&platform_util::OpenItem, path));
412#endif
413}
414
[email protected]848dd042011-06-04 18:24:03415void ChromeContentBrowserClient::AllowCertificateError(
416 SSLCertErrorHandler* handler,
417 bool overridable,
418 Callback2<SSLCertErrorHandler*, bool>::Type* callback) {
419 SSLBlockingPage* blocking_page = new SSLBlockingPage(
420 handler, overridable, callback);
421 blocking_page->Show();
422}
423
[email protected]8ec26472011-06-06 16:52:45424void ChromeContentBrowserClient::ShowClientCertificateRequestDialog(
425 int render_process_id,
426 int render_view_id,
427 SSLClientAuthHandler* handler) {
428 TabContents* tab = tab_util::GetTabContentsByID(
429 render_process_id, render_view_id);
430 if (!tab) {
431 NOTREACHED();
432 return;
433 }
434
435 TabContentsWrapper* wrapper =
436 TabContentsWrapper::GetCurrentWrapperForContents(tab);
437 wrapper->ssl_helper()->ShowClientCertificateRequestDialog(handler);
438}
439
440void ChromeContentBrowserClient::AddNewCertificate(
441 net::URLRequest* request,
442 net::X509Certificate* cert,
443 int render_process_id,
444 int render_view_id) {
445 // The handler will run the UI and delete itself when it's finished.
446 new SSLAddCertHandler(request, cert, render_process_id, render_view_id);
447}
448
[email protected]941623e2011-06-07 23:06:04449void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
450 const GURL& source_origin,
451 int callback_context,
452 int render_process_id,
453 int render_view_id) {
454 RenderViewHost* rvh = RenderViewHost::FromID(
455 render_process_id, render_view_id);
456 if (!rvh) {
457 NOTREACHED();
458 return;
459 }
460
461 RenderProcessHost* process = rvh->process();
462 DesktopNotificationService* service =
463 DesktopNotificationServiceFactory::GetForProfile(process->profile());
464 service->RequestPermission(
465 source_origin, render_process_id, render_view_id, callback_context,
466 tab_util::GetTabContentsByID(render_process_id, render_view_id));
467}
468
469WebKit::WebNotificationPresenter::Permission
470 ChromeContentBrowserClient::CheckDesktopNotificationPermission(
471 const GURL& source_url,
472 const content::ResourceContext& context) {
473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
474 ProfileIOData* io_data =
475 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
476
477 const Extension* extension =
478 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
479 if (extension &&
480 extension->HasApiPermission(Extension::kNotificationPermission)) {
481 return WebKit::WebNotificationPresenter::PermissionAllowed;
482 }
483
484 // Fall back to the regular notification preferences, which works on an
485 // origin basis.
486 return io_data->GetNotificationService() ?
487 io_data->GetNotificationService()->HasPermission(source_url.GetOrigin()) :
488 WebKit::WebNotificationPresenter::PermissionNotAllowed;
489}
490
491void ChromeContentBrowserClient::ShowDesktopNotification(
492 const DesktopNotificationHostMsg_Show_Params& params,
493 int render_process_id,
494 int render_view_id,
495 bool worker) {
496 RenderViewHost* rvh = RenderViewHost::FromID(
497 render_process_id, render_view_id);
498 if (!rvh) {
499 NOTREACHED();
500 return;
501 }
502
503 RenderProcessHost* process = rvh->process();
504 DesktopNotificationService* service =
505 DesktopNotificationServiceFactory::GetForProfile(process->profile());
506 service->ShowDesktopNotification(
507 params, render_process_id, render_view_id,
508 worker ? DesktopNotificationService::WorkerNotification :
509 DesktopNotificationService::PageNotification);
510}
511
512void ChromeContentBrowserClient::CancelDesktopNotification(
513 int render_process_id,
514 int render_view_id,
515 int notification_id) {
516 RenderViewHost* rvh = RenderViewHost::FromID(
517 render_process_id, render_view_id);
518 if (!rvh) {
519 NOTREACHED();
520 return;
521 }
522
523 RenderProcessHost* process = rvh->process();
524 DesktopNotificationService* service =
525 DesktopNotificationServiceFactory::GetForProfile(process->profile());
526 service->CancelDesktopNotification(
527 render_process_id, render_view_id, notification_id);
528}
529
[email protected]9f3fba52011-06-08 20:37:19530bool ChromeContentBrowserClient::CanCreateWindow(
531 const GURL& source_url,
532 WindowContainerType container_type,
533 const content::ResourceContext& context) {
534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
535 // If the opener is trying to create a background window but doesn't have
536 // the appropriate permission, fail the attempt.
537 if (container_type == WINDOW_CONTAINER_TYPE_BACKGROUND) {
538 ProfileIOData* io_data =
539 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
540 const Extension* extension =
541 io_data->GetExtensionInfoMap()->extensions().GetByURL(source_url);
542 return (extension &&
543 extension->HasApiPermission(Extension::kBackgroundPermission));
544 }
545 return true;
546}
547
548std::string ChromeContentBrowserClient::GetWorkerProcessTitle(
549 const GURL& url, const content::ResourceContext& context) {
550 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
551 // Check if it's an extension-created worker, in which case we want to use
552 // the name of the extension.
553 ProfileIOData* io_data =
554 reinterpret_cast<ProfileIOData*>(context.GetUserData(NULL));
555 const Extension* extension =
556 io_data->GetExtensionInfoMap()->extensions().GetByID(url.host());
557 return extension ? extension->name() : std::string();
558}
559
[email protected]3cb054e62011-06-13 05:21:17560ResourceDispatcherHost*
561 ChromeContentBrowserClient::GetResourceDispatcherHost() {
562 return g_browser_process->resource_dispatcher_host();
563}
564
565ui::Clipboard* ChromeContentBrowserClient::GetClipboard() {
566 return g_browser_process->clipboard();
567}
568
[email protected]b80f68432011-05-02 17:22:30569#if defined(OS_LINUX)
570int ChromeContentBrowserClient::GetCrashSignalFD(
571 const std::string& process_type) {
572 if (process_type == switches::kRendererProcess)
573 return RendererCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
574
575 if (process_type == switches::kPluginProcess)
576 return PluginCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
577
578 if (process_type == switches::kPpapiPluginProcess)
579 return PpapiCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
580
581 if (process_type == switches::kGpuProcess)
582 return GpuCrashHandlerHostLinux::GetInstance()->GetDeathSignalSocket();
583
584 return -1;
585}
586#endif
587
[email protected]37a72af2011-06-13 05:42:01588#if defined(USE_NSS)
589crypto::CryptoModuleBlockingPasswordDelegate*
590 ChromeContentBrowserClient::GetCryptoPasswordDelegate(
591 const GURL& url) {
592 return browser::NewCryptoModuleBlockingDialogDelegate(
593 browser::kCryptoModulePasswordKeygen, url.host());
594}
595#endif
596
[email protected]d977f9c2011-03-14 16:10:26597} // namespace chrome