diff --git a/dom/broadcastchannel/BroadcastChannel.cpp b/dom/broadcastchannel/BroadcastChannel.cpp index cf0919624c05..32880c157e04 100644 --- a/dom/broadcastchannel/BroadcastChannel.cpp +++ b/dom/broadcastchannel/BroadcastChannel.cpp @@ -272,11 +272,12 @@ BroadcastChannel::BroadcastChannel(nsPIDOMWindowInner* aWindow, , mPrincipalInfo(new PrincipalInfo(aPrincipalInfo)) , mOrigin(aOrigin) , mChannel(aChannel) - , mIsKeptAlive(false) , mInnerID(0) , mState(StateActive) { // Window can be null in workers + + KeepAliveIfHasListenersFor(NS_LITERAL_STRING("message")); } BroadcastChannel::~BroadcastChannel() @@ -496,82 +497,7 @@ BroadcastChannel::Shutdown() mActor = nullptr; } - // If shutdown() is called we have to release the reference if we still keep - // it. - if (mIsKeptAlive) { - mIsKeptAlive = false; - Release(); - } -} - -EventHandlerNonNull* -BroadcastChannel::GetOnmessage() -{ - if (NS_IsMainThread()) { - return GetEventHandler(nsGkAtoms::onmessage, EmptyString()); - } - return GetEventHandler(nullptr, NS_LITERAL_STRING("message")); -} - -void -BroadcastChannel::SetOnmessage(EventHandlerNonNull* aCallback) -{ - if (NS_IsMainThread()) { - SetEventHandler(nsGkAtoms::onmessage, EmptyString(), aCallback); - } else { - SetEventHandler(nullptr, NS_LITERAL_STRING("message"), aCallback); - } - - UpdateMustKeepAlive(); -} - -void -BroadcastChannel::AddEventListener(const nsAString& aType, - EventListener* aCallback, - const AddEventListenerOptionsOrBoolean& aOptions, - const dom::Nullable& aWantsUntrusted, - ErrorResult& aRv) -{ - DOMEventTargetHelper::AddEventListener(aType, aCallback, aOptions, - aWantsUntrusted, aRv); - - if (aRv.Failed()) { - return; - } - - UpdateMustKeepAlive(); -} - -void -BroadcastChannel::RemoveEventListener(const nsAString& aType, - EventListener* aCallback, - const EventListenerOptionsOrBoolean& aOptions, - ErrorResult& aRv) -{ - DOMEventTargetHelper::RemoveEventListener(aType, aCallback, aOptions, aRv); - - if (aRv.Failed()) { - return; - } - - UpdateMustKeepAlive(); -} - -void -BroadcastChannel::UpdateMustKeepAlive() -{ - bool toKeepAlive = HasListenersFor(NS_LITERAL_STRING("message")); - if (toKeepAlive == mIsKeptAlive) { - return; - } - - mIsKeptAlive = toKeepAlive; - - if (toKeepAlive) { - AddRef(); - } else { - Release(); - } + IgnoreKeepAliveIfHasListenersFor(NS_LITERAL_STRING("message")); } NS_IMETHODIMP diff --git a/dom/broadcastchannel/BroadcastChannel.h b/dom/broadcastchannel/BroadcastChannel.h index d7d46eeeccfd..a2c04f015e01 100644 --- a/dom/broadcastchannel/BroadcastChannel.h +++ b/dom/broadcastchannel/BroadcastChannel.h @@ -67,21 +67,7 @@ public: void Close(); - EventHandlerNonNull* GetOnmessage(); - void SetOnmessage(EventHandlerNonNull* aCallback); - - using nsIDOMEventTarget::AddEventListener; - using nsIDOMEventTarget::RemoveEventListener; - - virtual void AddEventListener(const nsAString& aType, - EventListener* aCallback, - const AddEventListenerOptionsOrBoolean& aOptions, - const Nullable& aWantsUntrusted, - ErrorResult& aRv) override; - virtual void RemoveEventListener(const nsAString& aType, - EventListener* aCallback, - const EventListenerOptionsOrBoolean& aOptions, - ErrorResult& aRv) override; + IMPL_EVENT_HANDLER(message) void Shutdown(); @@ -98,13 +84,6 @@ private: void PostMessageInternal(JSContext* aCx, JS::Handle aMessage, ErrorResult& aRv); - void UpdateMustKeepAlive(); - - bool IsCertainlyAliveForCC() const override - { - return mIsKeptAlive; - } - void RemoveDocFromBFCache(); RefPtr mActor; @@ -117,8 +96,6 @@ private: nsCString mOrigin; nsString mChannel; - bool mIsKeptAlive; - uint64_t mInnerID; enum {