Bug 1196592: Make retargeting Fetch to another thread actually work. r=nsm

This commit is contained in:
Kyle Huey 2015-08-28 13:49:07 -07:00
parent 6e6b038e49
commit 787ed3ef0d
4 changed files with 41 additions and 9 deletions

View File

@ -41,7 +41,7 @@ namespace dom {
NS_IMPL_ISUPPORTS(FetchDriver,
nsIStreamListener, nsIChannelEventSink, nsIInterfaceRequestor,
nsIAsyncVerifyRedirectCallback)
nsIAsyncVerifyRedirectCallback, nsIThreadRetargetableStreamListener)
FetchDriver::FetchDriver(InternalRequest* aRequest, nsIPrincipal* aPrincipal,
nsILoadGroup* aLoadGroup)
@ -782,9 +782,8 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest,
}
// Try to retarget off main thread.
nsCOMPtr<nsIThreadRetargetableRequest> rr = do_QueryInterface(aRequest);
if (rr) {
rr->RetargetDeliveryTo(sts);
if (nsCOMPtr<nsIThreadRetargetableRequest> rr = do_QueryInterface(aRequest)) {
NS_WARN_IF(NS_FAILED(rr->RetargetDeliveryTo(sts)));
}
return NS_OK;
}
@ -796,6 +795,10 @@ FetchDriver::OnDataAvailable(nsIRequest* aRequest,
uint64_t aOffset,
uint32_t aCount)
{
// NB: This can be called on any thread! But we're guaranteed that it is
// called between OnStartRequest and OnStopRequest, so we don't need to worry
// about races.
uint32_t aRead;
MOZ_ASSERT(mResponse);
MOZ_ASSERT(mPipeOutputStream);
@ -887,6 +890,12 @@ FetchDriver::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
return NS_OK;
}
NS_IMETHODIMP
FetchDriver::CheckListenerChain()
{
return NS_OK;
}
// Returns NS_OK if no preflight is required, error otherwise.
nsresult
FetchDriver::DoesNotRequirePreflight(nsIChannel* aChannel)

View File

@ -12,6 +12,7 @@
#include "nsIChannelEventSink.h"
#include "nsIInterfaceRequestor.h"
#include "nsIStreamListener.h"
#include "nsIThreadRetargetableStreamListener.h"
#include "mozilla/nsRefPtr.h"
#include "mozilla/DebugOnly.h"
@ -44,7 +45,8 @@ protected:
class FetchDriver final : public nsIStreamListener,
public nsIChannelEventSink,
public nsIInterfaceRequestor,
public nsIAsyncVerifyRedirectCallback
public nsIAsyncVerifyRedirectCallback,
public nsIThreadRetargetableStreamListener
{
public:
NS_DECL_ISUPPORTS
@ -53,6 +55,7 @@ public:
NS_DECL_NSICHANNELEVENTSINK
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
explicit FetchDriver(InternalRequest* aRequest, nsIPrincipal* aPrincipal,
nsILoadGroup* aLoadGroup);

View File

@ -412,7 +412,8 @@ nsPreflightCache::GetCacheKey(nsIURI* aURI,
NS_IMPL_ISUPPORTS(nsCORSListenerProxy, nsIStreamListener,
nsIRequestObserver, nsIChannelEventSink,
nsIInterfaceRequestor, nsIAsyncVerifyRedirectCallback)
nsIInterfaceRequestor, nsIAsyncVerifyRedirectCallback,
nsIThreadRetargetableStreamListener)
/* static */
void
@ -675,11 +676,15 @@ nsCORSListenerProxy::OnStopRequest(nsIRequest* aRequest,
NS_IMETHODIMP
nsCORSListenerProxy::OnDataAvailable(nsIRequest* aRequest,
nsISupports* aContext,
nsISupports* aContext,
nsIInputStream* aInputStream,
uint64_t aOffset,
uint32_t aCount)
{
// NB: This can be called on any thread! But we're guaranteed that it is
// called between OnStartRequest and OnStopRequest, so we don't need to worry
// about races.
MOZ_ASSERT(mInited, "nsCORSListenerProxy has not been initialized properly");
if (!mRequestApproved) {
return NS_ERROR_DOM_BAD_URI;
@ -826,6 +831,19 @@ nsCORSListenerProxy::OnRedirectVerifyCallback(nsresult result)
return NS_OK;
}
NS_IMETHODIMP
nsCORSListenerProxy::CheckListenerChain()
{
MOZ_ASSERT(NS_IsMainThread());
if (nsCOMPtr<nsIThreadRetargetableStreamListener> retargetableListener =
do_QueryInterface(mOuterListener)) {
return retargetableListener->CheckListenerChain();
}
return NS_ERROR_NO_INTERFACE;
}
// Please note that the CSP directive 'upgrade-insecure-requests' relies
// on the promise that channels get updated from http: to https: before
// the channel fetches any data from the netwerk. Such channels should
@ -1263,7 +1281,6 @@ nsCORSPreflightListener::GetInterface(const nsIID & aIID, void **aResult)
return QueryInterface(aIID, aResult);
}
nsresult
NS_StartCORSPreflight(nsIChannel* aRequestChannel,
nsIStreamListener* aListener,

View File

@ -16,6 +16,7 @@
#include "nsIInterfaceRequestor.h"
#include "nsIChannelEventSink.h"
#include "nsIAsyncVerifyRedirectCallback.h"
#include "nsIThreadRetargetableStreamListener.h"
#include "mozilla/Attributes.h"
class nsIURI;
@ -39,7 +40,8 @@ enum class DataURIHandling
class nsCORSListenerProxy final : public nsIStreamListener,
public nsIInterfaceRequestor,
public nsIChannelEventSink,
public nsIAsyncVerifyRedirectCallback
public nsIAsyncVerifyRedirectCallback,
public nsIThreadRetargetableStreamListener
{
public:
nsCORSListenerProxy(nsIStreamListener* aOuter,
@ -57,6 +59,7 @@ public:
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSICHANNELEVENTSINK
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
// Must be called at startup.
static void Startup();