Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1746)

Unified Diff: chrome/browser/notifications/desktop_notification_service.cc

Issue 25492006: Makes the response to CheckNotificationPermission asynchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
+}
« no previous file with comments | « chrome/browser/notifications/desktop_notification_service.h ('k') | chrome/browser/profiles/profile_io_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698