diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 0e1c9bfe2ef..9d1aa72f58a 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -14181,55 +14181,8 @@ nsDocShell::ShouldPrepareForIntercept(nsIURI* aURI, bool aIsNonSubresourceReques return NS_OK; } -namespace { - -class FetchEventDispatcher final : public nsIFetchEventDispatcher -{ -public: - FetchEventDispatcher(nsIInterceptedChannel* aChannel, - nsIRunnable* aContinueRunnable) - : mChannel(aChannel) - , mContinueRunnable(aContinueRunnable) - { - } - - NS_DECL_ISUPPORTS - NS_DECL_NSIFETCHEVENTDISPATCHER - -private: - ~FetchEventDispatcher() - { - } - - nsCOMPtr mChannel; - nsCOMPtr mContinueRunnable; -}; - -NS_IMPL_ISUPPORTS(FetchEventDispatcher, nsIFetchEventDispatcher) - NS_IMETHODIMP -FetchEventDispatcher::Dispatch() -{ - RefPtr swm = ServiceWorkerManager::GetInstance(); - if (!swm) { - mChannel->Cancel(NS_ERROR_INTERCEPTION_FAILED); - return NS_OK; - } - - ErrorResult error; - swm->DispatchPreparedFetchEvent(mChannel, mContinueRunnable, error); - if (NS_WARN_IF(error.Failed())) { - return error.StealNSResult(); - } - - return NS_OK; -} - -} - -NS_IMETHODIMP -nsDocShell::ChannelIntercepted(nsIInterceptedChannel* aChannel, - nsIFetchEventDispatcher** aFetchDispatcher) +nsDocShell::ChannelIntercepted(nsIInterceptedChannel* aChannel) { RefPtr swm = ServiceWorkerManager::GetInstance(); if (!swm) { @@ -14266,18 +14219,12 @@ nsDocShell::ChannelIntercepted(nsIInterceptedChannel* aChannel, attrs.InheritFromDocShellToDoc(GetOriginAttributes(), uri); ErrorResult error; - nsCOMPtr runnable = - swm->PrepareFetchEvent(attrs, doc, mInterceptedDocumentId, aChannel, - isReload, isSubresourceLoad, error); + swm->DispatchFetchEvent(attrs, doc, mInterceptedDocumentId, aChannel, + isReload, isSubresourceLoad, error); if (NS_WARN_IF(error.Failed())) { return error.StealNSResult(); } - MOZ_ASSERT(runnable); - RefPtr dispatcher = - new FetchEventDispatcher(aChannel, runnable); - dispatcher.forget(aFetchDispatcher); - return NS_OK; } diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index 1f749fca205..31c08875a48 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -3568,14 +3568,14 @@ public: } // anonymous namespace -already_AddRefed -ServiceWorkerManager::PrepareFetchEvent(const PrincipalOriginAttributes& aOriginAttributes, - nsIDocument* aDoc, - const nsAString& aDocumentIdForTopLevelNavigation, - nsIInterceptedChannel* aChannel, - bool aIsReload, - bool aIsSubresourceLoad, - ErrorResult& aRv) +void +ServiceWorkerManager::DispatchFetchEvent(const PrincipalOriginAttributes& aOriginAttributes, + nsIDocument* aDoc, + const nsAString& aDocumentIdForTopLevelNavigation, + nsIInterceptedChannel* aChannel, + bool aIsReload, + bool aIsSubresourceLoad, + ErrorResult& aRv) { MOZ_ASSERT(aChannel); AssertIsOnMainThread(); @@ -3590,13 +3590,13 @@ ServiceWorkerManager::PrepareFetchEvent(const PrincipalOriginAttributes& aOrigin loadGroup = aDoc->GetDocumentLoadGroup(); nsresult rv = aDoc->GetOrCreateId(documentId); if (NS_WARN_IF(NS_FAILED(rv))) { - return nullptr; + return; } } else { nsCOMPtr internalChannel; aRv = aChannel->GetChannel(getter_AddRefs(internalChannel)); if (NS_WARN_IF(aRv.Failed())) { - return nullptr; + return; } internalChannel->GetLoadGroup(getter_AddRefs(loadGroup)); @@ -3606,7 +3606,7 @@ ServiceWorkerManager::PrepareFetchEvent(const PrincipalOriginAttributes& aOrigin nsCOMPtr uri; aRv = aChannel->GetSecureUpgradedChannelURI(getter_AddRefs(uri)); if (NS_WARN_IF(aRv.Failed())) { - return nullptr; + return; } RefPtr registration = @@ -3614,7 +3614,7 @@ ServiceWorkerManager::PrepareFetchEvent(const PrincipalOriginAttributes& aOrigin if (!registration) { NS_WARNING("No registration found when dispatching the fetch event"); aRv.Throw(NS_ERROR_FAILURE); - return nullptr; + return; } // This should only happen if IsAvailable() returned true. @@ -3625,7 +3625,7 @@ ServiceWorkerManager::PrepareFetchEvent(const PrincipalOriginAttributes& aOrigin } if (NS_WARN_IF(aRv.Failed()) || !serviceWorker) { - return nullptr; + return; } nsCOMPtr continueRunnable = @@ -3633,18 +3633,6 @@ ServiceWorkerManager::PrepareFetchEvent(const PrincipalOriginAttributes& aOrigin aChannel, loadGroup, documentId, aIsReload); - return continueRunnable.forget(); -} - -void -ServiceWorkerManager::DispatchPreparedFetchEvent(nsIInterceptedChannel* aChannel, - nsIRunnable* aPreparedRunnable, - ErrorResult& aRv) -{ - MOZ_ASSERT(aChannel); - MOZ_ASSERT(aPreparedRunnable); - AssertIsOnMainThread(); - nsCOMPtr innerChannel; aRv = aChannel->GetChannel(getter_AddRefs(innerChannel)); if (NS_WARN_IF(aRv.Failed())) { @@ -3655,12 +3643,12 @@ ServiceWorkerManager::DispatchPreparedFetchEvent(nsIInterceptedChannel* aChannel // If there is no upload stream, then continue immediately if (!uploadChannel) { - MOZ_ALWAYS_TRUE(NS_SUCCEEDED(aPreparedRunnable->Run())); + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(continueRunnable->Run())); return; } // Otherwise, ensure the upload stream can be cloned directly. This may // require some async copying, so provide a callback. - aRv = uploadChannel->EnsureUploadStreamIsCloneable(aPreparedRunnable); + aRv = uploadChannel->EnsureUploadStreamIsCloneable(continueRunnable); } bool diff --git a/dom/workers/ServiceWorkerManager.h b/dom/workers/ServiceWorkerManager.h index aafcf0a1f41..2cc63574db6 100644 --- a/dom/workers/ServiceWorkerManager.h +++ b/dom/workers/ServiceWorkerManager.h @@ -373,19 +373,14 @@ public: bool IsControlled(nsIDocument* aDocument, ErrorResult& aRv); - already_AddRefed - PrepareFetchEvent(const PrincipalOriginAttributes& aOriginAttributes, - nsIDocument* aDoc, - const nsAString& aDocumentIdForTopLevelNavigation, - nsIInterceptedChannel* aChannel, - bool aIsReload, - bool aIsSubresourceLoad, - ErrorResult& aRv); - void - DispatchPreparedFetchEvent(nsIInterceptedChannel* aChannel, - nsIRunnable* aPreparedRunnable, - ErrorResult& aRv); + DispatchFetchEvent(const PrincipalOriginAttributes& aOriginAttributes, + nsIDocument* aDoc, + const nsAString& aDocumentIdForTopLevelNavigation, + nsIInterceptedChannel* aChannel, + bool aIsReload, + bool aIsSubresourceLoad, + ErrorResult& aRv); void Update(nsIPrincipal* aPrincipal, diff --git a/modules/libjar/InterceptedJARChannel.cpp b/modules/libjar/InterceptedJARChannel.cpp index 659ba98d63c..1609afb739d 100644 --- a/modules/libjar/InterceptedJARChannel.cpp +++ b/modules/libjar/InterceptedJARChannel.cpp @@ -156,14 +156,7 @@ InterceptedJARChannel::NotifyController() 0, UINT32_MAX, true, true); NS_ENSURE_SUCCESS_VOID(rv); - nsCOMPtr dispatcher; - rv = mController->ChannelIntercepted(this, getter_AddRefs(dispatcher)); - if (NS_WARN_IF(NS_FAILED(rv))) { - rv = ResetInterception(); - NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), - "Failed to resume intercepted network request"); - } - rv = dispatcher->Dispatch(); + rv = mController->ChannelIntercepted(this); if (NS_WARN_IF(NS_FAILED(rv))) { rv = ResetInterception(); NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), diff --git a/netwerk/base/nsINetworkInterceptController.idl b/netwerk/base/nsINetworkInterceptController.idl index bbac746b27f..17d27de42ae 100644 --- a/netwerk/base/nsINetworkInterceptController.idl +++ b/netwerk/base/nsINetworkInterceptController.idl @@ -116,29 +116,13 @@ interface nsIInterceptedChannel : nsISupports void setReleaseHandle(in nsISupports aHandle); }; -/** - * Interface to allow consumers to dispatch the fetch event asynchronously. - * Consumers get access to this interface by calling channelIntercepted(), - * and they can choose to either dispatch() immediately or do that at some - * later time. - */ - -[scriptable, uuid(799504e4-36f8-4ab5-b9d2-53f0c0c40c04)] -interface nsIFetchEventDispatcher : nsISupports -{ - /** - * Actually dispatches the fetch event to the service worker. - */ - void dispatch(); -}; - /** * Interface to allow consumers to attach themselves to a channel's * notification callbacks/loadgroup and determine if a given channel * request should be intercepted before any network request is initiated. */ -[scriptable, uuid(49eb1997-90fb-49d6-a25d-41f51c7c99e8)] +[scriptable, uuid(70d2b4fe-a552-48cd-8d93-1d8437a56b53)] interface nsINetworkInterceptController : nsISupports { /** @@ -156,5 +140,5 @@ interface nsINetworkInterceptController : nsISupports * * @param aChannel the controlling interface for a channel that has been intercepted */ - nsIFetchEventDispatcher channelIntercepted(in nsIInterceptedChannel aChannel); + void channelIntercepted(in nsIInterceptedChannel aChannel); }; diff --git a/netwerk/protocol/http/HttpChannelParentListener.cpp b/netwerk/protocol/http/HttpChannelParentListener.cpp index b25298c0fb0..9ca2e2e4321 100644 --- a/netwerk/protocol/http/HttpChannelParentListener.cpp +++ b/netwerk/protocol/http/HttpChannelParentListener.cpp @@ -311,54 +311,12 @@ public: } }; -class ResponseSynthesizer final : public nsIFetchEventDispatcher -{ -public: - ResponseSynthesizer(nsIInterceptedChannel* aChannel, - HttpChannelParentListener* aParentListener) - : mChannel(aChannel) - , mParentListener(aParentListener) - { - } - - NS_DECL_ISUPPORTS - NS_DECL_NSIFETCHEVENTDISPATCHER - -private: - ~ResponseSynthesizer() - { - } - - nsCOMPtr mChannel; - RefPtr mParentListener; -}; - -NS_IMPL_ISUPPORTS(ResponseSynthesizer, nsIFetchEventDispatcher) - NS_IMETHODIMP -ResponseSynthesizer::Dispatch() -{ - mParentListener->SynthesizeResponse(mChannel); - - return NS_OK; -} - -NS_IMETHODIMP -HttpChannelParentListener::ChannelIntercepted(nsIInterceptedChannel* aChannel, - nsIFetchEventDispatcher** aDispatcher) -{ - RefPtr dispatcher = - new ResponseSynthesizer(aChannel, this); - dispatcher.forget(aDispatcher); - return NS_OK; -} - -void -HttpChannelParentListener::SynthesizeResponse(nsIInterceptedChannel* aChannel) +HttpChannelParentListener::ChannelIntercepted(nsIInterceptedChannel* aChannel) { if (mShouldSuspendIntercept) { mInterceptedChannel = aChannel; - return; + return NS_OK; } aChannel->SynthesizeStatus(mSynthesizedResponseHead->Status(), @@ -375,6 +333,8 @@ HttpChannelParentListener::SynthesizeResponse(nsIInterceptedChannel* aChannel) RefPtr channel = do_QueryObject(mNextListener); MOZ_ASSERT(channel); channel->ResponseSynthesized(); + + return NS_OK; } //----------------------------------------------------------------------------- diff --git a/netwerk/protocol/http/HttpChannelParentListener.h b/netwerk/protocol/http/HttpChannelParentListener.h index 00475220b34..0dcd0843152 100644 --- a/netwerk/protocol/http/HttpChannelParentListener.h +++ b/netwerk/protocol/http/HttpChannelParentListener.h @@ -62,9 +62,6 @@ private: // Private partner function to SuspendForDiversion. nsresult ResumeForDiversion(); - void SynthesizeResponse(nsIInterceptedChannel* aChannel); - friend class ResponseSynthesizer; - // Can be the original HttpChannelParent that created this object (normal // case), a different {HTTP|FTP}ChannelParent that we've been redirected to, // or some other listener that we have been diverted to via diff --git a/netwerk/protocol/http/InterceptedChannel.cpp b/netwerk/protocol/http/InterceptedChannel.cpp index 2db1cc173eb..8c368b7e1af 100644 --- a/netwerk/protocol/http/InterceptedChannel.cpp +++ b/netwerk/protocol/http/InterceptedChannel.cpp @@ -72,18 +72,10 @@ InterceptedChannelBase::DoNotifyController() return; } - nsCOMPtr dispatcher; - rv = mController->ChannelIntercepted(this, getter_AddRefs(dispatcher)); - - if (NS_WARN_IF(NS_FAILED(rv) || !dispatcher)) { + rv = mController->ChannelIntercepted(this); + if (NS_WARN_IF(NS_FAILED(rv))) { rv = ResetInterception(); NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to resume intercepted network request"); - } else { - rv = dispatcher->Dispatch(); - if (NS_WARN_IF(NS_FAILED(rv))) { - rv = ResetInterception(); - NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to resume intercepted network request"); - } } mController = nullptr; }