From c4e3e0ced1a05cb22d4edb6408f87657cba67a46 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 1 Jul 2020 15:47:13 -0700 Subject: [PATCH] fix: ensure notification close takes effect --- .../chromium/notification_provenance.patch | 19 +++++++++++++++++++ .../notifications/mac/cocoa_notification.mm | 15 +++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/patches/chromium/notification_provenance.patch b/patches/chromium/notification_provenance.patch index 8977d1b1e214d..b4f39d64dda75 100644 --- a/patches/chromium/notification_provenance.patch +++ b/patches/chromium/notification_provenance.patch @@ -165,3 +165,22 @@ index 6d108f9884f7e8f608b70ec33d286a06346e7456..4650a01c2d090c5957eb7a7e21f12448 const std::string& notification_id, const GURL& origin, const blink::PlatformNotificationData& notification_data, +diff --git a/third_party/blink/renderer/modules/notifications/notification.cc b/third_party/blink/renderer/modules/notifications/notification.cc +index 9249243e98bd918be5ff3c07b92a2a91c79307e8..5ff350c0c71deb52c7e674dfeaa4b8fd9a276d8b 100644 +--- a/third_party/blink/renderer/modules/notifications/notification.cc ++++ b/third_party/blink/renderer/modules/notifications/notification.cc +@@ -130,12 +130,8 @@ Notification* Notification::Create(ExecutionContext* context, + + // TODO(https://crbug.com/595685): Make |token| a constructor parameter + // once persistent notifications have been mojofied too. +- if (notification->tag().IsNull() || notification->tag().IsEmpty()) { +- auto unguessable_token = base::UnguessableToken::Create(); +- notification->SetToken(unguessable_token.ToString().c_str()); +- } else { +- notification->SetToken(notification->tag()); +- } ++ auto unguessable_token = base::UnguessableToken::Create(); ++ notification->SetToken(unguessable_token.ToString().c_str()); + + notification->SchedulePrepareShow(); + diff --git a/shell/browser/notifications/mac/cocoa_notification.mm b/shell/browser/notifications/mac/cocoa_notification.mm index b4be60027323f..6e18a30f1fd23 100644 --- a/shell/browser/notifications/mac/cocoa_notification.mm +++ b/shell/browser/notifications/mac/cocoa_notification.mm @@ -105,15 +105,16 @@ } void CocoaNotification::Dismiss() { - if (notification_) + if (notification_) { [NSUserNotificationCenter.defaultUserNotificationCenter removeDeliveredNotification:notification_]; - NotificationDismissed(); + NotificationDismissed(); - this->LogAction("dismissed"); + this->LogAction("dismissed"); - notification_.reset(nil); + notification_.reset(nil); + } } void CocoaNotification::NotificationDisplayed() { @@ -165,8 +166,10 @@ void CocoaNotification::LogAction(const char* action) { if (getenv("ELECTRON_DEBUG_NOTIFICATIONS")) { NSString* identifier = [notification_ valueForKey:@"identifier"]; - LOG(INFO) << "Notification " << action << " (" << [identifier UTF8String] - << ")"; + if (identifier) { + LOG(INFO) << "Notification " << action << " (" << [identifier UTF8String] + << ")"; + } } }