Bug 1881040 - Propagate RequestPriority when using PFetch. r=edenchuang

This patch makes sure the RequestPriority of the internal request is
propagated to the child process when using PFetch here:
https://searchfox.org/mozilla-central/rev/14ff5b1650123600698f4bb8998ee02b102b8d2f/dom/fetch/Fetch.cpp#632

Note that IPCInternalRequest is also used in ServiceWorkerPrivate when
intercepting a request. However, propagating the RequestPriority of the
intercepted request does not seem desirable, so we just initialize with
PRIORITY_AUTO.

One version of the constructor for InternalRequest is no longer used, so
we just remove it.

Differential Revision: https://phabricator.services.mozilla.com/D210281
This commit is contained in:
Frédéric Wang 2024-06-12 07:50:41 +00:00
Родитель 83be8ddc91
Коммит 290ea69c0e
5 изменённых файлов: 19 добавлений и 37 удалений

Просмотреть файл

@ -39,6 +39,10 @@ struct ParamTraits<mozilla::dom::RequestRedirect>
: public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::RequestRedirect> { : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::RequestRedirect> {
}; };
template <> template <>
struct ParamTraits<mozilla::dom::RequestPriority>
: public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::RequestPriority> {
};
template <>
struct ParamTraits<mozilla::dom::ResponseType> struct ParamTraits<mozilla::dom::ResponseType>
: public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::ResponseType> {}; : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::ResponseType> {};

Просмотреть файл

