FIXME: DesktopNotificationDelegate has been removed

Related CL: https://codereview.chromium.org/2906883003
This commit is contained in:
Tony Ganch 2017-08-17 18:19:14 +02:00 committed by Cheng Zhao
parent fe431a9e58
commit f694b64d71
8 changed files with 57 additions and 84 deletions

View file

@ -49,7 +49,8 @@ namespace api {
Notification::Notification(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper,
mate::Arguments* args) {
mate::Arguments* args)
: NotificationDelegate(std::string()) { // FIXME(alexeykuzmin)
InitWith(isolate, wrapper);
presenter_ = brightray::BrowserClient::Get()->GetNotificationPresenter();

View file

@ -0,0 +1,34 @@
// 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

View file

@ -7,14 +7,18 @@
#include <string>
#include "content/public/browser/desktop_notification_delegate.h"
#include "base/macros.h"
namespace brightray {
class NotificationDelegate : public content::DesktopNotificationDelegate {
class NotificationDelegate {
public:
explicit NotificationDelegate(const std::string& notification_id);
virtual ~NotificationDelegate() {}
// The native Notification object is destroyed.
virtual void NotificationDestroyed() {}
virtual void NotificationDestroyed();
// Failed to send the notification.
virtual void NotificationFailed() {}
@ -22,6 +26,15 @@ class NotificationDelegate : public content::DesktopNotificationDelegate {
// 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

View file

@ -1,33 +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_adapter.h"
namespace brightray {
NotificationDelegateAdapter::NotificationDelegateAdapter(
std::unique_ptr<content::DesktopNotificationDelegate> delegate)
: delegate_(std::move(delegate)) {
}
NotificationDelegateAdapter::~NotificationDelegateAdapter() {
}
void NotificationDelegateAdapter::NotificationDestroyed() {
delete this;
}
void NotificationDelegateAdapter::NotificationDisplayed() {
delegate_->NotificationDisplayed();
}
void NotificationDelegateAdapter::NotificationClosed() {
delegate_->NotificationClosed();
}
void NotificationDelegateAdapter::NotificationClick() {
delegate_->NotificationClick();
}
} // namespace brightray

View file

@ -1,38 +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.
#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_DELEGATE_ADAPTER_H_
#define BRIGHTRAY_BROWSER_NOTIFICATION_DELEGATE_ADAPTER_H_
#include <memory>
#include "base/macros.h"
#include "brightray/browser/notification_delegate.h"
namespace brightray {
// Adapt the content::DesktopNotificationDelegate to NotificationDelegate.
class NotificationDelegateAdapter : public NotificationDelegate {
public:
explicit NotificationDelegateAdapter(
std::unique_ptr<content::DesktopNotificationDelegate> delegate);
~NotificationDelegateAdapter() override;
// NotificationDelegate:
void NotificationDestroyed() override;
// content::DesktopNotificationDelegate:
void NotificationDisplayed() override;
void NotificationClosed() override;
void NotificationClick() override;
private:
std::unique_ptr<content::DesktopNotificationDelegate> delegate_;
DISALLOW_COPY_AND_ASSIGN(NotificationDelegateAdapter);
};
} // namespace brightray
#endif // BRIGHTRAY_BROWSER_NOTIFICATION_DELEGATE_ADAPTER_H_

View file

@ -7,7 +7,7 @@
#include "base/strings/utf_string_conversions.h"
#include "brightray/browser/browser_client.h"
#include "brightray/browser/notification.h"
#include "brightray/browser/notification_delegate_adapter.h"
#include "brightray/browser/notification_delegate.h"
#include "brightray/browser/notification_presenter.h"
#include "content/public/common/notification_resources.h"
#include "content/public/common/platform_notification_data.h"
@ -77,16 +77,14 @@ void PlatformNotificationService::DisplayNotification(
const GURL& origin,
const content::PlatformNotificationData& notification_data,
const content::NotificationResources& notification_resources,
std::unique_ptr<content::DesktopNotificationDelegate> delegate,
base::Closure* cancel_callback) {
auto presenter = browser_client_->GetNotificationPresenter();
if (!presenter)
return;
std::unique_ptr<NotificationDelegateAdapter> adapter(
new NotificationDelegateAdapter(std::move(delegate)));
auto notification = presenter->CreateNotification(adapter.get());
brightray::NotificationDelegate* delegate =
new NotificationDelegate(notification_id);
auto notification = presenter->CreateNotification(delegate);
if (notification) {
ignore_result(adapter.release()); // it will release itself automatically.
*cancel_callback = base::Bind(&RemoveNotification, notification);
browser_client_->WebNotificationAllowed(
render_process_id_, base::Bind(&OnWebNotificationAllowed, notification,

View file

@ -37,7 +37,6 @@ class PlatformNotificationService
const GURL& origin,
const content::PlatformNotificationData& notification_data,
const content::NotificationResources& notification_resources,
std::unique_ptr<content::DesktopNotificationDelegate> delegate,
base::Closure* cancel_callback) override;
void DisplayPersistentNotification(
content::BrowserContext* browser_context,

View file

@ -68,8 +68,7 @@
'browser/network_delegate.cc',
'browser/network_delegate.h',
'browser/notification_delegate.h',
'browser/notification_delegate_adapter.cc',
'browser/notification_delegate_adapter.h',
'browser/notification_delegate.cc',
'browser/notification_presenter.cc',
'browser/notification_presenter.h',
'browser/notification.cc',