gecko-dev/dom/fetch/FetchDriver.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

195 строки
5.9 KiB
C
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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
#include "nsIChannelEventSink.h"
#include "nsICacheInfoChannel.h"
#include "nsIInterfaceRequestor.h"
#include "nsIStreamListener.h"
#include "nsIThreadRetargetableStreamListener.h"
#include "mozilla/ConsoleReportCollector.h"
#include "mozilla/dom/AbortSignal.h"
#include "mozilla/dom/SerializedStackHolder.h"
#include "mozilla/dom/SRIMetadata.h"
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
#include "mozilla/RefPtr.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/net/ReferrerPolicy.h"
class nsIConsoleReportCollector;
class nsICookieSettings;
class nsICSPEventListener;
class nsIEventTarget;
class nsIOutputStream;
class nsILoadGroup;
class nsIPrincipal;
namespace mozilla {
namespace dom {
class Document;
class InternalRequest;
class InternalResponse;
class PerformanceStorage;
/**
* Provides callbacks to be called when response is available or on error.
* Implemenations usually resolve or reject the promise returned from fetch().
* The callbacks can be called synchronously or asynchronously from
* FetchDriver::Fetch.
*/
class FetchDriverObserver {
public:
FetchDriverObserver()
: mReporter(new ConsoleReportCollector()), mGotResponseAvailable(false) {}
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FetchDriverObserver);
void OnResponseAvailable(InternalResponse* aResponse) {
MOZ_ASSERT(!mGotResponseAvailable);
mGotResponseAvailable = true;
OnResponseAvailableInternal(aResponse);
}
enum EndReason {
eAborted,
eByNetworking,
};
virtual void OnResponseEnd(EndReason aReason){};
nsIConsoleReportCollector* GetReporter() const { return mReporter; }
virtual void FlushConsoleReport() = 0;
// Called in OnStartRequest() to determine if the OnDataAvailable() method
// needs to be called. Invoking that method may generate additional main
// thread runnables.
virtual bool NeedOnDataAvailable() = 0;
// Called once when the first byte of data is received iff
// NeedOnDataAvailable() returned true when called in OnStartRequest().
virtual void OnDataAvailable() = 0;
protected:
virtual ~FetchDriverObserver(){};
virtual void OnResponseAvailableInternal(InternalResponse* aResponse) = 0;
nsCOMPtr<nsIConsoleReportCollector> mReporter;
private:
bool mGotResponseAvailable;
};
class AlternativeDataStreamListener;
class FetchDriver final : public nsIStreamListener,
public nsIChannelEventSink,
public nsIInterfaceRequestor,
public nsIThreadRetargetableStreamListener,
public AbortFollower {
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSICHANNELEVENTSINK
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
FetchDriver(InternalRequest* aRequest, nsIPrincipal* aPrincipal,
nsILoadGroup* aLoadGroup, nsIEventTarget* aMainThreadEventTarget,
nsICookieSettings* aCookieSettings,
PerformanceStorage* aPerformanceStorage, bool aIsTrackingFetch);
nsresult Fetch(AbortSignalImpl* aSignalImpl, FetchDriverObserver* aObserver);
void SetDocument(Document* aDocument);
void SetCSPEventListener(nsICSPEventListener* aCSPEventListener);
void SetClientInfo(const ClientInfo& aClientInfo);
void SetController(const Maybe<ServiceWorkerDescriptor>& aController);
void SetWorkerScript(const nsACString& aWorkerScript) {
MOZ_ASSERT(!aWorkerScript.IsEmpty());
mWorkerScript = aWorkerScript;
}
void SetOriginStack(UniquePtr<SerializedStackHolder>&& aOriginStack) {
mOriginStack = std::move(aOriginStack);
}
// AbortFollower
void Abort() override;
private:
nsCOMPtr<nsIPrincipal> mPrincipal;
nsCOMPtr<nsILoadGroup> mLoadGroup;
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<InternalRequest> mRequest;
RefPtr<InternalResponse> mResponse;
nsCOMPtr<nsIOutputStream> mPipeOutputStream;
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<FetchDriverObserver> mObserver;
RefPtr<Document> mDocument;
nsCOMPtr<nsICSPEventListener> mCSPEventListener;
Maybe<ClientInfo> mClientInfo;
Maybe<ServiceWorkerDescriptor> mController;
nsCOMPtr<nsIChannel> mChannel;
nsAutoPtr<SRICheckDataVerifier> mSRIDataVerifier;
nsCOMPtr<nsIEventTarget> mMainThreadEventTarget;
nsCOMPtr<nsICookieSettings> mCookieSettings;
// This is set only when Fetch is used in workers.
RefPtr<PerformanceStorage> mPerformanceStorage;
SRIMetadata mSRIMetadata;
nsCString mWorkerScript;
UniquePtr<SerializedStackHolder> mOriginStack;
// This is written once in OnStartRequest on the main thread and then
// written/read in OnDataAvailable() on any thread. Necko guarantees
// that these do not overlap.
bool mNeedToObserveOnDataAvailable;
bool mIsTrackingFetch;
RefPtr<AlternativeDataStreamListener> mAltDataListener;
bool mOnStopRequestCalled;
#ifdef DEBUG
bool mResponseAvailableCalled;
bool mFetchCalled;
#endif
friend class AlternativeDataStreamListener;
FetchDriver() = delete;
FetchDriver(const FetchDriver&) = delete;
FetchDriver& operator=(const FetchDriver&) = delete;
~FetchDriver();
nsresult HttpFetch(
const nsACString& aPreferredAlternativeDataType = EmptyCString());
// Returns the filtered response sent to the observer.
already_AddRefed<InternalResponse> BeginAndGetFilteredResponse(
InternalResponse* aResponse, bool aFoundOpaqueRedirect);
// Utility since not all cases need to do any post processing of the filtered
// response.
void FailWithNetworkError(nsresult rv);
void SetRequestHeaders(nsIHttpChannel* aChannel) const;
nsresult FinishOnStopRequest(AlternativeDataStreamListener* aAltDataListener);
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_FetchDriver_h