Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/notifications/non_persistent_notification_handler.h" | 5 #include "chrome/browser/notifications/non_persistent_notification_handler.h" |
| 6 | 6 |
| 7 #include "base/strings/nullable_string16.h" | 7 #include "base/strings/nullable_string16.h" |
| 8 #include "chrome/browser/notifications/notification_delegate.h" | |
| 9 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 8 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 9 #include "content/public/browser/notification_event_dispatcher.h" | |
| 10 | 10 |
| 11 NonPersistentNotificationHandler::NonPersistentNotificationHandler() = default; | 11 NonPersistentNotificationHandler::NonPersistentNotificationHandler() = default; |
| 12 NonPersistentNotificationHandler::~NonPersistentNotificationHandler() = default; | 12 NonPersistentNotificationHandler::~NonPersistentNotificationHandler() = default; |
| 13 | 13 |
| 14 void NonPersistentNotificationHandler::OnClose( | 14 void NonPersistentNotificationHandler::OnClose( |
| 15 Profile* profile, | 15 Profile* profile, |
| 16 const std::string& origin, | 16 const std::string& origin, |
| 17 const std::string& notification_id, | 17 const std::string& notification_id, |
| 18 bool by_user) { | 18 bool by_user) { |
| 19 if (notifications_.find(notification_id) != notifications_.end()) { | 19 content::NotificationEventDispatcher::GetInstance() |
| 20 notifications_[notification_id]->Close(by_user); | 20 ->DispatchNonPersistentCloseEvent(notification_id); |
| 21 notifications_.erase(notification_id); | |
| 22 } | |
| 23 } | 21 } |
| 24 | 22 |
| 25 void NonPersistentNotificationHandler::OnClick( | 23 void NonPersistentNotificationHandler::OnClick( |
|
Peter Beverloo
2017/05/31 17:52:42
Should OnShow() be added to the handlers?
Miguel Garcia
2017/06/01 17:00:53
Not sure I get this, what would OnShow do?
Peter Beverloo
2017/06/01 17:56:27
You're now special casing non-persistent notificat
| |
| 26 Profile* profile, | 24 Profile* profile, |
| 27 const std::string& origin, | 25 const std::string& origin, |
| 28 const std::string& notification_id, | 26 const std::string& notification_id, |
| 29 int action_index, | 27 int action_index, |
| 30 const base::NullableString16& reply) { | 28 const base::NullableString16& reply) { |
| 31 DCHECK(reply.is_null()); | 29 DCHECK(reply.is_null()); |
| 32 | 30 |
| 33 if (notifications_.find(notification_id) != notifications_.end()) { | 31 // Non persistent notifications don't allow buttons. |
|
Peter Beverloo
2017/05/31 17:52:42
nit: refer to https://notifications.spec.whatwg.or
Miguel Garcia
2017/06/01 17:00:53
Done.
| |
| 34 if (action_index >= 0) | 32 DCHECK_EQ(-1, action_index); |
| 35 notifications_[notification_id]->ButtonClick(action_index); | 33 |
| 36 else | 34 content::NotificationEventDispatcher::GetInstance() |
| 37 notifications_[notification_id]->Click(); | 35 ->DispatchNonPersistentClickEvent(notification_id); |
| 38 } | |
| 39 } | 36 } |
| 40 | 37 |
| 41 void NonPersistentNotificationHandler::OpenSettings(Profile* profile) { | 38 void NonPersistentNotificationHandler::OpenSettings(Profile* profile) { |
| 42 NotificationCommon::OpenNotificationSettings(profile); | 39 NotificationCommon::OpenNotificationSettings(profile); |
| 43 } | 40 } |
| 44 | |
| 45 void NonPersistentNotificationHandler::RegisterNotification( | |
| 46 const std::string& notification_id, | |
| 47 NotificationDelegate* delegate) { | |
| 48 notifications_[notification_id] = | |
| 49 scoped_refptr<NotificationDelegate>(delegate); | |
| 50 } | |
| OLD | NEW |