gecko-dev/dom/fetch/InternalResponse.h

256 строки
5.6 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_InternalResponse_h
#define mozilla_dom_InternalResponse_h
#include "nsIInputStream.h"
#include "nsISupportsImpl.h"
#include "mozilla/dom/ResponseBinding.h"
#include "mozilla/dom/ChannelInfo.h"
#include "mozilla/UniquePtr.h"
namespace mozilla {
namespace ipc {
class PrincipalInfo;
} // namespace ipc
namespace dom {
class InternalHeaders;
class InternalResponse final
{
friend class FetchDriver;
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(InternalResponse)
InternalResponse(uint16_t aStatus, const nsACString& aStatusText);
already_AddRefed<InternalResponse> Clone();
static already_AddRefed<InternalResponse>
NetworkError()
{
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<InternalResponse> response = new InternalResponse(0, EmptyCString());
ErrorResult result;
response->Headers()->SetGuard(HeadersGuardEnum::Immutable, result);
MOZ_ASSERT(!result.Failed());
response->mType = ResponseType::Error;
return response.forget();
}
already_AddRefed<InternalResponse>
OpaqueResponse();
already_AddRefed<InternalResponse>
OpaqueRedirectResponse();
already_AddRefed<InternalResponse>
BasicResponse();
already_AddRefed<InternalResponse>
CORSResponse();
ResponseType
Type() const
{
MOZ_ASSERT_IF(mType == ResponseType::Error, !mWrappedResponse);
MOZ_ASSERT_IF(mType == ResponseType::Default, !mWrappedResponse);
MOZ_ASSERT_IF(mType == ResponseType::Basic, mWrappedResponse);
MOZ_ASSERT_IF(mType == ResponseType::Cors, mWrappedResponse);
MOZ_ASSERT_IF(mType == ResponseType::Opaque, mWrappedResponse);
MOZ_ASSERT_IF(mType == ResponseType::Opaqueredirect, mWrappedResponse);
return mType;
}
bool
IsError() const
{
return Type() == ResponseType::Error;
}
// FIXME(nsm): Return with exclude fragment.
void
GetUrl(nsCString& aURL) const
{
aURL.Assign(mURL);
}
void
GetUnfilteredUrl(nsCString& aURL) const
{
if (mWrappedResponse) {
return mWrappedResponse->GetUrl(aURL);
}
return GetUrl(aURL);
}
// SetUrl should only be called when the fragment has alredy been stripped
void
SetUrl(const nsACString& aURL)
{
mURL.Assign(aURL);
}
uint16_t
GetStatus() const
{
return mStatus;
}
uint16_t
GetUnfilteredStatus() const
{
if (mWrappedResponse) {
return mWrappedResponse->GetStatus();
}
return GetStatus();
}
const nsCString&
GetStatusText() const
{
return mStatusText;
}
const nsCString&
GetUnfilteredStatusText() const
{
if (mWrappedResponse) {
return mWrappedResponse->GetStatusText();
}
return GetStatusText();
}
InternalHeaders*
Headers()
{
return mHeaders;
}
InternalHeaders*
UnfilteredHeaders()
{
if (mWrappedResponse) {
return mWrappedResponse->Headers();
};
return Headers();
}
void
GetUnfilteredBody(nsIInputStream** aStream)
{
if (mWrappedResponse) {
MOZ_ASSERT(!mBody);
return mWrappedResponse->GetBody(aStream);
}
nsCOMPtr<nsIInputStream> stream = mBody;
stream.forget(aStream);
}
void
GetBody(nsIInputStream** aStream)
{
if (Type() == ResponseType::Opaque ||
Type() == ResponseType::Opaqueredirect) {
*aStream = nullptr;
return;
}
return GetUnfilteredBody(aStream);
}
void
SetBody(nsIInputStream* aBody)
{
if (mWrappedResponse) {
return mWrappedResponse->SetBody(aBody);
}
// A request's body may not be reset once set.
MOZ_ASSERT(!mBody);
mBody = aBody;
}
void
InitChannelInfo(nsIChannel* aChannel)
{
mChannelInfo.InitFromChannel(aChannel);
}
void
InitChannelInfo(const mozilla::ipc::IPCChannelInfo& aChannelInfo)
{
mChannelInfo.InitFromIPCChannelInfo(aChannelInfo);
}
void
InitChannelInfo(const ChannelInfo& aChannelInfo)
{
mChannelInfo = aChannelInfo;
}
const ChannelInfo&
GetChannelInfo() const
{
return mChannelInfo;
}
const UniquePtr<mozilla::ipc::PrincipalInfo>&
GetPrincipalInfo() const
{
return mPrincipalInfo;
}
// Takes ownership of the principal info.
void
SetPrincipalInfo(UniquePtr<mozilla::ipc::PrincipalInfo> aPrincipalInfo);
nsresult
StripFragmentAndSetUrl(const nsACString& aUrl);
LoadTainting
GetTainting() const;
private:
~InternalResponse();
explicit InternalResponse(const InternalResponse& aOther) = delete;
InternalResponse& operator=(const InternalResponse&) = delete;
// Returns an instance of InternalResponse which is a copy of this
// InternalResponse, except headers, body and wrapped response (if any) which
// are left uninitialized. Used for cloning and filtering.
already_AddRefed<InternalResponse> CreateIncompleteCopy();
ResponseType mType;
nsCString mTerminationReason;
nsCString mURL;
const uint16_t mStatus;
const nsCString mStatusText;
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<InternalHeaders> mHeaders;
nsCOMPtr<nsIInputStream> mBody;
ChannelInfo mChannelInfo;
UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
// For filtered responses.
// Cache, and SW interception should always serialize/access the underlying
// unfiltered headers and when deserializing, create an InternalResponse
// with the unfiltered headers followed by wrapping it.
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<InternalResponse> mWrappedResponse;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_InternalResponse_h