Bug 1930676 - Part 7: Implement NotificationChild::FrozenCallback r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D228897
This commit is contained in:
Kagami Sascha Rosylight
2024-11-15 00:35:43 +00:00
parent be3d7d1489
commit 5301a3d17a
2 changed files with 26 additions and 3 deletions

View File

@@ -15,15 +15,24 @@ namespace mozilla::dom::notification {
using IPCResult = mozilla::ipc::IPCResult;
NS_IMPL_ISUPPORTS(NotificationChild, nsISupports);
NotificationChild::NotificationChild(Notification* aNonPersistentNotification,
WindowGlobalChild* aWindow)
: mNonPersistentNotification(aNonPersistentNotification),
mWindow(aWindow) {}
: mNonPersistentNotification(aNonPersistentNotification), mWindow(aWindow) {
if (mWindow) {
BindToOwner(mWindow->GetWindowGlobal()->AsGlobal());
return;
}
}
// Step 2 of https://notifications.spec.whatwg.org/#activating-a-notification
// MOZ_CAN_RUN_SCRIPT_BOUNDARY because of DispatchEvent (boundary for now, bug
// 1748910) and FocusWindow.
// Bug 1539864 for IPDL not able to handle MOZ_CAN_RUN_SCRIPT.
//
// Note that FrozenCallback below makes sure we don't do anything here on
// bfcached page.
MOZ_CAN_RUN_SCRIPT_BOUNDARY IPCResult NotificationChild::RecvNotifyClick() {
// Step 2.1: Let intoFocus be the result of firing an event named click on the
// Notification object representing notification, with its cancelable
@@ -64,4 +73,14 @@ void NotificationChild::ActorDestroy(ActorDestroyReason aWhy) {
}
}
void NotificationChild::FrozenCallback(nsIGlobalObject* aOwner) {
// Make sure the closure below won't dispatch close event and still allow
// explicit close() call.
mNonPersistentNotification = nullptr;
// Closing on FrozenCallback makes sure that clicking the notification opens a
// new tab instead of pinging an inactive tab
Close();
DisconnectFreezeObserver();
}
} // namespace mozilla::dom::notification

View File

@@ -7,8 +7,10 @@
#ifndef DOM_NOTIFICATION_NOTIFICATIONCHILD_H_
#define DOM_NOTIFICATION_NOTIFICATIONCHILD_H_
#include "mozilla/GlobalFreezeObserver.h"
#include "mozilla/WeakPtr.h"
#include "mozilla/dom/notification/PNotificationChild.h"
#include "nsISupportsImpl.h"
namespace mozilla::dom {
class Notification;
@@ -18,10 +20,11 @@ class WindowGlobalChild;
namespace mozilla::dom::notification {
class NotificationChild final : public PNotificationChild,
public GlobalFreezeObserver,
public SupportsWeakPtr {
using IPCResult = mozilla::ipc::IPCResult;
NS_INLINE_DECL_REFCOUNTING(NotificationChild)
NS_DECL_ISUPPORTS
public:
explicit NotificationChild(Notification* aNonPersistentNotification,
@@ -30,6 +33,7 @@ class NotificationChild final : public PNotificationChild,
IPCResult RecvNotifyClick();
void ActorDestroy(ActorDestroyReason aWhy) override;
void FrozenCallback(nsIGlobalObject* aOwner) override;
private:
~NotificationChild() = default;