2014-10-06 11:01:20 -07: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 00:51:59 -08:00
|
|
|
#include "nsAutoPtr.h"
|
2015-01-07 13:47:18 -08:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
|
|
|
#include "nsIChannelEventSink.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2014-10-06 11:01:20 -07:00
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsRefPtr.h"
|
|
|
|
|
2014-12-10 00:51:59 -08:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2014-12-23 07:56:19 -08:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2014-12-10 00:51:59 -08:00
|
|
|
|
2014-10-14 16:36:58 -07:00
|
|
|
class nsIDocument;
|
2014-12-10 00:51:59 -08:00
|
|
|
class nsIOutputStream;
|
2015-01-08 08:55:05 -08:00
|
|
|
class nsILoadGroup;
|
2014-12-10 00:51:59 -08:00
|
|
|
class nsIPrincipal;
|
2014-10-06 11:01:20 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-12-10 00:51:59 -08:00
|
|
|
class BlobSet;
|
2014-10-06 11:01:20 -07:00
|
|
|
class InternalRequest;
|
|
|
|
class InternalResponse;
|
|
|
|
|
|
|
|
class FetchDriverObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FetchDriverObserver);
|
|
|
|
virtual void OnResponseAvailable(InternalResponse* aResponse) = 0;
|
2015-01-14 20:59:00 -08:00
|
|
|
virtual void OnResponseEnd()
|
|
|
|
{ };
|
2014-10-06 11:01:20 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~FetchDriverObserver()
|
|
|
|
{ };
|
|
|
|
};
|
|
|
|
|
2015-01-07 13:47:18 -08:00
|
|
|
class FetchDriver MOZ_FINAL : public nsIStreamListener,
|
|
|
|
public nsIChannelEventSink,
|
|
|
|
public nsIInterfaceRequestor,
|
|
|
|
public nsIAsyncVerifyRedirectCallback
|
2014-10-06 11:01:20 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-12-10 00:51:59 -08:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2015-01-07 13:47:18 -08:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
|
|
|
NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
|
2014-12-10 00:51:59 -08:00
|
|
|
|
2015-01-08 08:55:05 -08:00
|
|
|
explicit FetchDriver(InternalRequest* aRequest, nsIPrincipal* aPrincipal,
|
|
|
|
nsILoadGroup* aLoadGroup);
|
2014-10-06 11:01:20 -07:00
|
|
|
NS_IMETHOD Fetch(FetchDriverObserver* aObserver);
|
|
|
|
|
2014-12-23 07:56:19 -08:00
|
|
|
void
|
2014-10-14 16:36:58 -07:00
|
|
|
SetDocument(nsIDocument* aDocument)
|
2014-12-23 07:56:19 -08:00
|
|
|
{
|
2014-10-14 16:36:58 -07:00
|
|
|
// Cannot set document after Fetch() has been called.
|
2014-12-23 07:56:19 -08:00
|
|
|
MOZ_ASSERT(mFetchRecursionCount == 0);
|
2014-10-14 16:36:58 -07:00
|
|
|
mDocument = aDocument;
|
2014-12-23 07:56:19 -08:00
|
|
|
}
|
|
|
|
|
2014-10-06 11:01:20 -07:00
|
|
|
private:
|
2014-12-10 00:51:59 -08:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2015-01-08 08:55:05 -08:00
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
2014-10-06 11:01:20 -07:00
|
|
|
nsRefPtr<InternalRequest> mRequest;
|
2014-12-10 00:51:59 -08:00
|
|
|
nsRefPtr<InternalResponse> mResponse;
|
|
|
|
nsCOMPtr<nsIOutputStream> mPipeOutputStream;
|
2014-10-06 11:01:20 -07:00
|
|
|
nsRefPtr<FetchDriverObserver> mObserver;
|
2015-01-07 13:47:18 -08:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mNotificationCallbacks;
|
|
|
|
nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
|
|
|
|
nsCOMPtr<nsIChannel> mOldRedirectChannel;
|
|
|
|
nsCOMPtr<nsIChannel> mNewRedirectChannel;
|
2014-10-14 16:36:58 -07:00
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
2014-10-06 11:01:20 -07:00
|
|
|
uint32_t mFetchRecursionCount;
|
|
|
|
|
2014-12-10 00:51:59 -08:00
|
|
|
DebugOnly<bool> mResponseAvailableCalled;
|
|
|
|
|
2015-01-06 15:35:02 -08:00
|
|
|
FetchDriver() = delete;
|
|
|
|
FetchDriver(const FetchDriver&) = delete;
|
|
|
|
FetchDriver& operator=(const FetchDriver&) = delete;
|
2014-10-06 11:01:20 -07:00
|
|
|
~FetchDriver();
|
|
|
|
|
|
|
|
nsresult Fetch(bool aCORSFlag);
|
|
|
|
nsresult ContinueFetch(bool aCORSFlag);
|
|
|
|
nsresult BasicFetch();
|
2015-01-07 15:50:54 -08:00
|
|
|
nsresult HttpFetch(bool aCORSFlag = false, bool aCORSPreflightFlag = false, bool aAuthenticationFlag = false);
|
2014-12-10 00:51:59 -08: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 11:01:20 -07:00
|
|
|
nsresult FailWithNetworkError();
|
|
|
|
nsresult SucceedWithResponse();
|
2015-01-07 13:47:18 -08:00
|
|
|
nsresult DoesNotRequirePreflight(nsIChannel* aChannel);
|
2014-10-06 11:01:20 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_FetchDriver_h
|