Chromium Code Reviews| Index: chrome/browser/notifications/desktop_notification_service.cc |
| =================================================================== |
| --- chrome/browser/notifications/desktop_notification_service.cc (revision 32803) |
| +++ chrome/browser/notifications/desktop_notification_service.cc (working copy) |
| @@ -191,6 +191,11 @@ |
| : profile_(profile), |
| ui_manager_(ui_manager) { |
| InitPrefs(); |
| + |
| + // Listen for new extension installations so we can cache permissions. |
| + notification_registrar_.Add(this, |
| + NotificationType::EXTENSION_LOADED, |
| + Source<Profile>(profile_)); |
| } |
| DesktopNotificationService::~DesktopNotificationService() { |
| @@ -212,8 +217,33 @@ |
| denied_sites = prefs->GetList(prefs::kDesktopNotificationDeniedOrigins); |
| prefs_cache_ = new NotificationsPrefsCache(allowed_sites, denied_sites); |
| + |
| + ExtensionsService* ext_service = profile_->GetExtensionsService(); |
| + if (ext_service) { |
| + const ExtensionList* extensions = ext_service->extensions(); |
| + for (ExtensionList::const_iterator iter = extensions->begin(); |
| + iter != extensions->end(); ++iter) { |
| + if ((*iter)->HasApiPermission(Extension::kNotificationPermission)) { |
| + prefs_cache_->CacheAllowedOrigin((*iter)->url()); |
|
Aaron Boodman
2009/11/24 20:38:14
Why do you need to store this state again? It is a
John Gregg
2009/11/24 20:52:44
I need this state on the IO thread to respond to a
|
| + } |
| + } |
| + } |
| } |
| +void DesktopNotificationService::Observe(NotificationType type, |
| + const NotificationSource& source, |
| + const NotificationDetails& details) { |
| + if (type != NotificationType::EXTENSION_LOADED) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + Details<Extension> extension = static_cast<Details<Extension> >(details); |
| + if (extension->HasApiPermission(Extension::kNotificationPermission)) { |
| + GrantPermission(extension->url()); |
| + } |
| +} |
| + |
| void DesktopNotificationService::GrantPermission(const GURL& origin) { |
| DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| PrefService* prefs = profile_->GetPrefs(); |
| @@ -292,7 +322,7 @@ |
| bool DesktopNotificationService::ShowDesktopNotification( |
| const GURL& origin, const GURL& url, int process_id, int route_id, |
| - NotificationSource source, int notification_id) { |
| + DesktopNotificationSource source, int notification_id) { |
| DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| NotificationObjectProxy* proxy = |
| new NotificationObjectProxy(process_id, route_id, |
| @@ -306,7 +336,7 @@ |
| bool DesktopNotificationService::ShowDesktopNotificationText( |
| const GURL& origin, const GURL& icon, const string16& title, |
| const string16& text, int process_id, int route_id, |
| - NotificationSource source, int notification_id) { |
| + DesktopNotificationSource source, int notification_id) { |
| DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| NotificationObjectProxy* proxy = |
| new NotificationObjectProxy(process_id, route_id, |