-void ChromeContentBrowserClient::RequestDesktopNotificationPermission(
- const GURL& source_origin,
- content::RenderFrameHost* render_frame_host,
- const base::Callback<void(blink::WebNotificationPermission)>& callback) {
-#if defined(ENABLE_NOTIFICATIONS)
- // Skip showing the infobar if the request comes from an extension, and that
- // extension has the 'notify' permission. (If the extension does not have the
- // permission, the user will still be prompted.)
- Profile* profile = Profile::FromBrowserContext(
- render_frame_host->GetSiteInstance()->GetBrowserContext());
- DesktopNotificationService* notification_service =
- DesktopNotificationServiceFactory::GetForProfile(profile);
-#if defined(ENABLE_EXTENSIONS)
- InfoMap* extension_info_map =
- extensions::ExtensionSystem::Get(profile)->info_map();
- const Extension* extension = NULL;
- if (extension_info_map) {
- extensions::ExtensionSet extensions;
- extension_info_map->GetExtensionsWithAPIPermissionForSecurityOrigin(
- source_origin,
- render_frame_host->GetProcess()->GetID(),
- extensions::APIPermission::kNotifications,
- &extensions);
- for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
- iter != extensions.end(); ++iter) {
- if (notification_service->IsNotifierEnabled(NotifierId(
- NotifierId::APPLICATION, (*iter)->id()))) {
- extension = iter->get();
- break;
- }
- }
- }
- if (IsExtensionWithPermissionOrSuggestInConsole(
- APIPermission::kNotifications,
- extension,
- render_frame_host->GetRenderViewHost())) {
- callback.Run(blink::WebNotificationPermissionAllowed);
- return;
- }
-#endif
-
- WebContents* web_contents = WebContents::FromRenderFrameHost(
- render_frame_host);
- int render_process_id = render_frame_host->GetProcess()->GetID();
- const PermissionRequestID request_id(render_process_id,
- web_contents->GetRoutingID(),
- -1 /* bridge id */,
- GURL());
-
- notification_service->RequestNotificationPermission(
- web_contents,
- request_id,
- source_origin,
- // TODO(peter): plumb user_gesture over IPC
- true,
- callback);
-
-#else
- NOTIMPLEMENTED();
-#endif
-}
-