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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/notifications/in_page_notification_handler.h"
6 #include "chrome/browser/notifications/notification.h"
7 #include "chrome/browser/notifications/notification_delegate.h"
8 #include "chrome/browser/notifications/platform_notification_service_impl.h"
9
10 InPageNotificationHandler::InPageNotificationHandler() {}
11 InPageNotificationHandler::~InPageNotificationHandler() {}
12
13 void InPageNotificationHandler::HandleNotificationOperation(
14 notification_operation_common::NotificationOperation operation,
15 Profile* profile,
16 const std::string& origin,
17 const std::string& notification_id,
18 int action_index) {
19 if (notifications_.find(notification_id) != notifications_.end()) {
20 switch (operation) {
21 case notification_operation_common::NOTIFICATION_CLICK:
22 notifications_[notification_id]->delegate()->Click();
23 break;
24 case notification_operation_common::NOTIFICATION_CLOSE:
25 notifications_[notification_id]->delegate()->Close(true /* by user */);
26 notifications_.erase(notification_id);
27 break;
28 case notification_operation_common::NOTIFICATION_SETTINGS:
29 notification_operation_common::OpenNotificationSettings(profile);
30 break;
31 }
32 }
33 }
34
35 void InPageNotificationHandler::RegisterNotification(
36 const std::string& notification_id,
37 std::unique_ptr<Notification> notification) {
38 DCHECK_EQ(notifications_.count(notification_id), 0u);
39 notifications_[notification_id] = std::move(notification);
40 }
41
42 void InPageNotificationHandler::CloseNotification(
43 Profile* profile,
44 const std::string& notification_id) {
45 if (notifications_.find(notification_id) != notifications_.end()) {
46 notifications_[notification_id]->delegate()->Close(false /* by user */);
47 notifications_.erase(notification_id);
48 }
49 }
50
51 notification_operation_common::NotificationHandlerType
52 InPageNotificationHandler::NotificationType() {
53 return notification_operation_common::INPAGE_NOTIFICATION;
54 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698