diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 414bdcb56f02..9a05816b0414 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -3546,7 +3546,8 @@ nsresult nsHttpChannel::OpenCacheEntryInternal(bool isHttps) { }; // calls nsHttpChannel::Notify after `mCacheOpenDelay` milliseconds - NS_NewTimerWithCallback(getter_AddRefs(mCacheOpenTimer), this, + auto callback = MakeRefPtr(this); + NS_NewTimerWithCallback(getter_AddRefs(mCacheOpenTimer), callback, mCacheOpenDelay, nsITimer::TYPE_ONE_SHOT); } NS_ENSURE_SUCCESS(rv, rv); @@ -5351,8 +5352,6 @@ NS_INTERFACE_MAP_BEGIN(nsHttpChannel) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsICorsPreflightCallback) NS_INTERFACE_MAP_ENTRY(nsIRaceCacheWithNetwork) - NS_INTERFACE_MAP_ENTRY(nsITimerCallback) - NS_INTERFACE_MAP_ENTRY(nsINamed) NS_INTERFACE_MAP_ENTRY(nsIRequestTailUnblockCallback) NS_INTERFACE_MAP_ENTRY_CONCRETE(nsHttpChannel) NS_INTERFACE_MAP_END_INHERITING(HttpBaseChannel) @@ -8969,7 +8968,9 @@ nsresult nsHttpChannel::TriggerNetworkWithDelay(uint32_t aDelay) { if (!mNetworkTriggerTimer) { mNetworkTriggerTimer = NS_NewTimer(); } - mNetworkTriggerTimer->InitWithCallback(this, aDelay, nsITimer::TYPE_ONE_SHOT); + auto callback = MakeRefPtr(this); + mNetworkTriggerTimer->InitWithCallback(callback, aDelay, + nsITimer::TYPE_ONE_SHOT); return NS_OK; } @@ -9091,20 +9092,24 @@ nsHttpChannel::Test_triggerNetwork(int32_t aTimeout) { return TriggerNetworkWithDelay(aTimeout); } +nsHttpChannel::TimerCallback::TimerCallback(nsHttpChannel* aChannel) + : mChannel(aChannel) {} + +NS_IMPL_ISUPPORTS(nsHttpChannel::TimerCallback, nsITimerCallback, nsINamed) + NS_IMETHODIMP -nsHttpChannel::GetName(nsACString& aName) { +nsHttpChannel::TimerCallback::GetName(nsACString& aName) { aName.AssignLiteral("nsHttpChannel"); return NS_OK; } NS_IMETHODIMP -nsHttpChannel::Notify(nsITimer* aTimer) { - RefPtr self(this); - if (aTimer == mCacheOpenTimer) { - return Test_triggerDelayedOpenCacheEntry(); +nsHttpChannel::TimerCallback::Notify(nsITimer* aTimer) { + if (aTimer == mChannel->mCacheOpenTimer) { + return mChannel->Test_triggerDelayedOpenCacheEntry(); } - if (aTimer == mNetworkTriggerTimer) { - return TriggerNetwork(); + if (aTimer == mChannel->mNetworkTriggerTimer) { + return mChannel->TriggerNetwork(); } MOZ_CRASH("Unknown timer"); diff --git a/netwerk/protocol/http/nsHttpChannel.h b/netwerk/protocol/http/nsHttpChannel.h index c2fa1d58284a..20d85cdda341 100644 --- a/netwerk/protocol/http/nsHttpChannel.h +++ b/netwerk/protocol/http/nsHttpChannel.h @@ -74,9 +74,7 @@ class nsHttpChannel final : public HttpBaseChannel, public nsSupportsWeakReference, public nsICorsPreflightCallback, public nsIRaceCacheWithNetwork, - public nsIRequestTailUnblockCallback, - public nsITimerCallback, - public nsINamed { + public nsIRequestTailUnblockCallback { public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIREQUESTOBSERVER @@ -93,8 +91,6 @@ class nsHttpChannel final : public HttpBaseChannel, NS_DECL_NSIDNSLISTENER NS_DECLARE_STATIC_IID_ACCESSOR(NS_HTTPCHANNEL_IID) NS_DECL_NSIRACECACHEWITHNETWORK - NS_DECL_NSITIMERCALLBACK - NS_DECL_NSINAMED NS_DECL_NSIREQUESTTAILUNBLOCKCALLBACK // nsIHttpAuthenticableChannel. We can't use @@ -734,6 +730,23 @@ class nsHttpChannel final : public HttpBaseChannel, // True if the channel is reading from cache. Atomic mIsReadingFromCache{false}; + // nsITimerCallback is implemented on a subclass so that the name attribute + // doesn't conflict with the name attribute of the nsIRequest interface that + // might be present on the same object (as seen from JavaScript code). + class TimerCallback final : public nsITimerCallback, public nsINamed { + public: + NS_DECL_ISUPPORTS + NS_DECL_NSITIMERCALLBACK + NS_DECL_NSINAMED + + explicit TimerCallback(nsHttpChannel* aChannel); + + private: + ~TimerCallback() = default; + + RefPtr mChannel; + }; + // These next members are only used in unit tests to delay the call to // cache->AsyncOpenURI in order to race the cache with the network. nsCOMPtr mCacheOpenTimer;