2015-05-03 15:32:37 -04: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-23 22:03:20 -07: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/. */
|
|
|
|
|
|
|
|
#include "InternalRequest.h"
|
|
|
|
|
2020-10-21 08:00:18 +00:00
|
|
|
#include "InternalResponse.h"
|
2020-05-28 23:31:26 +03:00
|
|
|
#include "mozilla/ErrorResult.h"
|
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 09:09:54 +00:00
|
|
|
#include "mozilla/dom/Document.h"
|
2016-06-07 02:46:03 -07:00
|
|
|
#include "mozilla/dom/FetchTypes.h"
|
2014-09-23 22:03:20 -07:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2018-01-31 08:24:59 +01:00
|
|
|
#include "mozilla/dom/WorkerCommon.h"
|
|
|
|
#include "mozilla/dom/WorkerPrivate.h"
|
2019-08-15 17:26:15 +00:00
|
|
|
#include "mozilla/ipc/IPCStreamUtils.h"
|
|
|
|
#include "mozilla/ipc/PBackgroundChild.h"
|
2020-06-29 13:40:27 +00:00
|
|
|
#include "mozilla/RemoteLazyInputStreamChild.h"
|
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 09:09:54 +00:00
|
|
|
#include "nsIContentPolicy.h"
|
|
|
|
#include "nsStreamUtils.h"
|
2014-09-23 22:03:20 -07:00
|
|
|
|
2020-11-04 17:04:01 +00:00
|
|
|
namespace mozilla::dom {
|
2014-09-23 22:03:20 -07:00
|
|
|
// The global is used to extract the principal.
|
2020-05-11 12:10:53 +00:00
|
|
|
SafeRefPtr<InternalRequest> InternalRequest::GetRequestConstructorCopy(
|
2014-09-23 22:03:20 -07:00
|
|
|
nsIGlobalObject* aGlobal, ErrorResult& aRv) const {
|
2016-05-03 09:48:40 +08:00
|
|
|
MOZ_RELEASE_ASSERT(!mURLList.IsEmpty(),
|
|
|
|
"Internal Request's urlList should not be empty when "
|
|
|
|
"copied from constructor.");
|
2020-05-11 12:10:53 +00:00
|
|
|
auto copy =
|
|
|
|
MakeSafeRefPtr<InternalRequest>(mURLList.LastElement(), mFragment);
|
2014-09-23 22:03:20 -07:00
|
|
|
copy->SetMethod(mMethod);
|
2014-10-02 10:59:20 -07:00
|
|
|
copy->mHeaders = new InternalHeaders(*mHeaders);
|
2015-01-07 15:50:54 -08:00
|
|
|
copy->SetUnsafeRequest();
|
2014-09-23 22:03:20 -07:00
|
|
|
copy->mBodyStream = mBodyStream;
|
2017-09-08 16:06:26 +02:00
|
|
|
copy->mBodyLength = mBodyLength;
|
2015-01-07 15:50:54 -08:00
|
|
|
// The "client" is not stored in our implementation. Fetch API users should
|
|
|
|
// use the appropriate window/document/principal and other Gecko security
|
|
|
|
// mechanisms as appropriate.
|
2016-07-11 12:25:54 -07:00
|
|
|
copy->mReferrer = mReferrer;
|
2016-02-26 17:36:45 -05:00
|
|
|
copy->mReferrerPolicy = mReferrerPolicy;
|
2016-04-01 11:52:28 +08:00
|
|
|
copy->mEnvironmentReferrerPolicy = mEnvironmentReferrerPolicy;
|
2016-09-07 10:20:23 +08:00
|
|
|
copy->mIntegrity = mIntegrity;
|
2017-11-20 17:07:26 -05:00
|
|
|
copy->mMozErrors = mMozErrors;
|
2014-09-23 22:03:20 -07:00
|
|
|
|
2016-04-07 14:13:09 -07:00
|
|
|
copy->mContentPolicyType = mContentPolicyTypeOverridden
|
|
|
|
? mContentPolicyType
|
|
|
|
: nsIContentPolicy::TYPE_FETCH;
|
2014-09-23 22:03:20 -07:00
|
|
|
copy->mMode = mMode;
|
|
|
|
copy->mCredentialsMode = mCredentialsMode;
|
2015-01-07 16:24:40 -08:00
|
|
|
copy->mCacheMode = mCacheMode;
|
2015-08-31 14:26:29 -07:00
|
|
|
copy->mRedirectMode = mRedirectMode;
|
2016-04-07 14:13:09 -07:00
|
|
|
copy->mContentPolicyTypeOverridden = mContentPolicyTypeOverridden;
|
2017-12-04 14:39:10 +08:00
|
|
|
|
|
|
|
copy->mPreferredAlternativeDataType = mPreferredAlternativeDataType;
|
2022-03-09 21:49:52 +00:00
|
|
|
copy->mSkipWasmCaching = mSkipWasmCaching;
|
2020-05-11 12:10:53 +00:00
|
|
|
return copy;
|
2014-09-23 22:03:20 -07:00
|
|
|
}
|
|
|
|
|
2020-05-11 12:10:53 +00:00
|
|
|
SafeRefPtr<InternalRequest> InternalRequest::Clone() {
|
|
|
|
auto clone = MakeSafeRefPtr<InternalRequest>(*this, ConstructorGuard{});
|
2015-02-19 20:24:24 -05:00
|
|
|
|
|
|
|
if (!mBodyStream) {
|
2020-05-11 12:10:53 +00:00
|
|
|
return clone;
|
2015-02-19 20:24:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> clonedBody;
|
|
|
|
nsCOMPtr<nsIInputStream> replacementBody;
|
|
|
|
|
|
|
|
nsresult rv = NS_CloneInputStream(mBodyStream, getter_AddRefs(clonedBody),
|
|
|
|
getter_AddRefs(replacementBody));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
clone->mBodyStream.swap(clonedBody);
|
|
|
|
if (replacementBody) {
|
|
|
|
mBodyStream.swap(replacementBody);
|
|
|
|
}
|
2020-05-11 12:10:53 +00:00
|
|
|
return clone;
|
2015-02-19 20:24:24 -05:00
|
|
|
}
|
2016-11-07 10:16:34 +08:00
|
|
|
InternalRequest::InternalRequest(const nsACString& aURL,
|
|
|
|
const nsACString& aFragment)
|
2016-10-26 09:07:25 +02:00
|
|
|
: mMethod("GET"),
|
|
|
|
mHeaders(new InternalHeaders(HeadersGuardEnum::None)),
|
2017-09-08 16:06:26 +02:00
|
|
|
mBodyLength(InternalResponse::UNKNOWN_BODY_SIZE),
|
2016-10-26 09:07:25 +02:00
|
|
|
mContentPolicyType(nsIContentPolicy::TYPE_FETCH),
|
|
|
|
mReferrer(NS_LITERAL_STRING_FROM_CSTRING(kFETCH_CLIENT_REFERRER_STR)),
|
|
|
|
mReferrerPolicy(ReferrerPolicy::_empty),
|
2019-08-21 13:24:45 +00:00
|
|
|
mEnvironmentReferrerPolicy(ReferrerPolicy::_empty),
|
2016-10-26 09:07:25 +02:00
|
|
|
mMode(RequestMode::No_cors),
|
|
|
|
mCredentialsMode(RequestCredentials::Omit),
|
|
|
|
mCacheMode(RequestCache::Default),
|
2020-01-16 16:33:49 +00:00
|
|
|
mRedirectMode(RequestRedirect::Follow) {
|
2016-10-26 09:07:25 +02:00
|
|
|
MOZ_ASSERT(!aURL.IsEmpty());
|
2016-11-07 10:16:34 +08:00
|
|
|
AddURL(aURL, aFragment);
|
2016-10-26 09:07:25 +02:00
|
|
|
}
|
|
|
|
InternalRequest::InternalRequest(
|
2016-11-07 10:16:34 +08:00
|
|
|
const nsACString& aURL, const nsACString& aFragment,
|
2016-10-26 09:07:25 +02:00
|
|
|
const nsACString& aMethod, already_AddRefed<InternalHeaders> aHeaders,
|
|
|
|
RequestCache aCacheMode, RequestMode aMode,
|
|
|
|
RequestRedirect aRequestRedirect, RequestCredentials aRequestCredentials,
|
|
|
|
const nsAString& aReferrer, ReferrerPolicy aReferrerPolicy,
|
|
|
|
nsContentPolicyType aContentPolicyType, const nsAString& aIntegrity)
|
|
|
|
: mMethod(aMethod),
|
|
|
|
mHeaders(aHeaders),
|
2018-06-16 17:21:46 +03:00
|
|
|
mBodyLength(InternalResponse::UNKNOWN_BODY_SIZE),
|
2016-10-26 09:07:25 +02:00
|
|
|
mContentPolicyType(aContentPolicyType),
|
|
|
|
mReferrer(aReferrer),
|
|
|
|
mReferrerPolicy(aReferrerPolicy),
|
2019-08-21 13:24:45 +00:00
|
|
|
mEnvironmentReferrerPolicy(ReferrerPolicy::_empty),
|
2016-10-26 09:07:25 +02:00
|
|
|
mMode(aMode),
|
|
|
|
mCredentialsMode(aRequestCredentials),
|
|
|
|
mCacheMode(aCacheMode),
|
|
|
|
mRedirectMode(aRequestRedirect),
|
2020-01-16 16:33:49 +00:00
|
|
|
mIntegrity(aIntegrity) {
|
2016-10-26 09:07:25 +02:00
|
|
|
MOZ_ASSERT(!aURL.IsEmpty());
|
2016-11-07 10:16:34 +08:00
|
|
|
AddURL(aURL, aFragment);
|
2016-10-26 09:07:25 +02:00
|
|
|
}
|
2020-05-11 12:10:53 +00:00
|
|
|
InternalRequest::InternalRequest(const InternalRequest& aOther,
|
|
|
|
ConstructorGuard)
|
2015-02-19 20:24:24 -05:00
|
|
|
: mMethod(aOther.mMethod),
|
2020-05-05 14:14:10 +00:00
|
|
|
mURLList(aOther.mURLList.Clone()),
|
2015-02-19 20:24:24 -05:00
|
|
|
mHeaders(new InternalHeaders(*aOther.mHeaders)),
|
2017-09-22 10:56:28 +01:00
|
|
|
mBodyLength(InternalResponse::UNKNOWN_BODY_SIZE),
|
2015-02-19 20:24:24 -05:00
|
|
|
mContentPolicyType(aOther.mContentPolicyType),
|
|
|
|
mReferrer(aOther.mReferrer),
|
2016-02-26 17:36:45 -05:00
|
|
|
mReferrerPolicy(aOther.mReferrerPolicy),
|
2016-04-01 11:52:28 +08:00
|
|
|
mEnvironmentReferrerPolicy(aOther.mEnvironmentReferrerPolicy),
|
2015-02-19 20:24:24 -05:00
|
|
|
mMode(aOther.mMode),
|
|
|
|
mCredentialsMode(aOther.mCredentialsMode),
|
|
|
|
mResponseTainting(aOther.mResponseTainting),
|
|
|
|
mCacheMode(aOther.mCacheMode),
|
2015-08-31 14:26:29 -07:00
|
|
|
mRedirectMode(aOther.mRedirectMode),
|
2016-09-07 10:20:23 +08:00
|
|
|
mIntegrity(aOther.mIntegrity),
|
2017-11-20 17:07:26 -05:00
|
|
|
mMozErrors(aOther.mMozErrors),
|
2016-11-07 10:16:34 +08:00
|
|
|
mFragment(aOther.mFragment),
|
2015-02-19 20:24:24 -05:00
|
|
|
mSkipServiceWorker(aOther.mSkipServiceWorker),
|
2022-03-09 21:49:52 +00:00
|
|
|
mSkipWasmCaching(aOther.mSkipWasmCaching),
|
2015-02-19 20:24:24 -05:00
|
|
|
mSynchronous(aOther.mSynchronous),
|
|
|
|
mUnsafeRequest(aOther.mUnsafeRequest),
|
|
|
|
mUseURLCredentials(aOther.mUseURLCredentials),
|
2016-04-07 14:13:09 -07:00
|
|
|
mContentPolicyTypeOverridden(aOther.mContentPolicyTypeOverridden) {
|
2015-02-19 20:24:24 -05:00
|
|
|
// NOTE: does not copy body stream... use the fallible Clone() for that
|
|
|
|
}
|
|
|
|
|
2019-08-15 17:26:15 +00:00
|
|
|
InternalRequest::InternalRequest(const IPCInternalRequest& aIPCRequest)
|
|
|
|
: mMethod(aIPCRequest.method()),
|
2020-05-05 14:14:10 +00:00
|
|
|
mURLList(aIPCRequest.urlList().Clone()),
|
2019-08-15 17:26:15 +00:00
|
|
|
mHeaders(new InternalHeaders(aIPCRequest.headers(),
|
|
|
|
aIPCRequest.headersGuard())),
|
|
|
|
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()),
|
2019-11-01 13:43:15 +00:00
|
|
|
mFragment(aIPCRequest.fragment()) {
|
2019-08-15 17:26:15 +00:00
|
|
|
if (aIPCRequest.principalInfo()) {
|
|
|
|
mPrincipalInfo = MakeUnique<mozilla::ipc::PrincipalInfo>(
|
|
|
|
aIPCRequest.principalInfo().ref());
|
|
|
|
}
|
|
|
|
|
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 09:09:54 +00:00
|
|
|
const Maybe<BodyStreamVariant>& body = aIPCRequest.body();
|
2019-08-15 17:26:15 +00:00
|
|
|
|
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 09:09:54 +00:00
|
|
|
// This constructor is (currently) only used for parent -> child communication
|
|
|
|
// (constructed on the child side).
|
|
|
|
if (body) {
|
|
|
|
MOZ_ASSERT(body->type() == BodyStreamVariant::TParentToChildStream);
|
2022-05-13 14:16:10 +00:00
|
|
|
mBodyStream = body->get_ParentToChildStream().stream();
|
2019-08-15 17:26:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 09:09:54 +00:00
|
|
|
InternalRequest::~InternalRequest() = default;
|
|
|
|
|
2015-03-25 16:38:42 -04:00
|
|
|
void InternalRequest::SetContentPolicyType(
|
|
|
|
nsContentPolicyType aContentPolicyType) {
|
|
|
|
mContentPolicyType = aContentPolicyType;
|
2015-06-15 16:12:45 -04:00
|
|
|
}
|
|
|
|
|
2016-04-07 14:13:09 -07:00
|
|
|
void InternalRequest::OverrideContentPolicyType(
|
|
|
|
nsContentPolicyType aContentPolicyType) {
|
|
|
|
SetContentPolicyType(aContentPolicyType);
|
|
|
|
mContentPolicyTypeOverridden = true;
|
|
|
|
}
|
|
|
|
|
2019-02-25 16:05:29 -06:00
|
|
|
/* static */
|
|
|
|
RequestDestination InternalRequest::MapContentPolicyTypeToRequestDestination(
|
2018-03-09 14:11:27 +00:00
|
|
|
nsContentPolicyType aContentPolicyType) {
|
2015-03-25 16:38:42 -04:00
|
|
|
switch (aContentPolicyType) {
|
|
|
|
case nsIContentPolicy::TYPE_OTHER:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::_empty;
|
2015-06-16 21:21:08 -04:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_SCRIPT:
|
2015-09-20 14:55:44 -07:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_SCRIPT_PRELOAD:
|
2019-02-12 13:16:32 +00:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_MODULE:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD:
|
2015-09-11 18:48:43 -04:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER:
|
2017-02-15 09:55:58 -05:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_WORKER_IMPORT_SCRIPTS:
|
2020-07-24 11:52:02 +00:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT:
|
2020-08-10 09:04:37 +00:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT:
|
2018-03-09 14:11:27 +00:00
|
|
|
case nsIContentPolicy::TYPE_SCRIPT:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Script;
|
2015-06-16 21:21:08 -04:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_WORKER:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Worker;
|
2015-06-16 21:21:08 -04:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Sharedworker;
|
2018-03-09 14:11:27 +00:00
|
|
|
case nsIContentPolicy::TYPE_IMAGESET:
|
2015-09-20 14:55:44 -07:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_IMAGE:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD:
|
2016-10-13 15:43:54 +08:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_IMAGE_FAVICON:
|
2018-03-09 14:11:27 +00:00
|
|
|
case nsIContentPolicy::TYPE_IMAGE:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Image;
|
2018-03-09 14:11:27 +00:00
|
|
|
case nsIContentPolicy::TYPE_STYLESHEET:
|
2015-09-20 14:55:44 -07:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Style;
|
2018-03-09 14:11:27 +00:00
|
|
|
case nsIContentPolicy::TYPE_OBJECT:
|
2015-07-18 11:51:00 -04:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_OBJECT:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Object;
|
2015-07-18 11:51:00 -04:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_EMBED:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Embed;
|
2015-03-25 16:38:42 -04:00
|
|
|
case nsIContentPolicy::TYPE_DOCUMENT:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Document;
|
2018-03-09 14:11:27 +00:00
|
|
|
case nsIContentPolicy::TYPE_SUBDOCUMENT:
|
2015-07-13 17:06:53 -04:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_IFRAME:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Iframe;
|
2015-07-13 17:06:53 -04:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_FRAME:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Frame;
|
2015-03-25 16:38:42 -04:00
|
|
|
case nsIContentPolicy::TYPE_PING:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::_empty;
|
2018-03-09 14:11:27 +00:00
|
|
|
case nsIContentPolicy::TYPE_XMLHTTPREQUEST:
|
2015-08-06 11:17:24 -07:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::_empty;
|
2015-08-06 11:17:24 -07:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_EVENTSOURCE:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::_empty;
|
2015-03-25 16:38:42 -04:00
|
|
|
case nsIContentPolicy::TYPE_OBJECT_SUBREQUEST:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::_empty;
|
2015-03-25 16:38:42 -04:00
|
|
|
case nsIContentPolicy::TYPE_DTD:
|
2019-07-03 17:28:25 +00:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_DTD:
|
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_FORCE_ALLOWED_DTD:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::_empty;
|
2015-03-25 16:38:42 -04:00
|
|
|
case nsIContentPolicy::TYPE_FONT:
|
2020-05-11 14:13:16 +00:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD:
|
2021-06-14 01:22:06 +00:00
|
|
|
case nsIContentPolicy::TYPE_UA_FONT:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Font;
|
2018-03-09 14:11:27 +00:00
|
|
|
case nsIContentPolicy::TYPE_MEDIA:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::_empty;
|
2015-06-15 16:45:27 -04:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_AUDIO:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Audio;
|
2015-06-15 16:45:27 -04:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_VIDEO:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Video;
|
2015-06-15 16:45:27 -04:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_TRACK:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Track;
|
2015-03-25 16:38:42 -04:00
|
|
|
case nsIContentPolicy::TYPE_WEBSOCKET:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::_empty;
|
2015-03-25 16:38:42 -04:00
|
|
|
case nsIContentPolicy::TYPE_CSP_REPORT:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Report;
|
2015-03-25 16:38:42 -04:00
|
|
|
case nsIContentPolicy::TYPE_XSLT:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Xslt;
|
2015-03-25 16:38:42 -04:00
|
|
|
case nsIContentPolicy::TYPE_BEACON:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::_empty;
|
2015-03-25 16:38:42 -04:00
|
|
|
case nsIContentPolicy::TYPE_FETCH:
|
2020-08-11 12:33:14 +00:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_FETCH_PRELOAD:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::_empty;
|
2015-06-02 15:42:19 -04:00
|
|
|
case nsIContentPolicy::TYPE_WEB_MANIFEST:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Manifest;
|
2017-11-16 12:27:01 +01:00
|
|
|
case nsIContentPolicy::TYPE_SAVEAS_DOWNLOAD:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::_empty;
|
2018-03-23 15:27:08 -07:00
|
|
|
case nsIContentPolicy::TYPE_SPECULATIVE:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::_empty;
|
2020-03-17 11:29:33 +00:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_AUDIOWORKLET:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Audioworklet;
|
2020-03-17 11:29:33 +00:00
|
|
|
case nsIContentPolicy::TYPE_INTERNAL_PAINTWORKLET:
|
2020-12-14 08:32:55 +00:00
|
|
|
return RequestDestination::Paintworklet;
|
2021-09-13 18:20:10 +00:00
|
|
|
case nsIContentPolicy::TYPE_PROXIED_WEBRTC_MEDIA:
|
|
|
|
return RequestDestination::_empty;
|
2020-12-14 08:32:55 +00:00
|
|
|
case nsIContentPolicy::TYPE_INVALID:
|
2015-03-25 16:38:42 -04:00
|
|
|
break;
|
2021-01-19 09:42:13 +00:00
|
|
|
// Do not add default: so that compilers can catch the missing case.
|
2015-03-25 16:38:42 -04:00
|
|
|
}
|
2018-03-09 14:11:27 +00:00
|
|
|
|
2020-12-14 08:32:55 +00:00
|
|
|
MOZ_ASSERT(false, "Unhandled nsContentPolicyType value");
|
|
|
|
return RequestDestination::_empty;
|
2015-03-25 16:38:42 -04:00
|
|
|
}
|
|
|
|
|
2015-09-01 07:58:34 -07:00
|
|
|
// static
|
|
|
|
bool InternalRequest::IsNavigationContentPolicy(
|
|
|
|
nsContentPolicyType aContentPolicyType) {
|
2015-07-14 13:11:26 -07:00
|
|
|
// https://fetch.spec.whatwg.org/#navigation-request-context
|
|
|
|
//
|
|
|
|
// A navigation request context is one of "form", "frame", "hyperlink",
|
|
|
|
// "iframe", "internal" (as long as context frame type is not "none"),
|
|
|
|
// "location", "metarefresh", and "prerender".
|
|
|
|
//
|
2015-09-01 07:58:34 -07:00
|
|
|
// Note, all of these request types are effectively initiated by nsDocShell.
|
|
|
|
return aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT ||
|
|
|
|
aContentPolicyType == nsIContentPolicy::TYPE_SUBDOCUMENT ||
|
|
|
|
aContentPolicyType == nsIContentPolicy::TYPE_INTERNAL_FRAME ||
|
2021-01-19 09:42:13 +00:00
|
|
|
aContentPolicyType == nsIContentPolicy::TYPE_INTERNAL_IFRAME;
|
2015-07-14 13:11:26 -07:00
|
|
|
}
|
|
|
|
|
2015-09-01 07:58:34 -07:00
|
|
|
// static
|
|
|
|
bool InternalRequest::IsWorkerContentPolicy(
|
|
|
|
nsContentPolicyType aContentPolicyType) {
|
2015-07-14 13:11:26 -07:00
|
|
|
// https://fetch.spec.whatwg.org/#worker-request-context
|
|
|
|
//
|
|
|
|
// A worker request context is one of "serviceworker", "sharedworker", and
|
|
|
|
// "worker".
|
|
|
|
//
|
|
|
|
// Note, service workers are not included here because currently there is
|
2018-03-09 14:11:27 +00:00
|
|
|
// no way to generate a Request with a "serviceworker" RequestDestination.
|
2015-07-14 13:11:26 -07:00
|
|
|
// ServiceWorker scripts cannot be intercepted.
|
2015-09-01 07:58:34 -07:00
|
|
|
return aContentPolicyType == nsIContentPolicy::TYPE_INTERNAL_WORKER ||
|
|
|
|
aContentPolicyType == nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InternalRequest::IsNavigationRequest() const {
|
|
|
|
return IsNavigationContentPolicy(mContentPolicyType);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InternalRequest::IsWorkerRequest() const {
|
|
|
|
return IsWorkerContentPolicy(mContentPolicyType);
|
2015-07-14 13:11:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool InternalRequest::IsClientRequest() const {
|
|
|
|
return IsNavigationRequest() || IsWorkerRequest();
|
|
|
|
}
|
|
|
|
|
2015-09-01 07:58:34 -07:00
|
|
|
// static
|
|
|
|
RequestMode InternalRequest::MapChannelToRequestMode(nsIChannel* aChannel) {
|
|
|
|
MOZ_ASSERT(aChannel);
|
|
|
|
|
2019-04-25 12:16:35 +00:00
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
|
2015-09-01 07:58:34 -07:00
|
|
|
|
|
|
|
nsContentPolicyType contentPolicy = loadInfo->InternalContentPolicyType();
|
2016-01-13 18:15:37 -05:00
|
|
|
if (IsNavigationContentPolicy(contentPolicy)) {
|
|
|
|
return RequestMode::Navigate;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: remove the worker override once securityMode is fully implemented
|
|
|
|
// (bug 1189945)
|
|
|
|
if (IsWorkerContentPolicy(contentPolicy)) {
|
2015-09-01 07:58:34 -07:00
|
|
|
return RequestMode::Same_origin;
|
|
|
|
}
|
|
|
|
|
2016-08-12 15:19:29 +10:00
|
|
|
uint32_t securityMode = loadInfo->GetSecurityMode();
|
2015-09-01 07:58:34 -07:00
|
|
|
|
|
|
|
switch (securityMode) {
|
2020-07-15 11:20:45 +00:00
|
|
|
case nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_INHERITS_SEC_CONTEXT:
|
2015-09-01 07:58:34 -07:00
|
|
|
case nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED:
|
|
|
|
return RequestMode::Same_origin;
|
2020-07-15 11:20:45 +00:00
|
|
|
case nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_INHERITS_SEC_CONTEXT:
|
|
|
|
case nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL:
|
2015-09-01 07:58:34 -07:00
|
|
|
return RequestMode::No_cors;
|
2020-07-15 11:20:45 +00:00
|
|
|
case nsILoadInfo::SEC_REQUIRE_CORS_INHERITS_SEC_CONTEXT:
|
2015-09-01 07:58:34 -07:00
|
|
|
// TODO: Check additional flag force-preflight after bug 1199693 (bug
|
|
|
|
// 1189945)
|
|
|
|
return RequestMode::Cors;
|
|
|
|
default:
|
2018-01-22 16:35:01 +01:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected security mode!");
|
|
|
|
return RequestMode::Same_origin;
|
2015-09-01 07:58:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-25 14:18:29 +08:00
|
|
|
// static
|
|
|
|
RequestCredentials InternalRequest::MapChannelToRequestCredentials(
|
|
|
|
nsIChannel* aChannel) {
|
|
|
|
MOZ_ASSERT(aChannel);
|
|
|
|
|
2019-04-25 12:16:35 +00:00
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
|
2016-01-25 14:18:29 +08:00
|
|
|
|
|
|
|
uint32_t cookiePolicy = loadInfo->GetCookiePolicy();
|
|
|
|
|
|
|
|
if (cookiePolicy == nsILoadInfo::SEC_COOKIES_INCLUDE) {
|
|
|
|
return RequestCredentials::Include;
|
|
|
|
} else if (cookiePolicy == nsILoadInfo::SEC_COOKIES_OMIT) {
|
|
|
|
return RequestCredentials::Omit;
|
|
|
|
} else if (cookiePolicy == nsILoadInfo::SEC_COOKIES_SAME_ORIGIN) {
|
|
|
|
return RequestCredentials::Same_origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected cookie policy!");
|
|
|
|
return RequestCredentials::Same_origin;
|
|
|
|
}
|
|
|
|
|
2016-03-02 18:09:30 -05:00
|
|
|
void InternalRequest::MaybeSkipCacheIfPerformingRevalidation() {
|
|
|
|
if (mCacheMode == RequestCache::Default &&
|
|
|
|
mHeaders->HasRevalidationHeaders()) {
|
|
|
|
mCacheMode = RequestCache::No_store;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-26 09:07:25 +02:00
|
|
|
void InternalRequest::SetPrincipalInfo(
|
|
|
|
UniquePtr<mozilla::ipc::PrincipalInfo> aPrincipalInfo) {
|
2018-05-30 21:15:35 +02:00
|
|
|
mPrincipalInfo = std::move(aPrincipalInfo);
|
2016-10-26 09:07:25 +02:00
|
|
|
}
|
|
|
|
|
2020-11-04 17:04:01 +00:00
|
|
|
} // namespace mozilla::dom
|