2015-05-03 22:32:37 +03: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-09-27 03:41:15 +04: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_InternalResponse_h
|
|
|
|
#define mozilla_dom_InternalResponse_h
|
|
|
|
|
2021-11-22 17:09:24 +03:00
|
|
|
#include "mozilla/dom/FetchTypes.h"
|
2014-10-02 21:59:20 +04:00
|
|
|
#include "nsIInputStream.h"
|
2017-12-04 09:39:15 +03:00
|
|
|
#include "nsICacheInfoChannel.h"
|
2014-09-27 03:41:15 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
2017-12-05 20:13:54 +03:00
|
|
|
#include "nsProxyRelease.h"
|
2014-09-27 03:41:15 +04:00
|
|
|
|
2017-08-11 04:04:55 +03:00
|
|
|
#include "mozilla/dom/InternalHeaders.h"
|
2019-07-16 11:50:14 +03:00
|
|
|
#include "mozilla/dom/RequestBinding.h"
|
2014-09-27 03:41:15 +04:00
|
|
|
#include "mozilla/dom/ResponseBinding.h"
|
2015-05-25 21:21:05 +03:00
|
|
|
#include "mozilla/dom/ChannelInfo.h"
|
2021-11-08 16:29:32 +03:00
|
|
|
#include "mozilla/dom/SafeRefPtr.h"
|
2021-11-22 17:09:24 +03:00
|
|
|
#include "mozilla/NotNull.h"
|
2015-06-05 07:39:34 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2014-09-27 03:41:15 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-06-05 07:39:34 +03:00
|
|
|
namespace ipc {
|
Bug 1622451 - minimize stream copying across IPC boundaries r=asuth,baku
Initially, IPCInternal{Request,Response} had contained IPCStreams which would
result in unecessary copying when sending the objects over IPC. The patch
makes these streams either:
1) ParentToParentStream (just a UUID)
2) ParentToChildStream (a PIPCBlobInputStream actor, acting as a handle)
3) ChildToParentStream (a real IPCStream)
These three types are union-ed together by the BodyStreamVariant IPDL structure.
This structure replaces the IPCStream members in IPCInternal{Request,Response}
so that, depending on the particular IPDL protocol, we can avoid cloning streams
and just pass handles/IDs instead.
As a side effect, this makes file-backed Response objects cloneable. Initially,
these Responses would be backed by an nsFileInputStream, which is not cloneable
outside the parent process. They are now backed by IPCBlobInputStreams, which
are cloneable.
One thing that's not really satisfactory (IMO), is the manual management of
IPCBlobInputStreamStorage so that no streams are leaked, e.g. if we store a
stream in the IPCBlobInputStreamStorage but fail to send an IPC message and
therefore fail to remove the stream from storage on the other side of the IPC
boundary (only parent-to-parent in this case).
Differential Revision: https://phabricator.services.mozilla.com/D73173
2020-05-29 12:09:54 +03:00
|
|
|
class PBackgroundChild;
|
2021-11-22 17:09:24 +03:00
|
|
|
class PBackgroundParent;
|
Bug 1622451 - minimize stream copying across IPC boundaries r=asuth,baku
Initially, IPCInternal{Request,Response} had contained IPCStreams which would
result in unecessary copying when sending the objects over IPC. The patch
makes these streams either:
1) ParentToParentStream (just a UUID)
2) ParentToChildStream (a PIPCBlobInputStream actor, acting as a handle)
3) ChildToParentStream (a real IPCStream)
These three types are union-ed together by the BodyStreamVariant IPDL structure.
This structure replaces the IPCStream members in IPCInternal{Request,Response}
so that, depending on the particular IPDL protocol, we can avoid cloning streams
and just pass handles/IDs instead.
As a side effect, this makes file-backed Response objects cloneable. Initially,
these Responses would be backed by an nsFileInputStream, which is not cloneable
outside the parent process. They are now backed by IPCBlobInputStreams, which
are cloneable.
One thing that's not really satisfactory (IMO), is the manual management of
IPCBlobInputStreamStorage so that no streams are leaked, e.g. if we store a
stream in the IPCBlobInputStreamStorage but fail to send an IPC message and
therefore fail to remove the stream from storage on the other side of the IPC
boundary (only parent-to-parent in this case).
Differential Revision: https://phabricator.services.mozilla.com/D73173
2020-05-29 12:09:54 +03:00
|
|
|
class PrincipalInfo;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace ipc
|
2015-06-05 07:39:34 +03:00
|
|
|
|
2014-09-27 03:41:15 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2021-11-19 19:45:19 +03:00
|
|
|
class ChildToParentInternalResponse;
|
2014-10-02 21:59:20 +04:00
|
|
|
class InternalHeaders;
|
2021-11-19 19:45:19 +03:00
|
|
|
class ParentToChildInternalResponse;
|
|
|
|
class ParentToParentInternalResponse;
|
2014-10-02 21:59:20 +04:00
|
|
|
|
2021-11-08 16:29:32 +03:00
|
|
|
class InternalResponse final : public AtomicSafeRefCounted<InternalResponse> {
|
2014-09-27 03:41:15 +04:00
|
|
|
friend class FetchDriver;
|
|
|
|
|
|
|
|
public:
|
2021-11-08 16:29:32 +03:00
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(InternalResponse)
|
2014-09-27 03:41:15 +04:00
|
|
|
|
2019-07-16 11:50:14 +03:00
|
|
|
InternalResponse(
|
|
|
|
uint16_t aStatus, const nsACString& aStatusText,
|
|
|
|
RequestCredentials aCredentialsMode = RequestCredentials::Omit);
|
2014-09-27 03:41:15 +04:00
|
|
|
|
2021-11-08 16:29:32 +03:00
|
|
|
static SafeRefPtr<InternalResponse> FromIPC(
|
2021-11-19 19:45:19 +03:00
|
|
|
const ParentToChildInternalResponse& aIPCResponse);
|
2019-08-15 20:26:15 +03:00
|
|
|
|
2021-11-19 19:45:19 +03:00
|
|
|
static SafeRefPtr<InternalResponse> FromIPC(
|
|
|
|
const ParentToParentInternalResponse& aIPCResponse);
|
|
|
|
|
2021-11-22 17:09:24 +03:00
|
|
|
void ToChildToParentInternalResponse(
|
2021-11-19 19:45:19 +03:00
|
|
|
ChildToParentInternalResponse* aIPCResponse,
|
2022-05-13 17:16:13 +03:00
|
|
|
mozilla::ipc::PBackgroundChild* aManager);
|
2019-08-15 20:26:15 +03:00
|
|
|
|
2021-11-22 17:09:24 +03:00
|
|
|
ParentToParentInternalResponse ToParentToParentInternalResponse();
|
|
|
|
|
2023-01-20 12:09:17 +03:00
|
|
|
ParentToChildInternalResponse ToParentToChildInternalResponse(
|
|
|
|
NotNull<mozilla::ipc::PBackgroundParent*> aBackgroundParent);
|
|
|
|
|
2017-08-11 04:04:55 +03:00
|
|
|
enum CloneType {
|
|
|
|
eCloneInputStream,
|
|
|
|
eDontCloneInputStream,
|
|
|
|
};
|
|
|
|
|
2021-11-08 16:29:32 +03:00
|
|
|
SafeRefPtr<InternalResponse> Clone(CloneType aCloneType);
|
2015-02-20 04:24:24 +03:00
|
|
|
|
2021-11-08 16:29:32 +03:00
|
|
|
static SafeRefPtr<InternalResponse> NetworkError(nsresult aRv) {
|
2017-11-15 22:53:42 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(NS_FAILED(aRv));
|
2021-11-08 16:29:32 +03:00
|
|
|
SafeRefPtr<InternalResponse> response =
|
|
|
|
MakeSafeRefPtr<InternalResponse>(0, ""_ns);
|
2015-03-08 05:54:41 +03:00
|
|
|
ErrorResult result;
|
|
|
|
response->Headers()->SetGuard(HeadersGuardEnum::Immutable, result);
|
|
|
|
MOZ_ASSERT(!result.Failed());
|
2014-09-27 03:41:15 +04:00
|
|
|
response->mType = ResponseType::Error;
|
2017-11-15 22:53:42 +03:00
|
|
|
response->mErrorCode = aRv;
|
2021-11-08 16:29:32 +03:00
|
|
|
return response;
|
2014-09-27 03:41:15 +04:00
|
|
|
}
|
|
|
|
|
2021-11-08 16:29:32 +03:00
|
|
|
SafeRefPtr<InternalResponse> OpaqueResponse();
|
2014-10-06 22:01:20 +04:00
|
|
|
|
2021-11-08 16:29:32 +03:00
|
|
|
SafeRefPtr<InternalResponse> OpaqueRedirectResponse();
|
2015-09-01 00:26:29 +03:00
|
|
|
|
2021-11-08 16:29:32 +03:00
|
|
|
SafeRefPtr<InternalResponse> BasicResponse();
|
2014-10-06 22:01:20 +04:00
|
|
|
|
2021-11-08 16:29:32 +03:00
|
|
|
SafeRefPtr<InternalResponse> CORSResponse();
|
2014-10-06 22:01:20 +04:00
|
|
|
|
2014-09-27 03:41:15 +04:00
|
|
|
ResponseType Type() const {
|
2015-03-17 18:47:01 +03:00
|
|
|
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);
|
2015-09-01 00:26:29 +03:00
|
|
|
MOZ_ASSERT_IF(mType == ResponseType::Opaqueredirect, mWrappedResponse);
|
2014-09-27 03:41:15 +04:00
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsError() const { return Type() == ResponseType::Error; }
|
2016-05-03 04:48:40 +03:00
|
|
|
// GetUrl should return last fetch URL in response's url list and null if
|
|
|
|
// response's url list is the empty list.
|
2016-11-07 09:59:00 +03:00
|
|
|
const nsCString& GetURL() const {
|
2016-05-03 04:48:40 +03:00
|
|
|
// Empty urlList when response is a synthetic response.
|
|
|
|
if (mURLList.IsEmpty()) {
|
2016-11-07 09:59:00 +03:00
|
|
|
return EmptyCString();
|
2016-05-03 04:48:40 +03:00
|
|
|
}
|
2016-11-07 09:59:00 +03:00
|
|
|
return mURLList.LastElement();
|
2014-10-06 22:01:20 +04:00
|
|
|
}
|
2016-05-03 04:48:40 +03:00
|
|
|
void GetURLList(nsTArray<nsCString>& aURLList) const {
|
|
|
|
aURLList.Assign(mURLList);
|
|
|
|
}
|
2016-11-07 09:59:00 +03:00
|
|
|
const nsCString& GetUnfilteredURL() const {
|
2015-09-18 23:41:56 +03:00
|
|
|
if (mWrappedResponse) {
|
2016-11-07 09:59:00 +03:00
|
|
|
return mWrappedResponse->GetURL();
|
2015-09-18 23:41:56 +03:00
|
|
|
}
|
2016-11-07 09:59:00 +03:00
|
|
|
return GetURL();
|
2015-09-18 23:41:56 +03:00
|
|
|
}
|
2016-05-03 04:48:40 +03:00
|
|
|
void GetUnfilteredURLList(nsTArray<nsCString>& aURLList) const {
|
|
|
|
if (mWrappedResponse) {
|
|
|
|
return mWrappedResponse->GetURLList(aURLList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetURLList(aURLList);
|
|
|
|
}
|
|
|
|
|
Bug 1622451 - minimize stream copying across IPC boundaries r=asuth,baku
Initially, IPCInternal{Request,Response} had contained IPCStreams which would
result in unecessary copying when sending the objects over IPC. The patch
makes these streams either:
1) ParentToParentStream (just a UUID)
2) ParentToChildStream (a PIPCBlobInputStream actor, acting as a handle)
3) ChildToParentStream (a real IPCStream)
These three types are union-ed together by the BodyStreamVariant IPDL structure.
This structure replaces the IPCStream members in IPCInternal{Request,Response}
so that, depending on the particular IPDL protocol, we can avoid cloning streams
and just pass handles/IDs instead.
As a side effect, this makes file-backed Response objects cloneable. Initially,
these Responses would be backed by an nsFileInputStream, which is not cloneable
outside the parent process. They are now backed by IPCBlobInputStreams, which
are cloneable.
One thing that's not really satisfactory (IMO), is the manual management of
IPCBlobInputStreamStorage so that no streams are leaked, e.g. if we store a
stream in the IPCBlobInputStreamStorage but fail to send an IPC message and
therefore fail to remove the stream from storage on the other side of the IPC
boundary (only parent-to-parent in this case).
Differential Revision: https://phabricator.services.mozilla.com/D73173
2020-05-29 12:09:54 +03:00
|
|
|
nsTArray<nsCString> GetUnfilteredURLList() const {
|
|
|
|
nsTArray<nsCString> list;
|
|
|
|
GetUnfilteredURLList(list);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2016-05-03 04:48:40 +03:00
|
|
|
void SetURLList(const nsTArray<nsCString>& aURLList) {
|
|
|
|
mURLList.Assign(aURLList);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
for (uint32_t i = 0; i < mURLList.Length(); ++i) {
|
|
|
|
MOZ_ASSERT(mURLList[i].Find("#"_ns) == kNotFound);
|
|
|
|
}
|
|
|
|
#endif
|
2014-09-27 03:41:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t GetStatus() const { return mStatus; }
|
|
|
|
|
2015-09-01 00:26:29 +03:00
|
|
|
uint16_t GetUnfilteredStatus() const {
|
|
|
|
if (mWrappedResponse) {
|
|
|
|
return mWrappedResponse->GetStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetStatus();
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:41:15 +04:00
|
|
|
const nsCString& GetStatusText() const { return mStatusText; }
|
|
|
|
|
2015-09-01 00:26:29 +03:00
|
|
|
const nsCString& GetUnfilteredStatusText() const {
|
|
|
|
if (mWrappedResponse) {
|
|
|
|
return mWrappedResponse->GetStatusText();
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetStatusText();
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:41:15 +04:00
|
|
|
InternalHeaders* Headers() { return mHeaders; }
|
|
|
|
|
2015-03-17 18:47:01 +03:00
|
|
|
InternalHeaders* UnfilteredHeaders() {
|
|
|
|
if (mWrappedResponse) {
|
|
|
|
return mWrappedResponse->Headers();
|
|
|
|
};
|
|
|
|
|
|
|
|
return Headers();
|
|
|
|
}
|
|
|
|
|
2016-06-02 00:02:29 +03:00
|
|
|
void GetUnfilteredBody(nsIInputStream** aStream,
|
|
|
|
int64_t* aBodySize = nullptr) {
|
2015-03-17 18:47:01 +03:00
|
|
|
if (mWrappedResponse) {
|
|
|
|
MOZ_ASSERT(!mBody);
|
2016-06-02 00:02:29 +03:00
|
|
|
return mWrappedResponse->GetBody(aStream, aBodySize);
|
2015-03-17 18:47:01 +03:00
|
|
|
}
|
2014-09-27 03:41:15 +04:00
|
|
|
nsCOMPtr<nsIInputStream> stream = mBody;
|
|
|
|
stream.forget(aStream);
|
2016-06-02 00:02:29 +03:00
|
|
|
if (aBodySize) {
|
|
|
|
*aBodySize = mBodySize;
|
|
|
|
}
|
2014-09-27 03:41:15 +04:00
|
|
|
}
|
|
|
|
|
2016-06-02 00:02:29 +03:00
|
|
|
void GetBody(nsIInputStream** aStream, int64_t* aBodySize = nullptr) {
|
2015-09-01 00:26:29 +03:00
|
|
|
if (Type() == ResponseType::Opaque ||
|
|
|
|
Type() == ResponseType::Opaqueredirect) {
|
2015-06-13 04:59:01 +03:00
|
|
|
*aStream = nullptr;
|
2016-06-02 00:02:29 +03:00
|
|
|
if (aBodySize) {
|
|
|
|
*aBodySize = UNKNOWN_BODY_SIZE;
|
|
|
|
}
|
2015-06-13 04:59:01 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-08 17:06:26 +03:00
|
|
|
GetUnfilteredBody(aStream, aBodySize);
|
2015-06-13 04:59:01 +03:00
|
|
|
}
|
|
|
|
|
2018-10-06 20:34:24 +03:00
|
|
|
void SetBodyBlobURISpec(nsACString& aBlobURISpec) {
|
|
|
|
mBodyBlobURISpec = aBlobURISpec;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsACString& BodyBlobURISpec() const {
|
|
|
|
if (mWrappedResponse) {
|
|
|
|
return mWrappedResponse->BodyBlobURISpec();
|
|
|
|
}
|
|
|
|
return mBodyBlobURISpec;
|
|
|
|
}
|
|
|
|
|
2018-09-11 22:13:15 +03:00
|
|
|
void SetBodyLocalPath(nsAString& aLocalPath) { mBodyLocalPath = aLocalPath; }
|
|
|
|
|
|
|
|
const nsAString& BodyLocalPath() const {
|
|
|
|
if (mWrappedResponse) {
|
|
|
|
return mWrappedResponse->BodyLocalPath();
|
|
|
|
}
|
|
|
|
return mBodyLocalPath;
|
|
|
|
}
|
|
|
|
|
2016-06-02 00:02:29 +03:00
|
|
|
void SetBody(nsIInputStream* aBody, int64_t aBodySize) {
|
2015-03-17 18:47:01 +03:00
|
|
|
if (mWrappedResponse) {
|
2016-06-02 00:02:29 +03:00
|
|
|
return mWrappedResponse->SetBody(aBody, aBodySize);
|
2015-03-17 18:47:01 +03:00
|
|
|
}
|
2014-12-10 11:51:59 +03:00
|
|
|
// A request's body may not be reset once set.
|
|
|
|
MOZ_ASSERT(!mBody);
|
2016-06-02 00:02:29 +03:00
|
|
|
MOZ_ASSERT(mBodySize == UNKNOWN_BODY_SIZE);
|
|
|
|
// Check arguments.
|
|
|
|
MOZ_ASSERT(aBodySize == UNKNOWN_BODY_SIZE || aBodySize >= 0);
|
|
|
|
// If body is not given, then size must be unknown.
|
|
|
|
MOZ_ASSERT_IF(!aBody, aBodySize == UNKNOWN_BODY_SIZE);
|
|
|
|
|
2014-09-27 03:41:15 +04:00
|
|
|
mBody = aBody;
|
2016-06-02 00:02:29 +03:00
|
|
|
mBodySize = aBodySize;
|
2014-09-27 03:41:15 +04:00
|
|
|
}
|
|
|
|
|
2017-07-10 12:03:24 +03:00
|
|
|
uint32_t GetPaddingInfo();
|
|
|
|
|
|
|
|
nsresult GeneratePaddingInfo();
|
|
|
|
|
2017-07-10 12:11:29 +03:00
|
|
|
int64_t GetPaddingSize();
|
|
|
|
|
|
|
|
void SetPaddingSize(int64_t aPaddingSize);
|
|
|
|
|
2019-08-15 20:26:15 +03:00
|
|
|
void SetAlternativeDataType(const nsACString& aAltDataType) {
|
|
|
|
if (mWrappedResponse) {
|
|
|
|
return mWrappedResponse->SetAlternativeDataType(aAltDataType);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mAlternativeDataType.IsEmpty());
|
|
|
|
|
|
|
|
mAlternativeDataType.Assign(aAltDataType);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCString& GetAlternativeDataType() {
|
|
|
|
if (mWrappedResponse) {
|
|
|
|
return mWrappedResponse->GetAlternativeDataType();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mAlternativeDataType;
|
|
|
|
}
|
|
|
|
|
2017-12-04 09:39:15 +03:00
|
|
|
void SetAlternativeBody(nsIInputStream* aAlternativeBody) {
|
|
|
|
if (mWrappedResponse) {
|
|
|
|
return mWrappedResponse->SetAlternativeBody(aAlternativeBody);
|
|
|
|
}
|
|
|
|
// A request's body may not be reset once set.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mAlternativeBody);
|
|
|
|
|
|
|
|
mAlternativeBody = aAlternativeBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIInputStream> TakeAlternativeBody() {
|
|
|
|
if (mWrappedResponse) {
|
|
|
|
return mWrappedResponse->TakeAlternativeBody();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mAlternativeBody) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup the non-alternative body here.
|
|
|
|
// Once alternative data is used, the real body is no need anymore.
|
|
|
|
mBody = nullptr;
|
|
|
|
mBodySize = UNKNOWN_BODY_SIZE;
|
|
|
|
return mAlternativeBody.forget();
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:13:54 +03:00
|
|
|
void SetCacheInfoChannel(
|
|
|
|
const nsMainThreadPtrHandle<nsICacheInfoChannel>& aCacheInfoChannel) {
|
2017-12-04 09:39:15 +03:00
|
|
|
if (mWrappedResponse) {
|
|
|
|
return mWrappedResponse->SetCacheInfoChannel(aCacheInfoChannel);
|
|
|
|
}
|
2017-12-05 20:13:54 +03:00
|
|
|
MOZ_ASSERT(!mCacheInfoChannel);
|
2017-12-04 09:39:15 +03:00
|
|
|
mCacheInfoChannel = aCacheInfoChannel;
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:13:54 +03:00
|
|
|
nsMainThreadPtrHandle<nsICacheInfoChannel> TakeCacheInfoChannel() {
|
2017-12-04 09:39:15 +03:00
|
|
|
if (mWrappedResponse) {
|
2017-12-04 09:39:26 +03:00
|
|
|
return mWrappedResponse->TakeCacheInfoChannel();
|
2017-12-04 09:39:15 +03:00
|
|
|
}
|
2017-12-05 20:13:54 +03:00
|
|
|
nsMainThreadPtrHandle<nsICacheInfoChannel> rtn = mCacheInfoChannel;
|
|
|
|
mCacheInfoChannel = nullptr;
|
|
|
|
return rtn;
|
2017-12-04 09:39:15 +03:00
|
|
|
}
|
|
|
|
|
2019-02-20 13:05:35 +03:00
|
|
|
bool HasCacheInfoChannel() const {
|
|
|
|
if (mWrappedResponse) {
|
|
|
|
return !!mWrappedResponse->HasCacheInfoChannel();
|
|
|
|
}
|
|
|
|
return !!mCacheInfoChannel;
|
|
|
|
}
|
|
|
|
|
2021-10-16 00:13:44 +03:00
|
|
|
bool HasBeenCloned() const { return mCloned; }
|
|
|
|
|
2023-01-20 12:09:17 +03:00
|
|
|
void SetSerializeAsLazy(bool aAllow) { mSerializeAsLazy = aAllow; }
|
|
|
|
bool CanSerializeAsLazy() const { return mSerializeAsLazy; }
|
|
|
|
|
2015-05-25 21:21:05 +03:00
|
|
|
void InitChannelInfo(nsIChannel* aChannel) {
|
|
|
|
mChannelInfo.InitFromChannel(aChannel);
|
2015-03-05 00:05:21 +03:00
|
|
|
}
|
|
|
|
|
2022-09-10 01:14:18 +03:00
|
|
|
void InitChannelInfo(nsITransportSecurityInfo* aSecurityInfo) {
|
|
|
|
mChannelInfo.InitFromTransportSecurityInfo(aSecurityInfo);
|
2015-05-25 21:21:05 +03:00
|
|
|
}
|
2015-03-05 00:05:21 +03:00
|
|
|
|
2015-05-25 21:21:05 +03:00
|
|
|
void InitChannelInfo(const ChannelInfo& aChannelInfo) {
|
|
|
|
mChannelInfo = aChannelInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ChannelInfo& GetChannelInfo() const { return mChannelInfo; }
|
2015-03-05 00:05:21 +03:00
|
|
|
|
2015-06-05 07:39:34 +03:00
|
|
|
const UniquePtr<mozilla::ipc::PrincipalInfo>& GetPrincipalInfo() const {
|
|
|
|
return mPrincipalInfo;
|
|
|
|
}
|
|
|
|
|
2016-05-03 04:48:40 +03:00
|
|
|
bool IsRedirected() const { return mURLList.Length() > 1; }
|
|
|
|
|
2017-11-15 22:53:42 +03:00
|
|
|
nsresult GetErrorCode() const { return mErrorCode; }
|
|
|
|
|
2015-06-05 07:39:34 +03:00
|
|
|
// Takes ownership of the principal info.
|
|
|
|
void SetPrincipalInfo(UniquePtr<mozilla::ipc::PrincipalInfo> aPrincipalInfo);
|
|
|
|
|
2015-10-22 21:07:32 +03:00
|
|
|
LoadTainting GetTainting() const;
|
|
|
|
|
2021-11-08 16:29:32 +03:00
|
|
|
SafeRefPtr<InternalResponse> Unfiltered();
|
2016-01-12 23:15:12 +03:00
|
|
|
|
2023-01-20 12:09:17 +03:00
|
|
|
InternalResponseMetadata GetMetadata();
|
|
|
|
|
2023-01-20 12:09:17 +03:00
|
|
|
RequestCredentials GetCredentialsMode() const {
|
|
|
|
if (mWrappedResponse) {
|
|
|
|
return mWrappedResponse->GetCredentialsMode();
|
|
|
|
}
|
|
|
|
return mCredentialsMode;
|
|
|
|
}
|
|
|
|
|
2015-06-05 07:39:34 +03:00
|
|
|
~InternalResponse();
|
2014-09-27 03:41:15 +04:00
|
|
|
|
2021-11-08 16:29:32 +03:00
|
|
|
private:
|
2015-03-17 18:47:01 +03:00
|
|
|
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.
|
2021-11-08 16:29:32 +03:00
|
|
|
SafeRefPtr<InternalResponse> CreateIncompleteCopy();
|
2014-10-06 22:01:20 +04:00
|
|
|
|
2021-11-22 17:09:24 +03:00
|
|
|
template <typename T>
|
|
|
|
static SafeRefPtr<InternalResponse> FromIPCTemplate(const T& aIPCResponse);
|
|
|
|
|
2014-09-27 03:41:15 +04:00
|
|
|
ResponseType mType;
|
2016-05-03 04:48:40 +03:00
|
|
|
// A response has an associated url list (a list of zero or more fetch URLs).
|
|
|
|
// Unless stated otherwise, it is the empty list. The current url is the last
|
|
|
|
// element in mURLlist
|
|
|
|
nsTArray<nsCString> mURLList;
|
2014-09-27 03:41:15 +04:00
|
|
|
const uint16_t mStatus;
|
|
|
|
const nsCString mStatusText;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<InternalHeaders> mHeaders;
|
2014-09-27 03:41:15 +04:00
|
|
|
nsCOMPtr<nsIInputStream> mBody;
|
2018-10-06 20:34:24 +03:00
|
|
|
nsCString mBodyBlobURISpec;
|
2018-09-11 22:13:15 +03:00
|
|
|
nsString mBodyLocalPath;
|
2016-06-02 00:02:29 +03:00
|
|
|
int64_t mBodySize;
|
2017-07-10 12:03:24 +03:00
|
|
|
// It's used to passed to the CacheResponse to generate padding size. Once, we
|
|
|
|
// generate the padding size for resposne, we don't need it anymore.
|
|
|
|
Maybe<uint32_t> mPaddingInfo;
|
2017-07-10 12:11:29 +03:00
|
|
|
int64_t mPaddingSize;
|
2017-11-15 22:53:42 +03:00
|
|
|
nsresult mErrorCode;
|
2019-07-16 11:50:14 +03:00
|
|
|
RequestCredentials mCredentialsMode;
|
2017-12-04 09:39:15 +03:00
|
|
|
|
|
|
|
// For alternative data such as JS Bytecode cached in the HTTP cache.
|
2019-08-15 20:26:15 +03:00
|
|
|
nsCString mAlternativeDataType;
|
2017-12-04 09:39:15 +03:00
|
|
|
nsCOMPtr<nsIInputStream> mAlternativeBody;
|
2017-12-05 20:13:54 +03:00
|
|
|
nsMainThreadPtrHandle<nsICacheInfoChannel> mCacheInfoChannel;
|
2021-10-16 00:13:44 +03:00
|
|
|
bool mCloned;
|
2023-01-20 12:09:17 +03:00
|
|
|
bool mSerializeAsLazy{true};
|
2017-12-04 09:39:15 +03:00
|
|
|
|
2016-06-02 00:02:29 +03:00
|
|
|
public:
|
2021-11-19 19:45:19 +03:00
|
|
|
static constexpr int64_t UNKNOWN_BODY_SIZE = -1;
|
|
|
|
static constexpr int64_t UNKNOWN_PADDING_SIZE = -1;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-06-02 00:02:29 +03:00
|
|
|
private:
|
2015-05-25 21:21:05 +03:00
|
|
|
ChannelInfo mChannelInfo;
|
2015-06-05 07:39:34 +03:00
|
|
|
UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
|
2015-03-17 18:47:01 +03:00
|
|
|
|
|
|
|
// 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.
|
2021-11-08 16:29:32 +03:00
|
|
|
SafeRefPtr<InternalResponse> mWrappedResponse;
|
2014-09-27 03:41:15 +04:00
|
|
|
};
|
|
|
|
|
2021-11-22 17:09:24 +03:00
|
|
|
ParentToChildInternalResponse ToParentToChild(
|
|
|
|
const ParentToParentInternalResponse& aResponse,
|
|
|
|
NotNull<mozilla::ipc::PBackgroundParent*> aBackgroundParent);
|
|
|
|
|
2014-09-27 03:41:15 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_InternalResponse_h
|