summaryrefslogtreecommitdiffstats
path: root/dom/fetch/Request.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /dom/fetch/Request.cpp
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz
firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip
Adding upstream version 125.0.1.upstream/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.cpp71
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()) {