Sanitized notification delegate implementation
I made `brightray::NotificationDelegate` back into just an interface and extracted the implementation used by `PlatformNotificationService`, so that the main process notification implementation can inherit only the interface.
This commit is contained in:
parent
8750fde6d3
commit
f3c32647af
5 changed files with 56 additions and 70 deletions
|
@ -51,8 +51,7 @@ namespace api {
|
||||||
|
|
||||||
Notification::Notification(v8::Isolate* isolate,
|
Notification::Notification(v8::Isolate* isolate,
|
||||||
v8::Local<v8::Object> wrapper,
|
v8::Local<v8::Object> wrapper,
|
||||||
mate::Arguments* args)
|
mate::Arguments* args) {
|
||||||
: NotificationDelegate(std::string()) { // FIXME(alexeykuzmin)
|
|
||||||
InitWith(isolate, wrapper);
|
InitWith(isolate, wrapper);
|
||||||
|
|
||||||
presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter();
|
presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter();
|
||||||
|
|
|
@ -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
|
|
||||||
|
|
|
@ -7,18 +7,12 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "base/macros.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
class NotificationDelegate {
|
class NotificationDelegate {
|
||||||
public:
|
public:
|
||||||
explicit NotificationDelegate(const std::string& notification_id);
|
|
||||||
virtual ~NotificationDelegate() {}
|
|
||||||
|
|
||||||
// The native Notification object is destroyed.
|
// The native Notification object is destroyed.
|
||||||
virtual void NotificationDestroyed();
|
virtual void NotificationDestroyed() {}
|
||||||
|
|
||||||
// Failed to send the notification.
|
// Failed to send the notification.
|
||||||
virtual void NotificationFailed() {}
|
virtual void NotificationFailed() {}
|
||||||
|
@ -27,14 +21,13 @@ class NotificationDelegate {
|
||||||
virtual void NotificationReplied(const std::string& reply) {}
|
virtual void NotificationReplied(const std::string& reply) {}
|
||||||
virtual void NotificationAction(int index) {}
|
virtual void NotificationAction(int index) {}
|
||||||
|
|
||||||
virtual void NotificationClick();
|
virtual void NotificationClick() {}
|
||||||
virtual void NotificationClosed();
|
virtual void NotificationClosed() {}
|
||||||
virtual void NotificationDisplayed();
|
virtual void NotificationDisplayed() {}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
const std::string notification_id_;
|
NotificationDelegate() = default;
|
||||||
|
~NotificationDelegate() = default;
|
||||||
DISALLOW_COPY_AND_ASSIGN(NotificationDelegate);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "brightray/browser/notification.h"
|
#include "brightray/browser/notification.h"
|
||||||
#include "brightray/browser/notification_delegate.h"
|
#include "brightray/browser/notification_delegate.h"
|
||||||
#include "brightray/browser/notification_presenter.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/notification_resources.h"
|
||||||
#include "content/public/common/platform_notification_data.h"
|
#include "content/public/common/platform_notification_data.h"
|
||||||
#include "third_party/skia/include/core/SkBitmap.h"
|
#include "third_party/skia/include/core/SkBitmap.h"
|
||||||
|
@ -44,6 +45,34 @@ void OnWebNotificationAllowed(base::WeakPtr<Notification> 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
|
} // namespace
|
||||||
|
|
||||||
PlatformNotificationService::PlatformNotificationService(
|
PlatformNotificationService::PlatformNotificationService(
|
||||||
|
@ -81,8 +110,8 @@ void PlatformNotificationService::DisplayNotification(
|
||||||
auto presenter = browser_client_->GetNotificationPresenter();
|
auto presenter = browser_client_->GetNotificationPresenter();
|
||||||
if (!presenter)
|
if (!presenter)
|
||||||
return;
|
return;
|
||||||
brightray::NotificationDelegate* delegate =
|
NotificationDelegateImpl* delegate =
|
||||||
new NotificationDelegate(notification_id);
|
new NotificationDelegateImpl(notification_id);
|
||||||
auto notification = presenter->CreateNotification(delegate);
|
auto notification = presenter->CreateNotification(delegate);
|
||||||
if (notification) {
|
if (notification) {
|
||||||
*cancel_callback = base::Bind(&RemoveNotification, notification);
|
*cancel_callback = base::Bind(&RemoveNotification, notification);
|
||||||
|
|
|
@ -68,7 +68,6 @@
|
||||||
'browser/network_delegate.cc',
|
'browser/network_delegate.cc',
|
||||||
'browser/network_delegate.h',
|
'browser/network_delegate.h',
|
||||||
'browser/notification_delegate.h',
|
'browser/notification_delegate.h',
|
||||||
'browser/notification_delegate.cc',
|
|
||||||
'browser/notification_presenter.cc',
|
'browser/notification_presenter.cc',
|
||||||
'browser/notification_presenter.h',
|
'browser/notification_presenter.h',
|
||||||
'browser/notification.cc',
|
'browser/notification.cc',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue