diff options
author | dewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-29 23:13:37 +0000 |
---|---|---|
committer | dewittj@chromium.org <dewittj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-29 23:13:37 +0000 |
commit | 33286c9c4a71992552614e64d7925cff05071caf (patch) | |
tree | 42072497aad6d9298516536400bf89dd3b5ca3b7 | |
parent | 4fc0071569acd1928e89b388dd0b6d44bea78776 (diff) | |
download | chromium_src-33286c9c4a71992552614e64d7925cff05071caf.zip chromium_src-33286c9c4a71992552614e64d7925cff05071caf.tar.gz chromium_src-33286c9c4a71992552614e64d7925cff05071caf.tar.bz2 |
Reland 201932: Add API function chrome.notifications.getAll
This function returns an object whose keys are the notification
IDs of all notifications created by that extension.
BUG=240924
TBR=miket@chromium.org
Review URL: https://chromiumcodereview.appspot.com/15715008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203001 0039d316-1c4b-4281-b951-d872f2087c98
16 files changed, 265 insertions, 18 deletions
diff --git a/chrome/browser/extensions/api/notifications/notifications_api.cc b/chrome/browser/extensions/api/notifications/notifications_api.cc index 9865aff..597cc8a 100644 --- a/chrome/browser/extensions/api/notifications/notifications_api.cc +++ b/chrome/browser/extensions/api/notifications/notifications_api.cc @@ -29,6 +29,23 @@ namespace { const char kResultKey[] = "result"; +// Given an extension id and another id, returns an id that is unique +// relative to other extensions. +std::string CreateScopedIdentifier(const std::string& extension_id, + const std::string& id) { + return extension_id + "-" + id; +} + +// Removes the unique internal identifier to send the ID as the +// extension expects it. +std::string StripScopeFromIdentifier(const std::string& extension_id, + const std::string& id) { + size_t index_of_separator = extension_id.length() + 1; + DCHECK_LT(index_of_separator, id.length()); + + return id.substr(index_of_separator); +} + class NotificationsApiDelegate : public NotificationDelegate { public: NotificationsApiDelegate(ApiFunction* api_function, @@ -46,13 +63,6 @@ class NotificationsApiDelegate : public NotificationDelegate { process_id_ = api_function->render_view_host()->GetProcess()->GetID(); } - // Given an extension id and another id, returns an id that is unique - // relative to other extensions. - static std::string CreateScopedIdentifier(const std::string& extension_id, - const std::string& id) { - return extension_id + "-" + id; - } - virtual void Display() OVERRIDE { } virtual void Error() OVERRIDE { @@ -135,10 +145,7 @@ bool NotificationsApiFunction::IsNotificationsApiAvailable() { // We need to check this explicitly rather than letting // _permission_features.json enforce it, because we're sharing the // chrome.notifications permissions namespace with WebKit notifications. - if (!(GetExtension()->is_platform_app() || GetExtension()->is_extension())) - return false; - - return true; + return GetExtension()->is_platform_app() || GetExtension()->is_extension(); } NotificationsApiFunction::NotificationsApiFunction() { @@ -333,9 +340,8 @@ bool NotificationsUpdateFunction::RunNotificationsApi() { params_ = api::notifications::Update::Params::Create(*args_); EXTENSION_FUNCTION_VALIDATE(params_.get()); - if (g_browser_process->notification_ui_manager()-> - DoesIdExist(NotificationsApiDelegate::CreateScopedIdentifier( - extension_->id(), params_->notification_id))) { + if (g_browser_process->notification_ui_manager()->DoesIdExist( + CreateScopedIdentifier(extension_->id(), params_->notification_id))) { CreateNotification(params_->notification_id, ¶ms_->options); SetResult(Value::CreateBooleanValue(true)); } else { @@ -357,9 +363,8 @@ bool NotificationsClearFunction::RunNotificationsApi() { params_ = api::notifications::Clear::Params::Create(*args_); EXTENSION_FUNCTION_VALIDATE(params_.get()); - bool cancel_result = g_browser_process->notification_ui_manager()-> - CancelById(NotificationsApiDelegate::CreateScopedIdentifier( - extension_->id(), params_->notification_id)); + bool cancel_result = g_browser_process->notification_ui_manager()->CancelById( + CreateScopedIdentifier(extension_->id(), params_->notification_id)); SetResult(Value::CreateBooleanValue(cancel_result)); SendResponse(true); @@ -367,4 +372,29 @@ bool NotificationsClearFunction::RunNotificationsApi() { return true; } +NotificationsGetAllFunction::NotificationsGetAllFunction() {} + +NotificationsGetAllFunction::~NotificationsGetAllFunction() {} + +bool NotificationsGetAllFunction::RunNotificationsApi() { + NotificationUIManager* notification_ui_manager = + g_browser_process->notification_ui_manager(); + std::set<std::string> notification_ids = + notification_ui_manager->GetAllIdsByProfileAndSourceOrigin( + profile_, extension_->url()); + + scoped_ptr<DictionaryValue> result(new DictionaryValue()); + + for (std::set<std::string>::iterator iter = notification_ids.begin(); + iter != notification_ids.end(); iter++) { + result->SetBooleanWithoutPathExpansion( + StripScopeFromIdentifier(extension_->id(), *iter), true); + } + + SetResult(result.release()); + SendResponse(true); + + return true; +} + } // namespace extensions diff --git a/chrome/browser/extensions/api/notifications/notifications_api.h b/chrome/browser/extensions/api/notifications/notifications_api.h index 8635a39..447d0bf 100644 --- a/chrome/browser/extensions/api/notifications/notifications_api.h +++ b/chrome/browser/extensions/api/notifications/notifications_api.h @@ -89,6 +89,20 @@ class NotificationsClearFunction : public NotificationsApiFunction { DECLARE_EXTENSION_FUNCTION("notifications.clear", NOTIFICATIONS_CLEAR) }; +class NotificationsGetAllFunction : public NotificationsApiFunction { + public: + NotificationsGetAllFunction(); + + // UIThreadExtensionFunction: + virtual bool RunNotificationsApi() OVERRIDE; + + protected: + virtual ~NotificationsGetAllFunction(); + + private: + DECLARE_EXTENSION_FUNCTION("notifications.getAll", NOTIFICATIONS_GET_ALL) +}; + } // namespace extensions #endif // CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_NOTIFICATIONS_API_H_ diff --git a/chrome/browser/extensions/api/notifications/notifications_apitest.cc b/chrome/browser/extensions/api/notifications/notifications_apitest.cc index 59a48ac..bf145fc 100644 --- a/chrome/browser/extensions/api/notifications/notifications_apitest.cc +++ b/chrome/browser/extensions/api/notifications/notifications_apitest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/stringprintf.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/api/notifications/notifications_api.h" #include "chrome/browser/extensions/extension_apitest.h" @@ -12,6 +13,7 @@ #include "content/public/browser/notification_service.h" #include "content/public/test/test_utils.h" #include "ui/message_center/message_center.h" +#include "ui/message_center/message_center_switches.h" #include "ui/message_center/message_center_util.h" // TODO(kbr): remove: http://crbug.com/222296 @@ -260,6 +262,78 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestMultipleItemNotification) { ASSERT_TRUE(notification_id.length() > 0); } +#if defined(OS_LINUX) +#define MAYBE_TestGetAll DISABLED_TestGetAll +#else +#define MAYBE_TestGetAll TestGetAll +#endif + +IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestGetAll) { + scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); + + { + scoped_refptr<extensions::NotificationsGetAllFunction> + notification_get_all_function( + new extensions::NotificationsGetAllFunction()); + notification_get_all_function->set_extension(empty_extension.get()); + notification_get_all_function->set_has_callback(true); + scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( + notification_get_all_function, "[]", browser(), utils::NONE)); + + base::DictionaryValue* return_value; + ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); + ASSERT_TRUE(result->GetAsDictionary(&return_value)); + ASSERT_TRUE(return_value->size() == 0); + } + + const unsigned int kNotificationsToCreate = 4; + + for (unsigned int i = 0; i < kNotificationsToCreate; i++) { + scoped_refptr<extensions::NotificationsCreateFunction> + notification_create_function( + new extensions::NotificationsCreateFunction()); + + notification_create_function->set_extension(empty_extension.get()); + notification_create_function->set_has_callback(true); + + scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( + notification_create_function, + base::StringPrintf("[\"identifier-%u\", " + "{" + "\"type\": \"basic\"," + "\"iconUrl\": \"an/image/that/does/not/exist.png\"," + "\"title\": \"Title\"," + "\"message\": \"Message.\"," + "\"priority\": 1," + "\"eventTime\": 1361488019.9999999" + "}]", + i), + browser(), + utils::NONE)); + } + + { + scoped_refptr<extensions::NotificationsGetAllFunction> + notification_get_all_function( + new extensions::NotificationsGetAllFunction()); + notification_get_all_function->set_extension(empty_extension.get()); + notification_get_all_function->set_has_callback(true); + scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( + notification_get_all_function, "[]", browser(), utils::NONE)); + + base::DictionaryValue* return_value; + ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType()); + ASSERT_TRUE(result->GetAsDictionary(&return_value)); + ASSERT_EQ(return_value->size(), kNotificationsToCreate); + bool dictionary_bool = false; + for (unsigned int i = 0; i < kNotificationsToCreate; i++) { + std::string id = base::StringPrintf("identifier-%u", i); + ASSERT_TRUE(return_value->GetBoolean(id, &dictionary_bool)); + ASSERT_TRUE(dictionary_bool); + } + } +} + IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) { #if defined(OS_MACOSX) // TODO(kbr): re-enable: http://crbug.com/222296 diff --git a/chrome/browser/notifications/balloon_notification_ui_manager.cc b/chrome/browser/notifications/balloon_notification_ui_manager.cc index 6388397..7c942d8 100644 --- a/chrome/browser/notifications/balloon_notification_ui_manager.cc +++ b/chrome/browser/notifications/balloon_notification_ui_manager.cc @@ -13,6 +13,7 @@ #include "chrome/browser/idle.h" #include "chrome/browser/notifications/balloon_collection.h" #include "chrome/browser/notifications/notification.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" #include "content/public/browser/notification_service.h" @@ -59,6 +60,26 @@ bool BalloonNotificationUIManager::CancelById(const std::string& id) { return balloon_collection_->RemoveById(id); } +std::set<std::string> +BalloonNotificationUIManager::GetAllIdsByProfileAndSourceOrigin( + Profile* profile, + const GURL& source) { + std::set<std::string> notification_ids = + NotificationUIManagerImpl::GetAllIdsByProfileAndSourceOrigin(profile, + source); + + const BalloonCollection::Balloons& balloons = + balloon_collection_->GetActiveBalloons(); + for (BalloonCollection::Balloons::const_iterator iter = balloons.begin(); + iter != balloons.end(); ++iter) { + if (profile->IsSameProfile((*iter)->profile()) && + source == (*iter)->notification().origin_url()) { + notification_ids.insert((*iter)->notification().notification_id()); + } + } + return notification_ids; +} + bool BalloonNotificationUIManager::CancelAllBySourceOrigin(const GURL& source) { // Same pattern as CancelById, but more complicated than the above // because there may be multiple notifications from the same source. diff --git a/chrome/browser/notifications/balloon_notification_ui_manager.h b/chrome/browser/notifications/balloon_notification_ui_manager.h index 12bb78e..953891e 100644 --- a/chrome/browser/notifications/balloon_notification_ui_manager.h +++ b/chrome/browser/notifications/balloon_notification_ui_manager.h @@ -36,6 +36,9 @@ class BalloonNotificationUIManager // NotificationUIManager: virtual bool DoesIdExist(const std::string& notification_id) OVERRIDE; virtual bool CancelById(const std::string& notification_id) OVERRIDE; + virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( + Profile* profile, + const GURL& source) OVERRIDE; virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; virtual void CancelAll() OVERRIDE; diff --git a/chrome/browser/notifications/message_center_notification_manager.cc b/chrome/browser/notifications/message_center_notification_manager.cc index 0d37a90..d2cc43f 100644 --- a/chrome/browser/notifications/message_center_notification_manager.cc +++ b/chrome/browser/notifications/message_center_notification_manager.cc @@ -70,6 +70,25 @@ bool MessageCenterNotificationManager::CancelById(const std::string& id) { return true; } +std::set<std::string> +MessageCenterNotificationManager::GetAllIdsByProfileAndSourceOrigin( + Profile* profile, + const GURL& source) { + + std::set<std::string> notification_ids = + NotificationUIManagerImpl::GetAllIdsByProfileAndSourceOrigin(profile, + source); + + for (NotificationMap::iterator iter = profile_notifications_.begin(); + iter != profile_notifications_.end(); iter++) { + if ((*iter).second->notification().origin_url() == source && + profile->IsSameProfile((*iter).second->profile())) { + notification_ids.insert(iter->first); + } + } + return notification_ids; +} + bool MessageCenterNotificationManager::CancelAllBySourceOrigin( const GURL& source) { // Same pattern as CancelById, but more complicated than the above @@ -94,7 +113,7 @@ bool MessageCenterNotificationManager::CancelAllByProfile(Profile* profile) { for (NotificationMap::iterator loopiter = profile_notifications_.begin(); loopiter != profile_notifications_.end(); ) { NotificationMap::iterator curiter = loopiter++; - if ((*curiter).second->profile() == profile) { + if (profile->IsSameProfile((*curiter).second->profile())) { message_center_->RemoveNotification(curiter->first, /* by_user */ false); removed = true; } diff --git a/chrome/browser/notifications/message_center_notification_manager.h b/chrome/browser/notifications/message_center_notification_manager.h index 12f8900..0d08189 100644 --- a/chrome/browser/notifications/message_center_notification_manager.h +++ b/chrome/browser/notifications/message_center_notification_manager.h @@ -34,6 +34,9 @@ class MessageCenterNotificationManager // NotificationUIManager virtual bool DoesIdExist(const std::string& notification_id) OVERRIDE; virtual bool CancelById(const std::string& notification_id) OVERRIDE; + virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( + Profile* profile, + const GURL& source) OVERRIDE; virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; virtual void CancelAll() OVERRIDE; diff --git a/chrome/browser/notifications/notification_ui_manager.cc b/chrome/browser/notifications/notification_ui_manager.cc index 1b1d62dc..2c73a9e 100644 --- a/chrome/browser/notifications/notification_ui_manager.cc +++ b/chrome/browser/notifications/notification_ui_manager.cc @@ -7,6 +7,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/notifications/balloon_notification_ui_manager.h" #include "chrome/browser/notifications/message_center_notification_manager.h" +#include "chrome/browser/profiles/profile.h" #include "ui/message_center/message_center_util.h" // static diff --git a/chrome/browser/notifications/notification_ui_manager.h b/chrome/browser/notifications/notification_ui_manager.h index 92dfe6e..6257939 100644 --- a/chrome/browser/notifications/notification_ui_manager.h +++ b/chrome/browser/notifications/notification_ui_manager.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_ #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_ +#include <set> #include <string> #include <vector> @@ -36,6 +37,12 @@ class NotificationUIManager { // displayed or in the queue. Returns true if anything was removed. virtual bool CancelById(const std::string& notification_id) = 0; + // Adds the notification_id for each outstanding notification to the set + // |notification_ids| (must not be NULL). + virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( + Profile* profile, + const GURL& source) = 0; + // Removes notifications matching the |source_origin| (which could be an // extension ID). Returns true if anything was removed. virtual bool CancelAllBySourceOrigin(const GURL& source_origin) = 0; diff --git a/chrome/browser/notifications/notification_ui_manager_impl.cc b/chrome/browser/notifications/notification_ui_manager_impl.cc index 0bda94d..e7fc422 100644 --- a/chrome/browser/notifications/notification_ui_manager_impl.cc +++ b/chrome/browser/notifications/notification_ui_manager_impl.cc @@ -95,6 +95,21 @@ bool NotificationUIManagerImpl::CancelById(const std::string& id) { return false; } +std::set<std::string> +NotificationUIManagerImpl::GetAllIdsByProfileAndSourceOrigin( + Profile* profile, + const GURL& source) { + std::set<std::string> notification_ids; + for (NotificationDeque::iterator iter = show_queue_.begin(); + iter != show_queue_.end(); iter++) { + if ((*iter)->notification().origin_url() == source && + profile->IsSameProfile((*iter)->profile())) { + notification_ids.insert((*iter)->notification().notification_id()); + } + } + return notification_ids; +} + bool NotificationUIManagerImpl::CancelAllBySourceOrigin(const GURL& source) { // Same pattern as CancelById, but more complicated than the above // because there may be multiple notifications from the same source. diff --git a/chrome/browser/notifications/notification_ui_manager_impl.h b/chrome/browser/notifications/notification_ui_manager_impl.h index 7e56336..273beea 100644 --- a/chrome/browser/notifications/notification_ui_manager_impl.h +++ b/chrome/browser/notifications/notification_ui_manager_impl.h @@ -36,6 +36,9 @@ class NotificationUIManagerImpl Profile* profile) OVERRIDE; virtual bool DoesIdExist(const std::string& notification_id) OVERRIDE; virtual bool CancelById(const std::string& notification_id) OVERRIDE; + virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( + Profile* profile, + const GURL& source) OVERRIDE; virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; virtual void CancelAll() OVERRIDE; diff --git a/chrome/browser/notifications/notification_ui_manager_mac.h b/chrome/browser/notifications/notification_ui_manager_mac.h index 6b95ee2..9286768 100644 --- a/chrome/browser/notifications/notification_ui_manager_mac.h +++ b/chrome/browser/notifications/notification_ui_manager_mac.h @@ -8,6 +8,7 @@ #import <AppKit/AppKit.h> #include <map> +#include <set> #include "base/basictypes.h" #include "base/memory/scoped_nsobject.h" @@ -33,6 +34,8 @@ class NotificationUIManagerMac : public BalloonNotificationUIManager { // NotificationUIManager: virtual void Add(const Notification& notification, Profile* profile) OVERRIDE; + virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( + Profile* profile, const GURL& source_origin) OVERRIDE; virtual bool CancelById(const std::string& notification_id) OVERRIDE; virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE; virtual bool CancelAllByProfile(Profile* profile) OVERRIDE; diff --git a/chrome/browser/notifications/notification_ui_manager_mac.mm b/chrome/browser/notifications/notification_ui_manager_mac.mm index 59339ed..0f0322b 100644 --- a/chrome/browser/notifications/notification_ui_manager_mac.mm +++ b/chrome/browser/notifications/notification_ui_manager_mac.mm @@ -11,6 +11,7 @@ #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/balloon_notification_ui_manager.h" #include "chrome/browser/notifications/message_center_notification_manager.h" +#include "chrome/browser/profiles/profile.h" #include "ui/message_center/message_center_util.h" @class NSUserNotificationCenter; @@ -161,6 +162,25 @@ void NotificationUIManagerMac::Add(const Notification& notification, } } +std::set<std::string> +NotificationUIManagerMac::GetAllIdsByProfileAndSourceOrigin( + Profile* profile, const GURL& source_origin) { + std::set<std::string> notification_ids = + BalloonNotificationUIManager::GetAllIdsByProfileAndSourceOrigin( + profile, source_origin); + + for (NotificationMap::iterator it = notification_map_.begin(); + it != notification_map_.end(); ++it) { + ControllerNotification* controller_notification = it->second; + Notification* model = controller_notification->model; + if (model->origin_url() == source_origin && + profile->IsSameProfile(controller_notification->profile)) { + notification_ids.insert(model->notification_id()); + } + } + return notification_ids; +} + bool NotificationUIManagerMac::CancelById(const std::string& notification_id) { NotificationMap::iterator it = notification_map_.find(notification_id); if (it == notification_map_.end()) diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc b/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc index 0fee623..2fc4db7 100644 --- a/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc +++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_service_unittest.cc @@ -11,6 +11,7 @@ #include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" #include "chrome/browser/notifications/sync_notifier/synced_notification.h" +#include "chrome/browser/profiles/profile.h" #include "sync/api/sync_change.h" #include "sync/api/sync_change_processor.h" #include "sync/api/sync_error_factory.h" @@ -122,6 +123,7 @@ class StubNotificationUIManager : public NotificationUIManager { OVERRIDE { // Make a deep copy of the notification that we can inspect. notification_ = notification; + profile_ = profile; } // Returns true if any notifications match the supplied ID, either currently @@ -136,6 +138,18 @@ class StubNotificationUIManager : public NotificationUIManager { return false; } + // Adds the notification_id for each outstanding notification to the set + // |notification_ids| (must not be NULL). + virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( + Profile* profile, + const GURL& source) OVERRIDE { + std::set<std::string> notification_ids; + if (source == notification_.origin_url() && + profile->IsSameProfile(profile_)) + notification_ids.insert(notification_.notification_id()); + return notification_ids; + } + // Removes notifications matching the |source_origin| (which could be an // extension ID). Returns true if anything was removed. virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE { @@ -157,6 +171,7 @@ class StubNotificationUIManager : public NotificationUIManager { private: DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); Notification notification_; + Profile* profile_; }; // Dummy SyncChangeProcessor used to help review what SyncChanges are pushed diff --git a/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc b/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc index 87810cc..6d7061d 100644 --- a/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc +++ b/chrome/browser/notifications/sync_notifier/synced_notification_unittest.cc @@ -9,6 +9,7 @@ #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/notifications/sync_notifier/synced_notification.h" +#include "chrome/browser/profiles/profile.h" #include "sync/api/sync_data.h" #include "sync/protocol/sync.pb.h" #include "sync/protocol/synced_notification_specifics.pb.h" @@ -87,6 +88,7 @@ class StubNotificationUIManager : public NotificationUIManager { OVERRIDE { // Make a deep copy of the notification that we can inspect. notification_ = notification; + profile_ = profile; } // Returns true if any notifications match the supplied ID, either currently @@ -101,6 +103,16 @@ class StubNotificationUIManager : public NotificationUIManager { return false; } + virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( + Profile* profile, + const GURL& source) OVERRIDE { + std::set<std::string> notification_ids; + if (source == notification_.origin_url() && + profile->IsSameProfile(profile_)) + notification_ids.insert(notification_.notification_id()); + return notification_ids; + } + // Removes notifications matching the |source_origin| (which could be an // extension ID). Returns true if anything was removed. virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE { @@ -122,6 +134,7 @@ class StubNotificationUIManager : public NotificationUIManager { private: DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager); Notification notification_; + Profile* profile_; }; class SyncedNotificationTest : public testing::Test { diff --git a/chrome/common/extensions/api/notifications.idl b/chrome/common/extensions/api/notifications.idl index 1b339e6..059febf 100644 --- a/chrome/common/extensions/api/notifications.idl +++ b/chrome/common/extensions/api/notifications.idl @@ -67,6 +67,8 @@ namespace notifications { callback ClearCallback = void (boolean wasCleared); + callback GetAllCallback = void (object notifications); + interface Functions { // Creates and displays a notification having the contents in |options|, // identified by the id |notificationId|. If |notificationId| is empty, @@ -89,6 +91,10 @@ namespace notifications { // corresponding notification. |callback| indicates whether a matching // notification existed. static void clear(DOMString notificationId, ClearCallback callback); + + // |callback| is executed with the set of notification_ids currently in + // the system. + static void getAll(GetAllCallback callback); }; interface Events { |