Chromium Code Reviews| Index: chrome/browser/extensions/api/notifications/notifications_api.cc |
| diff --git a/chrome/browser/extensions/api/notifications/notifications_api.cc b/chrome/browser/extensions/api/notifications/notifications_api.cc |
| index e45df6fe653d139f5444fe48f5e6f00d1586143b..9df28d516d3c5fe6e1a05b3fc88ba74dbeeeca9d 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 { |
| @@ -130,10 +140,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() { |
| @@ -330,9 +337,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 { |
| @@ -354,9 +360,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); |
| @@ -364,4 +369,30 @@ bool NotificationsClearFunction::RunNotificationsApi() { |
| return true; |
| } |
| +NotificationsGetAllFunction::NotificationsGetAllFunction() {} |
| + |
| +NotificationsGetAllFunction::~NotificationsGetAllFunction() {} |
| + |
| +bool NotificationsGetAllFunction::RunNotificationsApi() { |
| + std::set<std::string> notification_ids; |
| + NotificationUIManager* notification_ui_manager = |
| + g_browser_process->notification_ui_manager(); |
| + notification_ui_manager->GetAllIdsByProfileAndSourceOrigin( |
| + profile_, extension_->url(), ¬ification_ids); |
| + |
| + scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
| + |
| + for (std::set<std::string>::iterator iter = notification_ids.begin(); |
| + iter != notification_ids.end(); |
| + iter++) { |
|
Dmitry Titov
2013/05/16 20:39:15
nit: Most often, this loop is split in 2 lines, no
dewittj
2013/05/16 23:40:34
ALL HAIL CLANG-FORMAT-DIFF
|
| + result->SetBooleanWithoutPathExpansion( |
| + StripScopeFromIdentifier(extension_->id(), *iter), true); |
|
Dmitry Titov
2013/05/16 20:39:15
Just a note: this makes me think we might want to
dewittj
2013/05/16 23:40:34
I agree, but it is indeed better done in a separat
|
| + } |
| + |
| + SetResult(result.release()); |
| + SendResponse(true); |
| + |
| + return true; |
| +} |
| + |
| } // namespace extensions |