зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1354599 - Use of DOMEventTargetHelper::KeepAliveIfHasListenersFor in BroadcastChannel, r=smaug
This commit is contained in:
Родитель
b623ab29ec
Коммит
1ee7d66ef2
|
@ -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<bool>& 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
|
||||
|
|
|
@ -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<bool>& 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<JS::Value> aMessage,
|
||||
ErrorResult& aRv);
|
||||
|
||||
void UpdateMustKeepAlive();
|
||||
|
||||
bool IsCertainlyAliveForCC() const override
|
||||
{
|
||||
return mIsKeptAlive;
|
||||
}
|
||||
|
||||
void RemoveDocFromBFCache();
|
||||
|
||||
RefPtr<BroadcastChannelChild> mActor;
|
||||
|
@ -117,8 +96,6 @@ private:
|
|||
nsCString mOrigin;
|
||||
nsString mChannel;
|
||||
|
||||
bool mIsKeptAlive;
|
||||
|
||||
uint64_t mInnerID;
|
||||
|
||||
enum {
|
||||
|
|
Загрузка…
Ссылка в новой задаче