зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1231213 - Implement IPCInternal{Request,Response}. r=asuth
Differential Revision: https://phabricator.services.mozilla.com/D26163 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
eb5c44999d
Коммит
f98858dcc7
|
@ -7,15 +7,57 @@ include ChannelInfo;
|
|||
include PBackgroundSharedTypes;
|
||||
|
||||
using HeadersGuardEnum from "mozilla/dom/FetchIPCTypes.h";
|
||||
using ReferrerPolicy from "mozilla/dom/FetchIPCTypes.h";
|
||||
using RequestCache from "mozilla/dom/FetchIPCTypes.h";
|
||||
using RequestCredentials from "mozilla/dom/FetchIPCTypes.h";
|
||||
using RequestMode from "mozilla/dom/FetchIPCTypes.h";
|
||||
using RequestRedirect from "mozilla/dom/FetchIPCTypes.h";
|
||||
using ResponseType from "mozilla/dom/FetchIPCTypes.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
struct HeadersEntry
|
||||
{
|
||||
struct HeadersEntry {
|
||||
nsCString name;
|
||||
nsCString value;
|
||||
};
|
||||
|
||||
struct IPCInternalRequest {
|
||||
nsCString method;
|
||||
nsCString[] urlList;
|
||||
HeadersGuardEnum headersGuard;
|
||||
HeadersEntry[] headers;
|
||||
IPCStream? body;
|
||||
int64_t bodySize;
|
||||
nsCString preferredAlternativeDataType;
|
||||
uint32_t contentPolicyType;
|
||||
nsString referrer;
|
||||
ReferrerPolicy referrerPolicy;
|
||||
RequestMode requestMode;
|
||||
RequestCredentials requestCredentials;
|
||||
RequestCache cacheMode;
|
||||
RequestRedirect requestRedirect;
|
||||
nsString integrity;
|
||||
nsCString fragment;
|
||||
bool createdByFetchEvent;
|
||||
PrincipalInfo? principalInfo;
|
||||
};
|
||||
|
||||
struct IPCInternalResponse {
|
||||
ResponseType type;
|
||||
nsCString[] urlList;
|
||||
uint16_t status;
|
||||
nsCString statusText;
|
||||
HeadersGuardEnum headersGuard;
|
||||
HeadersEntry[] headers;
|
||||
IPCStream? body;
|
||||
int64_t bodySize;
|
||||
nsresult errorCode;
|
||||
nsCString alternativeDataType;
|
||||
IPCStream? alternativeBody;
|
||||
IPCChannelInfo channelInfo;
|
||||
PrincipalInfo? principalInfo;
|
||||
};
|
||||
|
||||
} // namespace ipc
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
#include "mozilla/dom/WorkerCommon.h"
|
||||
#include "mozilla/dom/WorkerPrivate.h"
|
||||
#include "mozilla/ipc/IPCStreamUtils.h"
|
||||
#include "mozilla/ipc/PBackgroundChild.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -171,8 +173,73 @@ InternalRequest::InternalRequest(const InternalRequest& aOther)
|
|||
// NOTE: does not copy body stream... use the fallible Clone() for that
|
||||
}
|
||||
|
||||
InternalRequest::InternalRequest(const IPCInternalRequest& aIPCRequest)
|
||||
: mMethod(aIPCRequest.method()),
|
||||
mURLList(aIPCRequest.urlList()),
|
||||
mHeaders(new InternalHeaders(aIPCRequest.headers(),
|
||||
aIPCRequest.headersGuard())),
|
||||
mBodyStream(mozilla::ipc::DeserializeIPCStream(aIPCRequest.body())),
|
||||
mBodyLength(aIPCRequest.bodySize()),
|
||||
mPreferredAlternativeDataType(aIPCRequest.preferredAlternativeDataType()),
|
||||
mContentPolicyType(
|
||||
static_cast<nsContentPolicyType>(aIPCRequest.contentPolicyType())),
|
||||
mReferrer(aIPCRequest.referrer()),
|
||||
mReferrerPolicy(aIPCRequest.referrerPolicy()),
|
||||
mMode(aIPCRequest.requestMode()),
|
||||
mCredentialsMode(aIPCRequest.requestCredentials()),
|
||||
mCacheMode(aIPCRequest.cacheMode()),
|
||||
mRedirectMode(aIPCRequest.requestRedirect()),
|
||||
mIntegrity(aIPCRequest.integrity()),
|
||||
mFragment(aIPCRequest.fragment()),
|
||||
mCreatedByFetchEvent(aIPCRequest.createdByFetchEvent()) {
|
||||
if (aIPCRequest.principalInfo()) {
|
||||
mPrincipalInfo = MakeUnique<mozilla::ipc::PrincipalInfo>(
|
||||
aIPCRequest.principalInfo().ref());
|
||||
}
|
||||
}
|
||||
|
||||
InternalRequest::~InternalRequest() {}
|
||||
|
||||
template void InternalRequest::ToIPC<mozilla::ipc::PBackgroundChild>(
|
||||
IPCInternalRequest* aIPCRequest, mozilla::ipc::PBackgroundChild* aManager,
|
||||
UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoStream);
|
||||
|
||||
template <typename M>
|
||||
void InternalRequest::ToIPC(
|
||||
IPCInternalRequest* aIPCRequest, M* aManager,
|
||||
UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoStream) {
|
||||
MOZ_ASSERT(aIPCRequest);
|
||||
MOZ_ASSERT(aManager);
|
||||
MOZ_ASSERT(!mURLList.IsEmpty());
|
||||
|
||||
aIPCRequest->method() = mMethod;
|
||||
aIPCRequest->urlList() = mURLList;
|
||||
mHeaders->ToIPC(aIPCRequest->headers(), aIPCRequest->headersGuard());
|
||||
|
||||
if (mBodyStream) {
|
||||
aAutoStream.reset(new mozilla::ipc::AutoIPCStream(aIPCRequest->body()));
|
||||
DebugOnly<bool> ok = aAutoStream->Serialize(mBodyStream, aManager);
|
||||
MOZ_ASSERT(ok);
|
||||
}
|
||||
|
||||
aIPCRequest->bodySize() = mBodyLength;
|
||||
aIPCRequest->preferredAlternativeDataType() = mPreferredAlternativeDataType;
|
||||
aIPCRequest->contentPolicyType() = static_cast<uint32_t>(mContentPolicyType);
|
||||
aIPCRequest->referrer() = mReferrer;
|
||||
aIPCRequest->referrerPolicy() = mReferrerPolicy;
|
||||
aIPCRequest->requestMode() = mMode;
|
||||
aIPCRequest->requestCredentials() = mCredentialsMode;
|
||||
aIPCRequest->cacheMode() = mCacheMode;
|
||||
aIPCRequest->requestRedirect() = mRedirectMode;
|
||||
aIPCRequest->integrity() = mIntegrity;
|
||||
aIPCRequest->fragment() = mFragment;
|
||||
aIPCRequest->createdByFetchEvent() = mCreatedByFetchEvent;
|
||||
|
||||
if (mPrincipalInfo) {
|
||||
aIPCRequest->principalInfo().emplace(*mPrincipalInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void InternalRequest::SetContentPolicyType(
|
||||
nsContentPolicyType aContentPolicyType) {
|
||||
mContentPolicyType = aContentPolicyType;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "mozilla/dom/RequestBinding.h"
|
||||
#include "mozilla/LoadTainting.h"
|
||||
#include "mozilla/net/ReferrerPolicy.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
|
||||
#include "nsIContentPolicy.h"
|
||||
#include "nsIInputStream.h"
|
||||
|
@ -26,6 +27,7 @@ namespace mozilla {
|
|||
|
||||
namespace ipc {
|
||||
class PrincipalInfo;
|
||||
class AutoIPCStream;
|
||||
} // namespace ipc
|
||||
|
||||
namespace dom {
|
||||
|
@ -68,6 +70,7 @@ namespace dom {
|
|||
*
|
||||
*/
|
||||
|
||||
class IPCInternalRequest;
|
||||
class Request;
|
||||
|
||||
#define kFETCH_CLIENT_REFERRER_STR "about:client"
|
||||
|
@ -87,6 +90,12 @@ class InternalRequest final {
|
|||
nsContentPolicyType aContentPolicyType,
|
||||
const nsAString& aIntegrity);
|
||||
|
||||
explicit InternalRequest(const IPCInternalRequest& aIPCRequest);
|
||||
|
||||
template <typename M>
|
||||
void ToIPC(IPCInternalRequest* aIPCRequest, M* aManager,
|
||||
UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoStream);
|
||||
|
||||
already_AddRefed<InternalRequest> Clone();
|
||||
|
||||
void GetMethod(nsCString& aMethod) const { aMethod.Assign(mMethod); }
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include "InternalResponse.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/dom/FetchTypes.h"
|
||||
#include "mozilla/dom/InternalHeaders.h"
|
||||
#include "mozilla/dom/cache/CacheTypes.h"
|
||||
#include "mozilla/ipc/PBackgroundSharedTypes.h"
|
||||
|
@ -39,8 +41,112 @@ InternalResponse::InternalResponse(uint16_t aStatus,
|
|||
mErrorCode(NS_OK),
|
||||
mCredentialsMode(aCredentialsMode) {}
|
||||
|
||||
/* static */ RefPtr<InternalResponse> InternalResponse::FromIPC(
|
||||
const IPCInternalResponse& aIPCResponse) {
|
||||
if (aIPCResponse.type() == ResponseType::Error) {
|
||||
return InternalResponse::NetworkError(aIPCResponse.errorCode());
|
||||
}
|
||||
|
||||
RefPtr<InternalResponse> response =
|
||||
new InternalResponse(aIPCResponse.status(), aIPCResponse.statusText());
|
||||
|
||||
response->SetURLList(aIPCResponse.urlList());
|
||||
response->mHeaders =
|
||||
new InternalHeaders(aIPCResponse.headers(), aIPCResponse.headersGuard());
|
||||
|
||||
nsCOMPtr<nsIInputStream> body =
|
||||
mozilla::ipc::DeserializeIPCStream(aIPCResponse.body());
|
||||
response->SetBody(body, aIPCResponse.bodySize());
|
||||
|
||||
response->SetAlternativeDataType(aIPCResponse.alternativeDataType());
|
||||
|
||||
nsCOMPtr<nsIInputStream> alternativeBody =
|
||||
mozilla::ipc::DeserializeIPCStream(aIPCResponse.alternativeBody());
|
||||
response->SetAlternativeBody(alternativeBody);
|
||||
|
||||
response->InitChannelInfo(aIPCResponse.channelInfo());
|
||||
|
||||
if (aIPCResponse.principalInfo()) {
|
||||
response->SetPrincipalInfo(MakeUnique<mozilla::ipc::PrincipalInfo>(
|
||||
aIPCResponse.principalInfo().ref()));
|
||||
}
|
||||
|
||||
switch (aIPCResponse.type()) {
|
||||
case ResponseType::Basic:
|
||||
response = response->BasicResponse();
|
||||
break;
|
||||
case ResponseType::Cors:
|
||||
response = response->CORSResponse();
|
||||
break;
|
||||
case ResponseType::Default:
|
||||
break;
|
||||
case ResponseType::Opaque:
|
||||
response = response->OpaqueResponse();
|
||||
break;
|
||||
case ResponseType::Opaqueredirect:
|
||||
response = response->OpaqueRedirectResponse();
|
||||
break;
|
||||
default:
|
||||
MOZ_CRASH("Unexpected ResponseType!");
|
||||
}
|
||||
|
||||
MOZ_ASSERT(response);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
InternalResponse::~InternalResponse() {}
|
||||
|
||||
template void InternalResponse::ToIPC<mozilla::ipc::PBackgroundChild>(
|
||||
IPCInternalResponse* aIPCResponse, mozilla::ipc::PBackgroundChild* aManager,
|
||||
UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoBodyStream,
|
||||
UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoAlternativeBodyStream);
|
||||
|
||||
template <typename M>
|
||||
void InternalResponse::ToIPC(
|
||||
IPCInternalResponse* aIPCResponse, M* aManager,
|
||||
UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoBodyStream,
|
||||
UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoAlternativeBodyStream) {
|
||||
MOZ_ASSERT(aIPCResponse);
|
||||
|
||||
aIPCResponse->type() = mType;
|
||||
GetUnfilteredURLList(aIPCResponse->urlList());
|
||||
aIPCResponse->status() = GetUnfilteredStatus();
|
||||
aIPCResponse->statusText() = GetUnfilteredStatusText();
|
||||
UnfilteredHeaders()->ToIPC(aIPCResponse->headers(),
|
||||
aIPCResponse->headersGuard());
|
||||
|
||||
nsCOMPtr<nsIInputStream> body;
|
||||
int64_t bodySize;
|
||||
GetUnfilteredBody(getter_AddRefs(body), &bodySize);
|
||||
|
||||
if (body) {
|
||||
aAutoBodyStream.reset(
|
||||
new mozilla::ipc::AutoIPCStream(aIPCResponse->body()));
|
||||
DebugOnly<bool> ok = aAutoBodyStream->Serialize(body, aManager);
|
||||
MOZ_ASSERT(ok);
|
||||
}
|
||||
|
||||
aIPCResponse->bodySize() = bodySize;
|
||||
aIPCResponse->errorCode() = mErrorCode;
|
||||
aIPCResponse->alternativeDataType() = GetAlternativeDataType();
|
||||
|
||||
nsCOMPtr<nsIInputStream> alternativeBody = TakeAlternativeBody();
|
||||
if (alternativeBody) {
|
||||
aAutoAlternativeBodyStream.reset(
|
||||
new mozilla::ipc::AutoIPCStream(aIPCResponse->alternativeBody()));
|
||||
DebugOnly<bool> ok =
|
||||
aAutoAlternativeBodyStream->Serialize(alternativeBody, aManager);
|
||||
MOZ_ASSERT(ok);
|
||||
}
|
||||
|
||||
aIPCResponse->channelInfo() = mChannelInfo.AsIPCChannelInfo();
|
||||
|
||||
if (mPrincipalInfo) {
|
||||
aIPCResponse->principalInfo().emplace(*mPrincipalInfo);
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<InternalResponse> InternalResponse::Clone(
|
||||
CloneType aCloneType) {
|
||||
RefPtr<InternalResponse> clone = CreateIncompleteCopy();
|
||||
|
|
|
@ -26,6 +26,7 @@ class AutoIPCStream;
|
|||
|
||||
namespace dom {
|
||||
|
||||
class IPCInternalResponse;
|
||||
class InternalHeaders;
|
||||
|
||||
class InternalResponse final {
|
||||
|
@ -38,6 +39,15 @@ class InternalResponse final {
|
|||
uint16_t aStatus, const nsACString& aStatusText,
|
||||
RequestCredentials aCredentialsMode = RequestCredentials::Omit);
|
||||
|
||||
static RefPtr<InternalResponse> FromIPC(
|
||||
const IPCInternalResponse& aIPCResponse);
|
||||
|
||||
template <typename M>
|
||||
void ToIPC(
|
||||
IPCInternalResponse* aIPCResponse, M* aManager,
|
||||
UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoBodyStream,
|
||||
UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoAlternativeBodyStream);
|
||||
|
||||
enum CloneType {
|
||||
eCloneInputStream,
|
||||
eDontCloneInputStream,
|
||||
|
@ -211,6 +221,24 @@ class InternalResponse final {
|
|||
|
||||
void SetPaddingSize(int64_t aPaddingSize);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void SetAlternativeBody(nsIInputStream* aAlternativeBody) {
|
||||
if (mWrappedResponse) {
|
||||
return mWrappedResponse->SetAlternativeBody(aAlternativeBody);
|
||||
|
@ -323,6 +351,7 @@ class InternalResponse final {
|
|||
RequestCredentials mCredentialsMode;
|
||||
|
||||
// For alternative data such as JS Bytecode cached in the HTTP cache.
|
||||
nsCString mAlternativeDataType;
|
||||
nsCOMPtr<nsIInputStream> mAlternativeBody;
|
||||
nsMainThreadPtrHandle<nsICacheInfoChannel> mCacheInfoChannel;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче