summaryrefslogtreecommitdiffstats
path: root/dom/fetch
diff options
context:
space:
mode:
Diffstat (limited to 'dom/fetch')
-rw-r--r--dom/fetch/FetchDriver.cpp46
-rw-r--r--dom/fetch/FetchIPCTypes.h34
-rw-r--r--dom/fetch/InternalRequest.cpp9
-rw-r--r--dom/fetch/InternalRequest.h8
-rw-r--r--dom/fetch/Request.cpp71
-rw-r--r--dom/fetch/Request.h2
6 files changed, 100 insertions, 70 deletions
diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp
index 77fe5e59bb..c4acc35cf5 100644
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -9,9 +9,11 @@
#include "mozilla/TaskQueue.h"
#include "mozilla/dom/FetchDriver.h"
+#include "mozilla/dom/FetchPriority.h"
#include "mozilla/dom/ReferrerInfo.h"
#include "nsIAsyncVerifyRedirectCallback.h"
#include "mozilla/dom/Document.h"
+#include "nsIBaseChannel.h"
#include "nsICookieJarSettings.h"
#include "nsIFile.h"
#include "nsIInputStream.h"
@@ -27,7 +29,6 @@
#include "nsIPipe.h"
#include "nsIRedirectHistoryEntry.h"
-#include "nsBaseChannel.h"
#include "nsContentPolicyUtils.h"
#include "nsDataChannel.h"
#include "nsDataHandler.h"
@@ -46,6 +47,7 @@
#include "mozilla/dom/UserActivation.h"
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/PreloaderBase.h"
+#include "mozilla/net/ContentRange.h"
#include "mozilla/net/InterceptionInfo.h"
#include "mozilla/net/NeckoChannelParams.h"
#include "mozilla/ipc/PBackgroundSharedTypes.h"
@@ -840,11 +842,20 @@ nsresult FetchDriver::HttpFetch(
nsIClassOfService::Tail);
}
- if (mIsTrackingFetch &&
- StaticPrefs::privacy_trackingprotection_lower_network_priority()) {
- nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(chan);
- if (p) {
+ if (nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(chan)) {
+ if (mIsTrackingFetch &&
+ StaticPrefs::privacy_trackingprotection_lower_network_priority()) {
p->SetPriority(nsISupportsPriority::PRIORITY_LOWEST);
+ } else if (StaticPrefs::network_fetchpriority_enabled()) {
+ // TODO: Bug 1881040 - we need to take into account of destination for the
+ // fetchpriority mapping.
+ const auto fetchPriority = ToFetchPriority(mRequest->GetPriorityMode());
+ // The spec defines the priority to be set in an implementation defined
+ // manner (<https://fetch.spec.whatwg.org/#concept-fetch>, step 15.
+ // See corresponding preferences in StaticPrefList.yaml for more context.
+ const int32_t supportsPriorityDelta =
+ FETCH_PRIORITY_ADJUSTMENT_FOR(global_fetch_api, fetchPriority);
+ p->AdjustPriority(supportsPriorityDelta);
}
}
@@ -1028,7 +1039,7 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest) {
bool foundOpaqueRedirect = false;
- nsAutoCString contentType;
+ nsAutoCString contentType(VoidCString());
int64_t contentLength = InternalResponse::UNKNOWN_BODY_SIZE;
rv = channel->GetContentLength(&contentLength);
@@ -1089,13 +1100,10 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest) {
// Should set a Content-Range header for blob scheme
// (https://fetch.spec.whatwg.org/#scheme-fetch)
nsAutoCString contentRange(VoidCString());
- nsCOMPtr<nsIURI> uri;
- channel->GetURI(getter_AddRefs(uri));
- if (IsBlobURI(uri)) {
- nsBaseChannel* bchan = static_cast<nsBaseChannel*>(channel.get());
- MOZ_ASSERT(bchan);
- Maybe<nsBaseChannel::ContentRange> range = bchan->GetContentRange();
- if (range.isSome()) {
+ nsCOMPtr<nsIBaseChannel> baseChan = do_QueryInterface(mChannel);
+ if (baseChan) {
+ RefPtr<mozilla::net::ContentRange> range = baseChan->ContentRange();
+ if (range) {
range->AsHeader(contentRange);
}
}
@@ -1111,11 +1119,13 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest) {
MOZ_ASSERT(!result.Failed());
}
- if (uri && uri->SchemeIs("data")) {
- nsDataChannel* dchan = static_cast<nsDataChannel*>(channel.get());
- MOZ_ASSERT(dchan);
- contentType.Assign(dchan->MimeType());
- } else {
+ if (baseChan) {
+ RefPtr<CMimeType> fullMimeType(baseChan->FullMimeType());
+ if (fullMimeType) {
+ fullMimeType->Serialize(contentType);
+ }
+ }
+ if (contentType.IsVoid()) {
channel->GetContentType(contentType);
if (!contentType.IsEmpty()) {
nsAutoCString contentCharset;
diff --git a/dom/fetch/FetchIPCTypes.h b/dom/fetch/FetchIPCTypes.h
index 343a5acb3f..66d183ec37 100644
--- a/dom/fetch/FetchIPCTypes.h
+++ b/dom/fetch/FetchIPCTypes.h
@@ -9,6 +9,7 @@
#include "ipc/EnumSerializer.h"
+#include "mozilla/dom/BindingIPCUtils.h"
#include "mozilla/dom/HeadersBinding.h"
#include "mozilla/dom/RequestBinding.h"
#include "mozilla/dom/ResponseBinding.h"
@@ -17,41 +18,30 @@
namespace IPC {
template <>
struct ParamTraits<mozilla::dom::HeadersGuardEnum>
- : public ContiguousEnumSerializer<
- mozilla::dom::HeadersGuardEnum, mozilla::dom::HeadersGuardEnum::None,
- mozilla::dom::HeadersGuardEnum::EndGuard_> {};
+ : public mozilla::dom::WebIDLEnumSerializer<
+ mozilla::dom::HeadersGuardEnum> {};
template <>
struct ParamTraits<mozilla::dom::ReferrerPolicy>
- : public ContiguousEnumSerializer<mozilla::dom::ReferrerPolicy,
- mozilla::dom::ReferrerPolicy::_empty,
- mozilla::dom::ReferrerPolicy::EndGuard_> {
+ : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::ReferrerPolicy> {
};
template <>
struct ParamTraits<mozilla::dom::RequestMode>
- : public ContiguousEnumSerializer<mozilla::dom::RequestMode,
- mozilla::dom::RequestMode::Same_origin,
- mozilla::dom::RequestMode::EndGuard_> {};
+ : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::RequestMode> {};
template <>
struct ParamTraits<mozilla::dom::RequestCredentials>
- : public ContiguousEnumSerializer<
- mozilla::dom::RequestCredentials,
- mozilla::dom::RequestCredentials::Omit,
- mozilla::dom::RequestCredentials::EndGuard_> {};
+ : public mozilla::dom::WebIDLEnumSerializer<
+ mozilla::dom::RequestCredentials> {};
template <>
struct ParamTraits<mozilla::dom::RequestCache>
- : public ContiguousEnumSerializer<mozilla::dom::RequestCache,
- mozilla::dom::RequestCache::Default,
- mozilla::dom::RequestCache::EndGuard_> {};
+ : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::RequestCache> {};
template <>
struct ParamTraits<mozilla::dom::RequestRedirect>
- : public ContiguousEnumSerializer<
- mozilla::dom::RequestRedirect, mozilla::dom::RequestRedirect::Follow,
- mozilla::dom::RequestRedirect::EndGuard_> {};
+ : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::RequestRedirect> {
+};
template <>
struct ParamTraits<mozilla::dom::ResponseType>
- : public ContiguousEnumSerializer<mozilla::dom::ResponseType,
- mozilla::dom::ResponseType::Basic,
- mozilla::dom::ResponseType::EndGuard_> {};
+ : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::ResponseType> {};
+
template <>
struct ParamTraits<mozilla::dom::FetchDriverObserver::EndReason>
: public ContiguousEnumSerializerInclusive<
diff --git a/dom/fetch/InternalRequest.cpp b/dom/fetch/InternalRequest.cpp
index 41797d3e82..b5cc7cf291 100644
--- a/dom/fetch/InternalRequest.cpp
+++ b/dom/fetch/InternalRequest.cpp
@@ -49,6 +49,7 @@ SafeRefPtr<InternalRequest> InternalRequest::GetRequestConstructorCopy(
copy->mCredentialsMode = mCredentialsMode;
copy->mCacheMode = mCacheMode;
copy->mRedirectMode = mRedirectMode;
+ copy->mPriorityMode = mPriorityMode;
copy->mContentPolicyTypeOverridden = mContentPolicyTypeOverridden;
copy->mPreferredAlternativeDataType = mPreferredAlternativeDataType;
@@ -91,7 +92,8 @@ InternalRequest::InternalRequest(const nsACString& aURL,
mMode(RequestMode::No_cors),
mCredentialsMode(RequestCredentials::Omit),
mCacheMode(RequestCache::Default),
- mRedirectMode(RequestRedirect::Follow) {
+ mRedirectMode(RequestRedirect::Follow),
+ mPriorityMode(RequestPriority::Auto) {
MOZ_ASSERT(!aURL.IsEmpty());
AddURL(aURL, aFragment);
}
@@ -101,7 +103,8 @@ InternalRequest::InternalRequest(
RequestCache aCacheMode, RequestMode aMode,
RequestRedirect aRequestRedirect, RequestCredentials aRequestCredentials,
const nsAString& aReferrer, ReferrerPolicy aReferrerPolicy,
- nsContentPolicyType aContentPolicyType, const nsAString& aIntegrity)
+ RequestPriority aPriority, nsContentPolicyType aContentPolicyType,
+ const nsAString& aIntegrity)
: mMethod(aMethod),
mHeaders(aHeaders),
mBodyLength(InternalResponse::UNKNOWN_BODY_SIZE),
@@ -113,6 +116,7 @@ InternalRequest::InternalRequest(
mCredentialsMode(aRequestCredentials),
mCacheMode(aCacheMode),
mRedirectMode(aRequestRedirect),
+ mPriorityMode(aPriority),
mIntegrity(aIntegrity) {
MOZ_ASSERT(!aURL.IsEmpty());
AddURL(aURL, aFragment);
@@ -132,6 +136,7 @@ InternalRequest::InternalRequest(const InternalRequest& aOther,
mResponseTainting(aOther.mResponseTainting),
mCacheMode(aOther.mCacheMode),
mRedirectMode(aOther.mRedirectMode),
+ mPriorityMode(aOther.mPriorityMode),
mIntegrity(aOther.mIntegrity),
mMozErrors(aOther.mMozErrors),
mFragment(aOther.mFragment),
diff --git a/dom/fetch/InternalRequest.h b/dom/fetch/InternalRequest.h
index 3dfbb9284d..d2b7721f5e 100644
--- a/dom/fetch/InternalRequest.h
+++ b/dom/fetch/InternalRequest.h
@@ -93,6 +93,7 @@ class InternalRequest final : public AtomicSafeRefCounted<InternalRequest> {
RequestRedirect aRequestRedirect,
RequestCredentials aRequestCredentials,
const nsAString& aReferrer, ReferrerPolicy aReferrerPolicy,
+ RequestPriority aPriority,
nsContentPolicyType aContentPolicyType,
const nsAString& aIntegrity);
@@ -250,6 +251,12 @@ class InternalRequest final : public AtomicSafeRefCounted<InternalRequest> {
mRedirectMode = aRedirectMode;
}
+ RequestPriority GetPriorityMode() const { return mPriorityMode; }
+
+ void SetPriorityMode(RequestPriority aPriorityMode) {
+ mPriorityMode = aPriorityMode;
+ }
+
const nsString& GetIntegrity() const { return mIntegrity; }
void SetIntegrity(const nsAString& aIntegrity) {
@@ -445,6 +452,7 @@ class InternalRequest final : public AtomicSafeRefCounted<InternalRequest> {
LoadTainting mResponseTainting = LoadTainting::Basic;
RequestCache mCacheMode;
RequestRedirect mRedirectMode;
+ RequestPriority mPriorityMode = RequestPriority::Auto;
nsString mIntegrity;
bool mMozErrors = false;
nsCString mFragment;
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()) {
diff --git a/dom/fetch/Request.h b/dom/fetch/Request.h
index 0086e076de..ee8deffe5a 100644
--- a/dom/fetch/Request.h
+++ b/dom/fetch/Request.h
@@ -53,6 +53,8 @@ class Request final : public FetchBody<Request>, public nsWrapperCache {
RequestRedirect Redirect() const { return mRequest->GetRedirectMode(); }
+ RequestPriority Priority() const { return mRequest->GetPriorityMode(); }
+
void GetIntegrity(nsAString& aIntegrity) const {
aIntegrity = mRequest->GetIntegrity();
}