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

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

Issue 2093953002: Introduce a new API to handle native notification clicks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/in_page_notification_handler.cc
diff --git a/chrome/browser/notifications/in_page_notification_handler.cc b/chrome/browser/notifications/in_page_notification_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b1a52c1a8a37c17a135977ad8891361a06c9cb6a
--- /dev/null
+++ b/chrome/browser/notifications/in_page_notification_handler.cc
@@ -0,0 +1,54 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/notifications/in_page_notification_handler.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/notifications/notification_delegate.h"
+#include "chrome/browser/notifications/platform_notification_service_impl.h"
+
+InPageNotificationHandler::InPageNotificationHandler() {}
+InPageNotificationHandler::~InPageNotificationHandler() {}
+
+void InPageNotificationHandler::HandleNotificationOperation(
+ notification_operation_common::NotificationOperation operation,
+ Profile* profile,
+ const std::string& origin,
+ const std::string& notification_id,
+ int action_index) {
+ if (notifications_.find(notification_id) != notifications_.end()) {
+ switch (operation) {
+ case notification_operation_common::NOTIFICATION_CLICK:
+ notifications_[notification_id]->delegate()->Click();
+ break;
+ case notification_operation_common::NOTIFICATION_CLOSE:
+ notifications_[notification_id]->delegate()->Close(true /* by user */);
+ notifications_.erase(notification_id);
+ break;
+ case notification_operation_common::NOTIFICATION_SETTINGS:
+ notification_operation_common::OpenNotificationSettings(profile);
+ break;
+ }
+ }
+}
+
+void InPageNotificationHandler::RegisterNotification(
+ const std::string& notification_id,
+ std::unique_ptr<Notification> notification) {
+ DCHECK_EQ(notifications_.count(notification_id), 0u);
+ notifications_[notification_id] = std::move(notification);
+}
+
+void InPageNotificationHandler::CloseNotification(
+ Profile* profile,
+ const std::string& notification_id) {
+ if (notifications_.find(notification_id) != notifications_.end()) {
+ notifications_[notification_id]->delegate()->Close(false /* by user */);
+ notifications_.erase(notification_id);
+ }
+}
+
+notification_operation_common::NotificationHandlerType
+InPageNotificationHandler::NotificationType() {
+ return notification_operation_common::INPAGE_NOTIFICATION;
+}

Powered by Google App Engine
This is Rietveld 408576698