Bug 1236686 - Remove nsIFetchEventDispatcher; r=jdm

This commit is contained in:
Ehsan Akhgari 2016-01-04 17:40:04 -05:00
parent 955f131219
commit 62802f2dd0
8 changed files with 34 additions and 178 deletions

View File

@ -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<nsIInterceptedChannel> mChannel;
nsCOMPtr<nsIRunnable> mContinueRunnable;
};
NS_IMPL_ISUPPORTS(FetchEventDispatcher, nsIFetchEventDispatcher)
NS_IMETHODIMP
FetchEventDispatcher::Dispatch()
{
RefPtr<ServiceWorkerManager> 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<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
if (!swm) {
@ -14266,18 +14219,12 @@ nsDocShell::ChannelIntercepted(nsIInterceptedChannel* aChannel,
attrs.InheritFromDocShellToDoc(GetOriginAttributes(), uri);
ErrorResult error;
nsCOMPtr<nsIRunnable> 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<FetchEventDispatcher> dispatcher =
new FetchEventDispatcher(aChannel, runnable);
dispatcher.forget(aFetchDispatcher);
return NS_OK;
}

View File

@ -3568,14 +3568,14 @@ public:
} // anonymous namespace
already_AddRefed<nsIRunnable>
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<nsIChannel> 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<nsIURI> uri;
aRv = aChannel->GetSecureUpgradedChannelURI(getter_AddRefs(uri));
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
return;
}
RefPtr<ServiceWorkerRegistrationInfo> 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<nsIRunnable> 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<nsIChannel> 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

View File

@ -373,19 +373,14 @@ public:
bool
IsControlled(nsIDocument* aDocument, ErrorResult& aRv);
already_AddRefed<nsIRunnable>
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,

View File

@ -156,14 +156,7 @@ InterceptedJARChannel::NotifyController()
0, UINT32_MAX, true, true);
NS_ENSURE_SUCCESS_VOID(rv);
nsCOMPtr<nsIFetchEventDispatcher> 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),

View File

@ -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);
};

View File

@ -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<nsIInterceptedChannel> mChannel;
RefPtr<HttpChannelParentListener> 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<ResponseSynthesizer> 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<HttpChannelParent> channel = do_QueryObject(mNextListener);
MOZ_ASSERT(channel);
channel->ResponseSynthesized();
return NS_OK;
}
//-----------------------------------------------------------------------------

View File

@ -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

View File

@ -72,18 +72,10 @@ InterceptedChannelBase::DoNotifyController()
return;
}
nsCOMPtr<nsIFetchEventDispatcher> 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;
}