@ -15,6 +15,7 @@ using mozilla::dom::ReferrerPolicy from "mozilla/dom/ReferrerPolicyBinding.h";
using mozilla::dom::RequestCache from "mozilla/dom/RequestBinding.h"; using mozilla::dom::RequestCache from "mozilla/dom/RequestBinding.h";
using mozilla::dom::RequestCredentials from "mozilla/dom/RequestBinding.h"; using mozilla::dom::RequestCredentials from "mozilla/dom/RequestBinding.h";
using mozilla::dom::RequestRedirect from "mozilla/dom/RequestBinding.h"; using mozilla::dom::RequestRedirect from "mozilla/dom/RequestBinding.h";
using mozilla::dom::RequestPriority from "mozilla/dom/RequestBinding.h";
using mozilla::dom::ResponseType from "mozilla/dom/ResponseBinding.h"; using mozilla::dom::ResponseType from "mozilla/dom/ResponseBinding.h";
using struct nsID from "nsID.h"; using struct nsID from "nsID.h";
using mozilla::dom::FetchDriverObserver::EndReason from "mozilla/dom/FetchDriver.h"; using mozilla::dom::FetchDriverObserver::EndReason from "mozilla/dom/FetchDriver.h";
@ -67,6 +68,7 @@ struct IPCInternalRequest {
RequestCredentials requestCredentials; RequestCredentials requestCredentials;
RequestCache cacheMode; RequestCache cacheMode;
RequestRedirect requestRedirect; RequestRedirect requestRedirect;
RequestPriority requestPriority;
nsString integrity; nsString integrity;
nsCString fragment; nsCString fragment;
PrincipalInfo? principalInfo; PrincipalInfo? principalInfo;

Просмотреть файл

@ -98,30 +98,6 @@ InternalRequest::InternalRequest(const nsACString& aURL,
MOZ_ASSERT(!aURL.IsEmpty()); MOZ_ASSERT(!aURL.IsEmpty());
AddURL(aURL, aFragment); AddURL(aURL, aFragment);
} }
InternalRequest::InternalRequest(
const nsACString& aURL, const nsACString& aFragment,
const nsACString& aMethod, already_AddRefed<InternalHeaders> aHeaders,
RequestCache aCacheMode, RequestMode aMode,
RequestRedirect aRequestRedirect, RequestCredentials aRequestCredentials,
const nsACString& aReferrer, ReferrerPolicy aReferrerPolicy,
RequestPriority aPriority, nsContentPolicyType aContentPolicyType,
const nsAString& aIntegrity)
: mMethod(aMethod),
mHeaders(aHeaders),
mBodyLength(InternalResponse::UNKNOWN_BODY_SIZE),
mContentPolicyType(aContentPolicyType),
mReferrer(aReferrer),
mReferrerPolicy(aReferrerPolicy),
mEnvironmentReferrerPolicy(ReferrerPolicy::_empty),
mMode(aMode),
mCredentialsMode(aRequestCredentials),
mCacheMode(aCacheMode),
mRedirectMode(aRequestRedirect),
mPriorityMode(aPriority),
mIntegrity(aIntegrity) {
MOZ_ASSERT(!aURL.IsEmpty());
AddURL(aURL, aFragment);
}
InternalRequest::InternalRequest(const InternalRequest& aOther, InternalRequest::InternalRequest(const InternalRequest& aOther,
ConstructorGuard) ConstructorGuard)
: mMethod(aOther.mMethod), : mMethod(aOther.mMethod),
@ -178,6 +154,7 @@ InternalRequest::InternalRequest(const IPCInternalRequest& aIPCRequest)
mCredentialsMode(aIPCRequest.requestCredentials()), mCredentialsMode(aIPCRequest.requestCredentials()),
mCacheMode(aIPCRequest.cacheMode()), mCacheMode(aIPCRequest.cacheMode()),
mRedirectMode(aIPCRequest.requestRedirect()), mRedirectMode(aIPCRequest.requestRedirect()),
mPriorityMode(aIPCRequest.requestPriority()),
mIntegrity(aIPCRequest.integrity()), mIntegrity(aIPCRequest.integrity()),
mFragment(aIPCRequest.fragment()), mFragment(aIPCRequest.fragment()),
mEmbedderPolicy(aIPCRequest.embedderPolicy()), mEmbedderPolicy(aIPCRequest.embedderPolicy()),
@ -227,6 +204,7 @@ void InternalRequest::ToIPCInternalRequest(
aIPCRequest->requestCredentials() = mCredentialsMode; aIPCRequest->requestCredentials() = mCredentialsMode;
aIPCRequest->cacheMode() = mCacheMode; aIPCRequest->cacheMode() = mCacheMode;
aIPCRequest->requestRedirect() = mRedirectMode; aIPCRequest->requestRedirect() = mRedirectMode;
aIPCRequest->requestPriority() = mPriorityMode;
aIPCRequest->integrity() = mIntegrity; aIPCRequest->integrity() = mIntegrity;
aIPCRequest->fragment() = mFragment; aIPCRequest->fragment() = mFragment;
aIPCRequest->embedderPolicy() = mEmbedderPolicy; aIPCRequest->embedderPolicy() = mEmbedderPolicy;

Просмотреть файл

@ -87,16 +87,6 @@ class InternalRequest final : public AtomicSafeRefCounted<InternalRequest> {
public: public:
MOZ_DECLARE_REFCOUNTED_TYPENAME(InternalRequest) MOZ_DECLARE_REFCOUNTED_TYPENAME(InternalRequest)
InternalRequest(const nsACString& aURL, const nsACString& aFragment); InternalRequest(const nsACString& aURL, const nsACString& aFragment);
InternalRequest(const nsACString& aURL, const nsACString& aFragment,
const nsACString& aMethod,
already_AddRefed<InternalHeaders> aHeaders,
RequestCache aCacheMode, RequestMode aMode,
RequestRedirect aRequestRedirect,
RequestCredentials aRequestCredentials,
const nsACString& aReferrer, ReferrerPolicy aReferrerPolicy,
RequestPriority aPriority,
nsContentPolicyType aContentPolicyType,
const nsAString& aIntegrity);
explicit InternalRequest(const IPCInternalRequest& aIPCRequest); explicit InternalRequest(const IPCInternalRequest& aIPCRequest);

Просмотреть файл

@ -322,6 +322,14 @@ Result<IPCInternalRequest, nsresult> GetIPCInternalRequest(
MOZ_ALWAYS_SUCCEEDS(internalChannel->GetRedirectMode(&redirectMode)); MOZ_ALWAYS_SUCCEEDS(internalChannel->GetRedirectMode(&redirectMode));
RequestRedirect requestRedirect = static_cast<RequestRedirect>(redirectMode); RequestRedirect requestRedirect = static_cast<RequestRedirect>(redirectMode);
// request's priority is not copied by the new Request() constructor used by
// a fetch() call while request's internal priority is. So let's use the
// default, otherwise a fetch(event.request) from a worker on an intercepted
// fetch event would adjust priority twice.
// https://fetch.spec.whatwg.org/#dom-global-fetch
// https://fetch.spec.whatwg.org/#dom-request
RequestPriority requestPriority = RequestPriority::Auto;
RequestCredentials requestCredentials = RequestCredentials requestCredentials =
InternalRequest::MapChannelToRequestCredentials(underlyingChannel); InternalRequest::MapChannelToRequestCredentials(underlyingChannel);
@ -411,9 +419,9 @@ Result<IPCInternalRequest, nsresult> GetIPCInternalRequest(
method, {spec}, ipcHeadersGuard, ipcHeaders, Nothing(), -1, method, {spec}, ipcHeadersGuard, ipcHeaders, Nothing(), -1,
alternativeDataType, contentPolicyType, internalPriority, referrer, alternativeDataType, contentPolicyType, internalPriority, referrer,
referrerPolicy, environmentReferrerPolicy, requestMode, referrerPolicy, environmentReferrerPolicy, requestMode,
requestCredentials, cacheMode, requestRedirect, integrity, fragment, requestCredentials, cacheMode, requestRedirect, requestPriority,
principalInfo, interceptionPrincipalInfo, contentPolicyType, integrity, fragment, principalInfo, interceptionPrincipalInfo,
redirectChain, isThirdPartyChannel, embedderPolicy); contentPolicyType, redirectChain, isThirdPartyChannel, embedderPolicy);
} }
nsresult MaybeStoreStreamForBackgroundThread(nsIInterceptedChannel* aChannel, nsresult MaybeStoreStreamForBackgroundThread(nsIInterceptedChannel* aChannel,