Add an abstract Notification class
This commit is contained in:
parent
41084883cf
commit
9897f3aab0
5 changed files with 47 additions and 15 deletions
|
@ -10,16 +10,15 @@
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#include "base/mac/scoped_nsobject.h"
|
#include "base/mac/scoped_nsobject.h"
|
||||||
#include "base/memory/weak_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "base/strings/string16.h"
|
#include "browser/notification.h"
|
||||||
#include "content/public/browser/desktop_notification_delegate.h"
|
#include "content/public/browser/desktop_notification_delegate.h"
|
||||||
|
|
||||||
@class NotificationDelegate;
|
@class NotificationDelegate;
|
||||||
class SkBitmap;
|
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
class CocoaNotification {
|
class CocoaNotification : public Notification {
|
||||||
public:
|
public:
|
||||||
static CocoaNotification* FromNSNotification(
|
static CocoaNotification* FromNSNotification(
|
||||||
NSUserNotification* notification);
|
NSUserNotification* notification);
|
||||||
|
@ -30,24 +29,18 @@ class CocoaNotification {
|
||||||
|
|
||||||
void ShowNotification(const base::string16& title,
|
void ShowNotification(const base::string16& title,
|
||||||
const base::string16& msg,
|
const base::string16& msg,
|
||||||
const SkBitmap& icon);
|
const SkBitmap& icon) override;
|
||||||
void DismissNotification();
|
void DismissNotification() override;
|
||||||
|
|
||||||
void NotifyDisplayed();
|
void NotifyDisplayed();
|
||||||
void NotifyClick();
|
void NotifyClick();
|
||||||
|
|
||||||
base::WeakPtr<CocoaNotification> GetWeakPtr() {
|
|
||||||
return weak_factory_.GetWeakPtr();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void Cleanup();
|
static void Cleanup();
|
||||||
|
|
||||||
scoped_ptr<content::DesktopNotificationDelegate> delegate_;
|
scoped_ptr<content::DesktopNotificationDelegate> delegate_;
|
||||||
base::scoped_nsobject<NSUserNotification> notification_;
|
base::scoped_nsobject<NSUserNotification> notification_;
|
||||||
|
|
||||||
base::WeakPtrFactory<CocoaNotification> weak_factory_;
|
|
||||||
|
|
||||||
static base::scoped_nsobject<NotificationDelegate> notification_delegate_;
|
static base::scoped_nsobject<NotificationDelegate> notification_delegate_;
|
||||||
static std::set<CocoaNotification*> notifications_;
|
static std::set<CocoaNotification*> notifications_;
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,7 @@ void CocoaNotification::Cleanup() {
|
||||||
|
|
||||||
CocoaNotification::CocoaNotification(
|
CocoaNotification::CocoaNotification(
|
||||||
scoped_ptr<content::DesktopNotificationDelegate> delegate)
|
scoped_ptr<content::DesktopNotificationDelegate> delegate)
|
||||||
: delegate_(delegate.Pass()),
|
: delegate_(delegate.Pass()) {
|
||||||
weak_factory_(this) {
|
|
||||||
if (!notification_delegate_) {
|
if (!notification_delegate_) {
|
||||||
notification_delegate_.reset([[NotificationDelegate alloc] init]);
|
notification_delegate_.reset([[NotificationDelegate alloc] init]);
|
||||||
NSUserNotificationCenter.defaultUserNotificationCenter.delegate =
|
NSUserNotificationCenter.defaultUserNotificationCenter.delegate =
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace brightray {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void RemoveNotification(base::WeakPtr<CocoaNotification> notification) {
|
void RemoveNotification(base::WeakPtr<Notification> notification) {
|
||||||
if (notification)
|
if (notification)
|
||||||
notification->DismissNotification();
|
notification->DismissNotification();
|
||||||
}
|
}
|
||||||
|
|
39
brightray/browser/notification.h
Normal file
39
brightray/browser/notification.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
// 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 BROWSER_NOTIFICATION_H_
|
||||||
|
#define BROWSER_NOTIFICATION_H_
|
||||||
|
|
||||||
|
#include "base/memory/weak_ptr.h"
|
||||||
|
#include "base/strings/string16.h"
|
||||||
|
|
||||||
|
class SkBitmap;
|
||||||
|
|
||||||
|
namespace brightray {
|
||||||
|
|
||||||
|
class Notification {
|
||||||
|
public:
|
||||||
|
Notification() : weak_factory_(this) {}
|
||||||
|
|
||||||
|
virtual void ShowNotification(const base::string16& title,
|
||||||
|
const base::string16& msg,
|
||||||
|
const SkBitmap& icon) = 0;
|
||||||
|
virtual void DismissNotification() = 0;
|
||||||
|
|
||||||
|
base::WeakPtr<Notification> GetWeakPtr() {
|
||||||
|
return weak_factory_.GetWeakPtr();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual ~Notification() {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
base::WeakPtrFactory<Notification> weak_factory_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(Notification);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace brightray
|
||||||
|
|
||||||
|
#endif // BROWSER_NOTIFICATION_H_
|
|
@ -61,6 +61,7 @@
|
||||||
'browser/network_delegate.cc',
|
'browser/network_delegate.cc',
|
||||||
'browser/network_delegate.h',
|
'browser/network_delegate.h',
|
||||||
'browser/notification_presenter.h',
|
'browser/notification_presenter.h',
|
||||||
|
'browser/notification.h',
|
||||||
'browser/permission_manager.cc',
|
'browser/permission_manager.cc',
|
||||||
'browser/permission_manager.h',
|
'browser/permission_manager.h',
|
||||||
'browser/platform_notification_service_impl.cc',
|
'browser/platform_notification_service_impl.cc',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue