Store weak ref to Notification in ToastEventHandler
This commit is contained in:
parent
ddee77fae4
commit
f4c27c6d29
9 changed files with 32 additions and 47 deletions
|
@ -136,19 +136,12 @@ void LibnotifyNotification::Dismiss() {
|
|||
|
||||
void LibnotifyNotification::OnNotificationClosed(
|
||||
NotifyNotification* notification) {
|
||||
delegate()->NotificationClosed();
|
||||
Destroy();
|
||||
NotificationDismissed();
|
||||
}
|
||||
|
||||
void LibnotifyNotification::OnNotificationView(
|
||||
NotifyNotification* notification, char* action) {
|
||||
delegate()->NotificationClick();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void LibnotifyNotification::NotificationFailed() {
|
||||
delegate()->NotificationFailed();
|
||||
Destroy();
|
||||
NotificationClicked();
|
||||
}
|
||||
|
||||
} // namespace brightray
|
||||
|
|
|
@ -34,8 +34,6 @@ class LibnotifyNotification : public Notification {
|
|||
CHROMEG_CALLBACK_1(LibnotifyNotification, void, OnNotificationView,
|
||||
NotifyNotification*, char*);
|
||||
|
||||
void NotificationFailed();
|
||||
|
||||
NotifyNotification* notification_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(LibnotifyNotification);
|
||||
|
|
|
@ -28,8 +28,7 @@ class CocoaNotification : public Notification {
|
|||
const bool silent) override;
|
||||
void Dismiss() override;
|
||||
|
||||
void NotifyDisplayed();
|
||||
void NotifyClick();
|
||||
void NotificationDisplayed();
|
||||
|
||||
NSUserNotification* notification() const { return notification_; }
|
||||
|
||||
|
|
|
@ -58,17 +58,11 @@ void CocoaNotification::Show(const base::string16& title,
|
|||
void CocoaNotification::Dismiss() {
|
||||
[NSUserNotificationCenter.defaultUserNotificationCenter
|
||||
removeDeliveredNotification:notification_];
|
||||
delegate()->NotificationClosed();
|
||||
Destroy();
|
||||
NotificationDismissed();
|
||||
}
|
||||
|
||||
void CocoaNotification::NotifyDisplayed() {
|
||||
void CocoaNotification::NotificationDisplayed() {
|
||||
delegate()->NotificationDisplayed();
|
||||
}
|
||||
|
||||
void CocoaNotification::NotifyClick() {
|
||||
delegate()->NotificationClick();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
} // namespace brightray
|
||||
|
|
|
@ -22,14 +22,14 @@
|
|||
didDeliverNotification:(NSUserNotification*)notif {
|
||||
auto notification = presenter_->GetNotification(notif);
|
||||
if (notification)
|
||||
notification->NotifyDisplayed();
|
||||
notification->NotificationDisplayed();
|
||||
}
|
||||
|
||||
- (void)userNotificationCenter:(NSUserNotificationCenter*)center
|
||||
didActivateNotification:(NSUserNotification *)notif {
|
||||
auto notification = presenter_->GetNotification(notif);
|
||||
if (notification)
|
||||
notification->NotifyClick();
|
||||
notification->NotificationClicked();
|
||||
}
|
||||
|
||||
- (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center
|
||||
|
|
|
@ -20,6 +20,21 @@ Notification::~Notification() {
|
|||
delegate()->NotificationDestroyed();
|
||||
}
|
||||
|
||||
void Notification::NotificationClicked() {
|
||||
delegate()->NotificationClick();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void Notification::NotificationDismissed() {
|
||||
delegate()->NotificationClosed();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void Notification::NotificationFailed() {
|
||||
delegate()->NotificationFailed();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void Notification::Destroy() {
|
||||
presenter()->RemoveNotification(this);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,11 @@ class Notification {
|
|||
// notification gets closed.
|
||||
virtual void Dismiss() = 0;
|
||||
|
||||
// Should be called by derived classes.
|
||||
void NotificationClicked();
|
||||
void NotificationDismissed();
|
||||
void NotificationFailed();
|
||||
|
||||
base::WeakPtr<Notification> GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ void WindowsToastNotification::Show(
|
|||
return;
|
||||
}
|
||||
|
||||
if (FAILED(SetupCallbacks(toast_notification_.Get()))) {
|
||||
if (!SetupCallbacks(toast_notification_.Get())) {
|
||||
NotificationFailed();
|
||||
return;
|
||||
}
|
||||
|
@ -134,21 +134,6 @@ void WindowsToastNotification::Dismiss() {
|
|||
toast_notifier_->Hide(toast_notification_.Get());
|
||||
}
|
||||
|
||||
void WindowsToastNotification::NotificationClicked() {
|
||||
delegate()->NotificationClick();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void WindowsToastNotification::NotificationDismissed() {
|
||||
delegate()->NotificationClosed();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void WindowsToastNotification::NotificationFailed() {
|
||||
delegate()->NotificationFailed();
|
||||
Destroy();
|
||||
}
|
||||
|
||||
bool WindowsToastNotification::GetToastXml(
|
||||
ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager,
|
||||
const std::wstring& title,
|
||||
|
@ -390,8 +375,8 @@ bool WindowsToastNotification::RemoveCallbacks(
|
|||
/*
|
||||
/ Toast Event Handler
|
||||
*/
|
||||
ToastEventHandler::ToastEventHandler(WindowsToastNotification* notification)
|
||||
: notification_(notification) {
|
||||
ToastEventHandler::ToastEventHandler(Notification* notification)
|
||||
: notification_(notification->GetWeakPtr()) {
|
||||
}
|
||||
|
||||
ToastEventHandler::~ToastEventHandler() {
|
||||
|
|
|
@ -50,10 +50,6 @@ class WindowsToastNotification : public Notification {
|
|||
private:
|
||||
friend class ToastEventHandler;
|
||||
|
||||
void NotificationClicked();
|
||||
void NotificationDismissed();
|
||||
void NotificationFailed();
|
||||
|
||||
bool GetToastXml(ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager,
|
||||
const std::wstring& title,
|
||||
const std::wstring& msg,
|
||||
|
@ -97,7 +93,7 @@ class ToastEventHandler : public RuntimeClass<RuntimeClassFlags<ClassicCom>,
|
|||
DesktopToastDismissedEventHandler,
|
||||
DesktopToastFailedEventHandler> {
|
||||
public:
|
||||
ToastEventHandler(WindowsToastNotification* notification);
|
||||
ToastEventHandler(Notification* notification);
|
||||
~ToastEventHandler();
|
||||
|
||||
IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, IInspectable* args);
|
||||
|
@ -105,7 +101,7 @@ class ToastEventHandler : public RuntimeClass<RuntimeClassFlags<ClassicCom>,
|
|||
IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastFailedEventArgs* e);
|
||||
|
||||
private:
|
||||
WindowsToastNotification* notification_; // weak ref.
|
||||
base::WeakPtr<Notification> notification_; // weak ref.
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ToastEventHandler);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue