Bug 1930676 - Part 7: Implement NotificationChild::FrozenCallback r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D228897
This commit is contained in:
@@ -15,15 +15,24 @@ namespace mozilla::dom::notification {
|
|||||||
|
|
||||||
using IPCResult = mozilla::ipc::IPCResult;
|
using IPCResult = mozilla::ipc::IPCResult;
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS(NotificationChild, nsISupports);
|
||||||
|
|
||||||
NotificationChild::NotificationChild(Notification* aNonPersistentNotification,
|
NotificationChild::NotificationChild(Notification* aNonPersistentNotification,
|
||||||
WindowGlobalChild* aWindow)
|
WindowGlobalChild* aWindow)
|
||||||
: mNonPersistentNotification(aNonPersistentNotification),
|
: mNonPersistentNotification(aNonPersistentNotification), mWindow(aWindow) {
|
||||||
mWindow(aWindow) {}
|
if (mWindow) {
|
||||||
|
BindToOwner(mWindow->GetWindowGlobal()->AsGlobal());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Step 2 of https://notifications.spec.whatwg.org/#activating-a-notification
|
// Step 2 of https://notifications.spec.whatwg.org/#activating-a-notification
|
||||||
// MOZ_CAN_RUN_SCRIPT_BOUNDARY because of DispatchEvent (boundary for now, bug
|
// MOZ_CAN_RUN_SCRIPT_BOUNDARY because of DispatchEvent (boundary for now, bug
|
||||||
// 1748910) and FocusWindow.
|
// 1748910) and FocusWindow.
|
||||||
// Bug 1539864 for IPDL not able to handle MOZ_CAN_RUN_SCRIPT.
|
// 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() {
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY IPCResult NotificationChild::RecvNotifyClick() {
|
||||||
// Step 2.1: Let intoFocus be the result of firing an event named click on the
|
// Step 2.1: Let intoFocus be the result of firing an event named click on the
|
||||||
// Notification object representing notification, with its cancelable
|
// 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
|
} // namespace mozilla::dom::notification
|
||||||
|
|||||||
@@ -7,8 +7,10 @@
|
|||||||
#ifndef DOM_NOTIFICATION_NOTIFICATIONCHILD_H_
|
#ifndef DOM_NOTIFICATION_NOTIFICATIONCHILD_H_
|
||||||
#define DOM_NOTIFICATION_NOTIFICATIONCHILD_H_
|
#define DOM_NOTIFICATION_NOTIFICATIONCHILD_H_
|
||||||
|
|
||||||
|
#include "mozilla/GlobalFreezeObserver.h"
|
||||||
#include "mozilla/WeakPtr.h"
|
#include "mozilla/WeakPtr.h"
|
||||||
#include "mozilla/dom/notification/PNotificationChild.h"
|
#include "mozilla/dom/notification/PNotificationChild.h"
|
||||||
|
#include "nsISupportsImpl.h"
|
||||||
|
|
||||||
namespace mozilla::dom {
|
namespace mozilla::dom {
|
||||||
class Notification;
|
class Notification;
|
||||||
@@ -18,10 +20,11 @@ class WindowGlobalChild;
|
|||||||
namespace mozilla::dom::notification {
|
namespace mozilla::dom::notification {
|
||||||
|
|
||||||
class NotificationChild final : public PNotificationChild,
|
class NotificationChild final : public PNotificationChild,
|
||||||
|
public GlobalFreezeObserver,
|
||||||
public SupportsWeakPtr {
|
public SupportsWeakPtr {
|
||||||
using IPCResult = mozilla::ipc::IPCResult;
|
using IPCResult = mozilla::ipc::IPCResult;
|
||||||
|
|
||||||
NS_INLINE_DECL_REFCOUNTING(NotificationChild)
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NotificationChild(Notification* aNonPersistentNotification,
|
explicit NotificationChild(Notification* aNonPersistentNotification,
|
||||||
@@ -30,6 +33,7 @@ class NotificationChild final : public PNotificationChild,
|
|||||||
IPCResult RecvNotifyClick();
|
IPCResult RecvNotifyClick();
|
||||||
|
|
||||||
void ActorDestroy(ActorDestroyReason aWhy) override;
|
void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||||
|
void FrozenCallback(nsIGlobalObject* aOwner) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~NotificationChild() = default;
|
~NotificationChild() = default;
|
||||||
|
|||||||
Reference in New Issue
Block a user