diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:33 +0000 |
commit | 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch) | |
tree | a4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /dom/fetch/Request.cpp | |
parent | Adding debian version 124.0.1-1. (diff) | |
download | firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/fetch/Request.cpp')
-rw-r--r-- | dom/fetch/Request.cpp | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/dom/fetch/Request.cpp b/dom/fetch/Request.cpp index 8108d2522b..e042dd6271 100644 --- a/dom/fetch/Request.cpp +++ b/dom/fetch/Request.cpp @@ -329,27 +329,37 @@ SafeRefPtr<Request> Request::Constructor(nsIGlobalObject* aGlobal, if (NS_WARN_IF(aRv.Failed())) { return nullptr; } - RequestMode fallbackMode = RequestMode::EndGuard_; - RequestCredentials fallbackCredentials = RequestCredentials::EndGuard_; - RequestCache fallbackCache = RequestCache::EndGuard_; + Maybe<RequestMode> mode; + if (aInit.mMode.WasPassed()) { + if (aInit.mMode.Value() == RequestMode::Navigate) { + aRv.ThrowTypeError<MSG_INVALID_REQUEST_MODE>("navigate"); + return nullptr; + } + + mode.emplace(aInit.mMode.Value()); + } + Maybe<RequestCredentials> credentials; + if (aInit.mCredentials.WasPassed()) { + credentials.emplace(aInit.mCredentials.Value()); + } + Maybe<RequestCache> cache; + if (aInit.mCache.WasPassed()) { + cache.emplace(aInit.mCache.Value()); + } if (aInput.IsUSVString()) { - fallbackMode = RequestMode::Cors; - fallbackCredentials = RequestCredentials::Same_origin; - fallbackCache = RequestCache::Default; + if (mode.isNothing()) { + mode.emplace(RequestMode::Cors); + } + if (credentials.isNothing()) { + credentials.emplace(RequestCredentials::Same_origin); + } + if (cache.isNothing()) { + cache.emplace(RequestCache::Default); + } } - RequestMode mode = - aInit.mMode.WasPassed() ? aInit.mMode.Value() : fallbackMode; - RequestCredentials credentials = aInit.mCredentials.WasPassed() - ? aInit.mCredentials.Value() - : fallbackCredentials; - - if (mode == RequestMode::Navigate) { - aRv.ThrowTypeError<MSG_INVALID_REQUEST_MODE>("navigate"); - return nullptr; - } if (aInit.IsAnyMemberPresent() && request->Mode() == RequestMode::Navigate) { - mode = RequestMode::Same_origin; + mode = Some(RequestMode::Same_origin); } if (aInit.IsAnyMemberPresent()) { @@ -430,6 +440,13 @@ SafeRefPtr<Request> Request::Constructor(nsIGlobalObject* aGlobal, signal = aInit.mSignal.Value(); } + // https://fetch.spec.whatwg.org/#dom-global-fetch + // https://fetch.spec.whatwg.org/#dom-request + // The priority of init overrides input's priority. + if (aInit.mPriority.WasPassed()) { + request->SetPriorityMode(aInit.mPriority.Value()); + } + UniquePtr<mozilla::ipc::PrincipalInfo> principalInfo; nsILoadInfo::CrossOriginEmbedderPolicy coep = nsILoadInfo::EMBEDDER_POLICY_NULL; @@ -473,24 +490,22 @@ SafeRefPtr<Request> Request::Constructor(nsIGlobalObject* aGlobal, request->SetPrincipalInfo(std::move(principalInfo)); request->SetEmbedderPolicy(coep); - if (mode != RequestMode::EndGuard_) { - request->SetMode(mode); + if (mode.isSome()) { + request->SetMode(mode.value()); } - if (credentials != RequestCredentials::EndGuard_) { - request->SetCredentialsMode(credentials); + if (credentials.isSome()) { + request->SetCredentialsMode(credentials.value()); } - RequestCache cache = - aInit.mCache.WasPassed() ? aInit.mCache.Value() : fallbackCache; - if (cache != RequestCache::EndGuard_) { - if (cache == RequestCache::Only_if_cached && + if (cache.isSome()) { + if (cache.value() == RequestCache::Only_if_cached && request->Mode() != RequestMode::Same_origin) { - nsCString modeString(RequestModeValues::GetString(request->Mode())); - aRv.ThrowTypeError<MSG_ONLY_IF_CACHED_WITHOUT_SAME_ORIGIN>(modeString); + aRv.ThrowTypeError<MSG_ONLY_IF_CACHED_WITHOUT_SAME_ORIGIN>( + GetEnumString(request->Mode())); return nullptr; } - request->SetCacheMode(cache); + request->SetCacheMode(cache.value()); } if (aInit.mRedirect.WasPassed()) { |