| Index: chrome/browser/notifications/desktop_notification_service.cc
|
| diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
|
| index 406ece6ad50f02cf8d7ae161db0252d87dd6b7dc..c97e0cd317508e93ba185f56bcca01f64023d885 100644
|
| --- a/chrome/browser/notifications/desktop_notification_service.cc
|
| +++ b/chrome/browser/notifications/desktop_notification_service.cc
|
| @@ -59,7 +59,6 @@ using message_center::NotifierId;
|
| using WebKit::WebNotificationPresenter;
|
| using WebKit::WebTextDirection;
|
|
|
| -
|
| // NotificationPermissionInfoBarDelegate --------------------------------------
|
|
|
| // The delegate for the infobar shown when an origin requests notification
|
| @@ -633,8 +632,42 @@ void DesktopNotificationService::OnStringListPrefChanged(
|
| }
|
|
|
| WebKit::WebNotificationPresenter::Permission
|
| - DesktopNotificationService::HasPermission(const GURL& origin) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| +DesktopNotificationService::HasPermission(const GURL& origin, int process_id) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| +
|
| + // There are two ways that permission can be granted:
|
| + // * An extension running in the process requested
|
| +
|
| + ExtensionService* service = profile_->GetExtensionService();
|
| + std::set<std::string> process_extensions =
|
| + service->process_map()->GetExtensionsInProcess(process_id);
|
| + const ExtensionSet* profile_extensions = service->extensions();
|
| +
|
| + ExtensionSet permission_extensions;
|
| +
|
| + if (origin.SchemeIs(extensions::kExtensionScheme)) {
|
| + const std::string& id = origin.host();
|
| +
|
| + if (process_extensions.find(id) != process_extensions.end()) {
|
| + const extensions::Extension* extension = profile_extensions->GetByID(id);
|
| + if (extension && ExtensionApplies(extension))
|
| + return WebKit::WebNotificationPresenter::PermissionAllowed;
|
| + }
|
| + } else {
|
| + for (std::set<std::string>::iterator iter = process_extensions.begin();
|
| + iter != process_extensions.end();
|
| + ++iter) {
|
| + const std::string& id = *iter;
|
| + const extensions::Extension* extension = profile_extensions->GetByID(id);
|
| + if (extension && ExtensionApplies(extension)) {
|
| + return WebKit::WebNotificationPresenter::PermissionAllowed;
|
| + }
|
| + }
|
| + }
|
| +
|
| + // Here, none of the known extensions apply to the security origin and have
|
| + // the notifications permission, so just check the content settings for the
|
| + // origin.
|
| HostContentSettingsMap* host_content_settings_map =
|
| profile_->GetHostContentSettingsMap();
|
| ContentSetting setting = host_content_settings_map->GetContentSetting(
|
| @@ -649,6 +682,7 @@ WebKit::WebNotificationPresenter::Permission
|
| return WebKit::WebNotificationPresenter::PermissionDenied;
|
| if (setting == CONTENT_SETTING_ASK)
|
| return WebKit::WebNotificationPresenter::PermissionNotAllowed;
|
| +
|
| NOTREACHED() << "Invalid notifications settings value: " << setting;
|
| return WebKit::WebNotificationPresenter::PermissionNotAllowed;
|
| }
|
| @@ -667,3 +701,11 @@ void DesktopNotificationService::Observe(
|
|
|
| SetNotifierEnabled(notifier_id, true);
|
| }
|
| +
|
| +bool DesktopNotificationService::ExtensionApplies(
|
| + const extensions::Extension* extension) {
|
| + message_center::NotifierId notifier_id(
|
| + message_center::NotifierId::APPLICATION, extension->id());
|
| + return IsNotifierEnabled(notifier_id) &&
|
| + extension->HasAPIPermission(extensions::APIPermission::kNotification);
|
| +}
|
|
|