diff --git a/atom/browser/api/atom_api_notification.cc b/atom/browser/api/atom_api_notification.cc index 681f5842b8c8..9bb24df93a6d 100644 --- a/atom/browser/api/atom_api_notification.cc +++ b/atom/browser/api/atom_api_notification.cc @@ -51,8 +51,7 @@ namespace api { Notification::Notification(v8::Isolate* isolate, v8::Local wrapper, - mate::Arguments* args) - : NotificationDelegate(std::string()) { // FIXME(alexeykuzmin) + mate::Arguments* args) { InitWith(isolate, wrapper); presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter(); diff --git a/brightray/browser/notification_delegate.cc b/brightray/browser/notification_delegate.cc deleted file mode 100644 index 4e88b4450c7c..000000000000 --- a/brightray/browser/notification_delegate.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2015 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#include "brightray/browser/notification_delegate.h" -#include "content/public/browser/notification_event_dispatcher.h" - -namespace brightray { - -NotificationDelegate::NotificationDelegate(const std::string& notification_id) - : notification_id_(notification_id) { -} - -void NotificationDelegate::NotificationDestroyed() { - delete this; -} - -void NotificationDelegate::NotificationClick() { - content::NotificationEventDispatcher::GetInstance() - ->DispatchNonPersistentClickEvent(notification_id_); -} - -void NotificationDelegate::NotificationClosed() { - content::NotificationEventDispatcher::GetInstance() - ->DispatchNonPersistentCloseEvent(notification_id_); -} - -void NotificationDelegate::NotificationDisplayed() { - content::NotificationEventDispatcher::GetInstance() - ->DispatchNonPersistentShowEvent(notification_id_); -} - -} // namespace brightray - diff --git a/brightray/browser/notification_delegate.h b/brightray/browser/notification_delegate.h index 3bd98dd76dc7..77264980fd88 100644 --- a/brightray/browser/notification_delegate.h +++ b/brightray/browser/notification_delegate.h @@ -7,36 +7,29 @@ #include -#include "base/macros.h" +namespace brightray { + +class NotificationDelegate { + public: + // The native Notification object is destroyed. + virtual void NotificationDestroyed() {} + + // Failed to send the notification. + virtual void NotificationFailed() {} + + // Notification was replied to + virtual void NotificationReplied(const std::string& reply) {} + virtual void NotificationAction(int index) {} + virtual void NotificationClick() {} + virtual void NotificationClosed() {} + virtual void NotificationDisplayed() {} -namespace brightray { - -class NotificationDelegate { - public: - explicit NotificationDelegate(const std::string& notification_id); - virtual ~NotificationDelegate() {} - - // The native Notification object is destroyed. - virtual void NotificationDestroyed(); - - // Failed to send the notification. - virtual void NotificationFailed() {} - - // Notification was replied to - virtual void NotificationReplied(const std::string& reply) {} - virtual void NotificationAction(int index) {} - - virtual void NotificationClick(); - virtual void NotificationClosed(); - virtual void NotificationDisplayed(); - - private: - const std::string notification_id_; - - DISALLOW_COPY_AND_ASSIGN(NotificationDelegate); -}; - -} // namespace brightray - -#endif // BRIGHTRAY_BROWSER_NOTIFICATION_DELEGATE_H_ + protected: + NotificationDelegate() = default; + ~NotificationDelegate() = default; +}; + +} // namespace brightray + +#endif // BRIGHTRAY_BROWSER_NOTIFICATION_DELEGATE_H_ diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 190075abee07..fa0f0e50fd79 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -9,6 +9,7 @@ #include "brightray/browser/notification.h" #include "brightray/browser/notification_delegate.h" #include "brightray/browser/notification_presenter.h" +#include "content/public/browser/notification_event_dispatcher.h" #include "content/public/common/notification_resources.h" #include "content/public/common/platform_notification_data.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -44,6 +45,34 @@ void OnWebNotificationAllowed(base::WeakPtr notification, } } +class NotificationDelegateImpl : public brightray::NotificationDelegate { + public: + explicit NotificationDelegateImpl(const std::string& notification_id) + : notification_id_(notification_id) {} + + void NotificationDestroyed() override { delete this; } + + void NotificationClick() override { + content::NotificationEventDispatcher::GetInstance() + ->DispatchNonPersistentClickEvent(notification_id_); + } + + void NotificationClosed() override { + content::NotificationEventDispatcher::GetInstance() + ->DispatchNonPersistentCloseEvent(notification_id_); + } + + void NotificationDisplayed() override { + content::NotificationEventDispatcher::GetInstance() + ->DispatchNonPersistentShowEvent(notification_id_); + } + + private: + std::string notification_id_; + + DISALLOW_COPY_AND_ASSIGN(NotificationDelegateImpl); +}; + } // namespace PlatformNotificationService::PlatformNotificationService( @@ -81,8 +110,8 @@ void PlatformNotificationService::DisplayNotification( auto presenter = browser_client_->GetNotificationPresenter(); if (!presenter) return; - brightray::NotificationDelegate* delegate = - new NotificationDelegate(notification_id); + NotificationDelegateImpl* delegate = + new NotificationDelegateImpl(notification_id); auto notification = presenter->CreateNotification(delegate); if (notification) { *cancel_callback = base::Bind(&RemoveNotification, notification); diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 846837d8c79e..0c6efa3a7f01 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -68,7 +68,6 @@ 'browser/network_delegate.cc', 'browser/network_delegate.h', 'browser/notification_delegate.h', - 'browser/notification_delegate.cc', 'browser/notification_presenter.cc', 'browser/notification_presenter.h', 'browser/notification.cc',