2015-05-03 19:32:37 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-10-06 18:01:20 +00:00
|
|
|
/* 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 "nsIChannelEventSink.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2014-10-06 18:01:20 +00:00
|
|
|
#include "nsIStreamListener.h"
|
2015-08-28 20:49:07 +00:00
|
|
|
#include "nsIThreadRetargetableStreamListener.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2014-10-06 18:01:20 +00:00
|
|
|
|
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
|
|
|
|
2014-10-14 23:36:58 +00:00
|
|
|
class nsIDocument;
|
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 {
|
|
|
|
|
|
|
|
class InternalRequest;
|
|
|
|
class InternalResponse;
|
|
|
|
|
|
|
|
class FetchDriverObserver
|
|
|
|
{
|
|
|
|
public:
|
2015-09-14 15:05:35 +00:00
|
|
|
FetchDriverObserver() : mGotResponseAvailable(false)
|
|
|
|
{ }
|
|
|
|
|
2014-10-06 18:01:20 +00:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FetchDriverObserver);
|
2015-09-14 15:05:35 +00:00
|
|
|
void OnResponseAvailable(InternalResponse* aResponse)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mGotResponseAvailable);
|
|
|
|
mGotResponseAvailable = true;
|
|
|
|
OnResponseAvailableInternal(aResponse);
|
|
|
|
}
|
2015-01-15 04:59:00 +00:00
|
|
|
virtual void OnResponseEnd()
|
|
|
|
{ };
|
2014-10-06 18:01:20 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~FetchDriverObserver()
|
|
|
|
{ };
|
2015-09-14 15:05:35 +00:00
|
|
|
|
|
|
|
virtual void OnResponseAvailableInternal(InternalResponse* aResponse) = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mGotResponseAvailable;
|
2014-10-06 18:01:20 +00:00
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class FetchDriver final : public nsIStreamListener,
|
2016-01-19 21:54:15 +00:00
|
|
|
public nsIChannelEventSink,
|
2015-03-27 18:52:19 +00:00
|
|
|
public nsIInterfaceRequestor,
|
2015-08-28 20:49:07 +00:00
|
|
|
public nsIThreadRetargetableStreamListener
|
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
|
2016-01-19 21:54:15 +00:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
2015-01-07 21:47:18 +00:00
|
|
|
NS_DECL_NSIINTERFACEREQUESTOR
|
2015-08-28 20:49:07 +00:00
|
|
|
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
|
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
|
2015-03-05 20:16:18 +00:00
|
|
|
SetDocument(nsIDocument* aDocument);
|
2014-12-23 15:56:19 +00:00
|
|
|
|
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;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<InternalRequest> mRequest;
|
|
|
|
RefPtr<InternalResponse> mResponse;
|
2014-12-10 08:51:59 +00:00
|
|
|
nsCOMPtr<nsIOutputStream> mPipeOutputStream;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<FetchDriverObserver> mObserver;
|
2014-10-14 23:36:58 +00:00
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
2014-10-06 18:01:20 +00:00
|
|
|
|
2014-12-10 08:51:59 +00:00
|
|
|
DebugOnly<bool> mResponseAvailableCalled;
|
2015-10-20 01:24:36 +00:00
|
|
|
DebugOnly<bool> mFetchCalled;
|
2014-12-10 08:51:59 +00:00
|
|
|
|
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();
|
|
|
|
|
2015-10-20 01:24:36 +00:00
|
|
|
nsresult ContinueFetch();
|
2015-10-20 01:24:36 +00:00
|
|
|
nsresult HttpFetch();
|
2014-12-10 08:51:59 +00:00
|
|
|
// Returns the filtered response sent to the observer.
|
2015-06-09 19:21:13 +00:00
|
|
|
// Callers who don't have access to a channel can pass null for aFinalURI.
|
2014-12-10 08:51:59 +00:00
|
|
|
already_AddRefed<InternalResponse>
|
2015-11-24 02:47:10 +00:00
|
|
|
BeginAndGetFilteredResponse(InternalResponse* aResponse, nsIURI* aFinalURI,
|
|
|
|
bool aFoundOpaqueRedirect);
|
2014-12-10 08:51:59 +00:00
|
|
|
// Utility since not all cases need to do any post processing of the filtered
|
|
|
|
// response.
|
2014-10-06 18:01:20 +00:00
|
|
|
nsresult FailWithNetworkError();
|
2016-01-19 21:54:15 +00:00
|
|
|
|
|
|
|
void SetRequestHeaders(nsIHttpChannel* aChannel) const;
|
2014-10-06 18:01:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_FetchDriver_h
|