Create a new tab when the user activates orphaned non-persistent notifications
The ability to respond to activations of non-persistent notification
relies on the originating document to stay alive. Once the document (or
tab) closes, the associated JavaScript event handler can no longer be
invoked.
This is by design, because certain kinds of notifications are largely
informative and should not be missed because the tab goes away. Calendar
reminders are an example of this. However, it also means that clicking
on the notification doesn't do anything.
Starting with this CL, clicking on such a notification will create a new
tab for the originating origin. The notification that was activated will
be closed as the user explicitly acknowledged it, too.
Bug: 442141
Change-Id: I44ed2f943c747aae4c9f589b1fee2e488aeaa5e0
Reviewed-on: https://chromium-review.googlesource.com/1057631
Reviewed-by: Avi Drissman <[email protected]>
Reviewed-by: Anita Woodruff <[email protected]>
Reviewed-by: Tom Sepez <[email protected]>
Commit-Queue: Peter Beverloo <[email protected]>
Cr-Commit-Position: refs/heads/master@{#562123}
diff --git a/chrome/browser/notifications/non_persistent_notification_handler.h b/chrome/browser/notifications/non_persistent_notification_handler.h
index 8e7025a..ba5b3a81 100644
--- a/chrome/browser/notifications/non_persistent_notification_handler.h
+++ b/chrome/browser/notifications/non_persistent_notification_handler.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_NOTIFICATIONS_NON_PERSISTENT_NOTIFICATION_HANDLER_H_
#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
#include "chrome/browser/notifications/notification_handler.h"
// NotificationHandler implementation for non persistent notifications.
@@ -31,6 +32,18 @@
void OpenSettings(Profile* profile, const GURL& origin) override;
private:
+ // Called when the "click" event for non-persistent notification has been
+ // dispatched. The |success| boolean indicates whether the click could be
+ // delivered to the originating document as a JavaScript event.
+ void DidDispatchClickEvent(Profile* profile,
+ const GURL& origin,
+ const std::string& notification_id,
+ base::OnceClosure completed_closure,
+ bool success);
+
+ base::WeakPtrFactory<NonPersistentNotificationHandler> weak_ptr_factory_{
+ this};
+
DISALLOW_COPY_AND_ASSIGN(NonPersistentNotificationHandler);
};