| Index: trunk/src/chrome/browser/extensions/api/notifications/notifications_api.cc
|
| ===================================================================
|
| --- trunk/src/chrome/browser/extensions/api/notifications/notifications_api.cc (revision 202763)
|
| +++ trunk/src/chrome/browser/extensions/api/notifications/notifications_api.cc (working copy)
|
| @@ -29,23 +29,6 @@
|
|
|
| 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,
|
| @@ -63,6 +46,13 @@
|
| 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 {
|
| @@ -145,7 +135,10 @@
|
| // 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.
|
| - return GetExtension()->is_platform_app() || GetExtension()->is_extension();
|
| + if (!(GetExtension()->is_platform_app() || GetExtension()->is_extension()))
|
| + return false;
|
| +
|
| + return true;
|
| }
|
|
|
| NotificationsApiFunction::NotificationsApiFunction() {
|
| @@ -340,8 +333,9 @@
|
| params_ = api::notifications::Update::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params_.get());
|
|
|
| - if (g_browser_process->notification_ui_manager()->DoesIdExist(
|
| - CreateScopedIdentifier(extension_->id(), params_->notification_id))) {
|
| + if (g_browser_process->notification_ui_manager()->
|
| + DoesIdExist(NotificationsApiDelegate::CreateScopedIdentifier(
|
| + extension_->id(), params_->notification_id))) {
|
| CreateNotification(params_->notification_id, ¶ms_->options);
|
| SetResult(Value::CreateBooleanValue(true));
|
| } else {
|
| @@ -363,8 +357,9 @@
|
| params_ = api::notifications::Clear::Params::Create(*args_);
|
| EXTENSION_FUNCTION_VALIDATE(params_.get());
|
|
|
| - bool cancel_result = g_browser_process->notification_ui_manager()->CancelById(
|
| - CreateScopedIdentifier(extension_->id(), params_->notification_id));
|
| + bool cancel_result = g_browser_process->notification_ui_manager()->
|
| + CancelById(NotificationsApiDelegate::CreateScopedIdentifier(
|
| + extension_->id(), params_->notification_id));
|
|
|
| SetResult(Value::CreateBooleanValue(cancel_result));
|
| SendResponse(true);
|
| @@ -372,29 +367,4 @@
|
| 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
|
|
|