Bug 1928702 - Part 4: Implement ActorDestroy r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D227689
This commit is contained in:
Kagami Sascha Rosylight 2024-11-07 17:32:05 +00:00
parent c2fa7e3ebb
commit baa2566f17
2 changed files with 27 additions and 1 deletions

View File

@ -6,6 +6,7 @@
#include "NotificationParent.h"
#include "NotificationUtils.h"
#include "mozilla/ipc/Endpoint.h"
namespace mozilla::dom::notification {
@ -40,4 +41,18 @@ nsresult NotificationParent::BindToMainThread(
return NS_OK;
}
void NotificationParent::ActorDestroy(ActorDestroyReason aWhy) {
nsAutoString alertName;
GetAlertName(alertName);
UnregisterNotification(mPrincipal, mId, alertName, CloseMode::InactiveGlobal);
}
void NotificationParent::MaybeInitAlertName() {
if (!mAlertName.IsEmpty()) {
return;
}
ComputeAlertName(mPrincipal, mOptions.tag(), mId, mAlertName);
}
} // namespace mozilla::dom::notification

View File

@ -35,21 +35,32 @@ class NotificationParent final : public PNotificationParent,
mOptions(aOptions) {};
IPCResult RecvShow(ShowResolver&& aResolver);
IPCResult RecvClose();
nsresult BindToMainThread(
Endpoint<PNotificationParent>&& aParentEndpoint,
PBackgroundParent::CreateNotificationParentResolver&& aResolver);
void ActorDestroy(ActorDestroyReason aWhy) override;
private:
~NotificationParent() = default;
void GetAlertName(nsAString& aRetval) {
if (mAlertName.IsEmpty()) {
MaybeInitAlertName();
}
aRetval = mAlertName;
}
void MaybeInitAlertName();
NotNull<nsCOMPtr<nsIPrincipal>> mPrincipal;
NotNull<nsCOMPtr<nsIPrincipal>> mEffectiveStoragePrincipal;
bool mIsSecureContext;
nsString mId;
nsString mScope;
IPCNotificationOptions mOptions;
nsString mAlertName;
};
} // namespace mozilla::dom::notification