2014-10-06 18:01:20 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_FetchDriver_h
|
|
|
|
#define mozilla_dom_FetchDriver_h
|
|
|
|
|
2014-12-10 08:51:59 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2015-01-07 21:47:18 +00:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
|
|
|
#include "nsIChannelEventSink.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2014-10-06 18:01:20 +00:00
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsRefPtr.h"
|
|
|
|
|
2014-12-10 08:51:59 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2014-12-23 15:56:19 +00:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2014-12-10 08:51:59 +00:00
|
|
|
|
|
|
|
class nsIOutputStream;
|
2015-01-08 16:55:05 +00:00
|
|
|
class nsILoadGroup;
|
2014-12-10 08:51:59 +00:00
|
|
|
class nsIPrincipal;
|
2014-10-06 18:01:20 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-12-10 08:51:59 +00:00
|
|
|
class BlobSet;
|
2014-10-06 18:01:20 +00:00
|
|
|
class InternalRequest;
|
|
|
|
class InternalResponse;
|
|
|
|
|
|
|
|
class FetchDriverObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FetchDriverObserver);
|
|
|
|
virtual void OnResponseAvailable(InternalResponse* aResponse) = 0;
|
2015-01-15 04:59:00 +00:00
|
|
|
virtual void OnResponseEnd()
|
|
|
|
{ };
|
2014-10-06 18:01:20 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~FetchDriverObserver()
|
|
|
|
{ };
|
|
|
|
};
|
|
|
|
|
2015-01-07 21:47:18 +00:00
|
|
|
class FetchDriver MOZ_FINAL : public nsIStreamListener,
|
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsIAsyncVerifyRedirectCallback
|
2014-10-06 18:01:20 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-12-10 08:51:59 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2015-01-07 21:47:18 +00:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
|
2014-12-10 08:51:59 +00:00
|
|
|
|
2015-01-08 16:55:05 +00:00
|
|
|
explicit FetchDriver(InternalRequest* aRequest, nsIPrincipal* aPrincipal,
|
|
|
|
nsILoadGroup* aLoadGroup);
|
2014-10-06 18:01:20 +00:00
|
|
|
NS_IMETHOD Fetch(FetchDriverObserver* aObserver);
|
|
|
|
|
2014-12-23 15:56:19 +00:00
|
|
|
void
|
|
|
|
SetReferrerPolicy(net::ReferrerPolicy aPolicy)
|
|
|
|
{
|
|
|
|
// Cannot set policy after Fetch() has been called.
|
|
|
|
MOZ_ASSERT(mFetchRecursionCount == 0);
|
|
|
|
mReferrerPolicy = aPolicy;
|
|
|
|
}
|
|
|
|
|
2014-10-06 18:01:20 +00:00
|
|
|
private:
|
2014-12-10 08:51:59 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2015-01-08 16:55:05 +00:00
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
2014-10-06 18:01:20 +00:00
|
|
|
nsRefPtr<InternalRequest> mRequest;
|
2014-12-10 08:51:59 +00:00
|
|
|
nsRefPtr<InternalResponse> mResponse;
|
|
|
|
nsCOMPtr<nsIOutputStream> mPipeOutputStream;
|
2014-10-06 18:01:20 +00:00
|
|
|
nsRefPtr<FetchDriverObserver> mObserver;
|
2015-01-07 21:47:18 +00:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mNotificationCallbacks;
|
|
|
|
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
|
|
|
|
nsCOMPtr<nsIChannel> mOldRedirectChannel;
|
|
|
|
nsCOMPtr<nsIChannel> mNewRedirectChannel;
|
2014-10-06 18:01:20 +00:00
|
|
|
uint32_t mFetchRecursionCount;
|
2014-12-23 15:56:19 +00:00
|
|
|
net::ReferrerPolicy mReferrerPolicy;
|
2014-10-06 18:01:20 +00:00
|
|
|
|
2014-12-10 08:51:59 +00:00
|
|
|
DebugOnly<bool> mResponseAvailableCalled;
|
|
|
|
|
2015-01-06 23:35:02 +00:00
|
|
|
FetchDriver() = delete;
|
|
|
|
FetchDriver(const FetchDriver&) = delete;
|
|
|
|
FetchDriver& operator=(const FetchDriver&) = delete;
|
2014-10-06 18:01:20 +00:00
|
|
|
~FetchDriver();
|
|
|
|
|
|
|
|
nsresult Fetch(bool aCORSFlag);
|
|
|
|
nsresult ContinueFetch(bool aCORSFlag);
|
|
|
|
nsresult BasicFetch();
|
2015-01-07 23:50:54 +00:00
|
|
|
nsresult HttpFetch(bool aCORSFlag = false, bool aCORSPreflightFlag = false, bool aAuthenticationFlag = false);
|
2014-12-10 08:51:59 +00:00
|
|
|
nsresult ContinueHttpFetchAfterNetworkFetch();
|
|
|
|
// Returns the filtered response sent to the observer.
|
|
|
|
already_AddRefed<InternalResponse>
|
|
|
|
BeginAndGetFilteredResponse(InternalResponse* aResponse);
|
|
|
|
// Utility since not all cases need to do any post processing of the filtered
|
|
|
|
// response.
|
|
|
|
void BeginResponse(InternalResponse* aResponse);
|
2014-10-06 18:01:20 +00:00
|
|
|
nsresult FailWithNetworkError();
|
|
|
|
nsresult SucceedWithResponse();
|
2015-01-07 21:47:18 +00:00
|
|
|
nsresult DoesNotRequirePreflight(nsIChannel* aChannel);
|
2014-10-06 18:01:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_FetchDriver_h
|